4.2. 기본 SSL 컨텍스트를 로드하는 클라이언트 생성 예
다음 예제에서는 Ely tron 클라이언트에서 초기화한 를 등록하는 방법을 보여줍니다. 이 예제에서는 공급자에 대한 인수로 제공된 정적 클라이언트 구성을 사용합니다.
SSLContext.getDefault() 메서드를 프로그래밍 방식으로 사용하고 사용하는 WildFlytronClientDefaultSSLContextProvider 공급자
4.2.1. JBoss EAP 클라이언트용 Maven 프로젝트 생성 링크 복사링크가 클립보드에 복사되었습니다!
JBoss EAP에 배포된 애플리케이션에 대한 클라이언트를 생성하려면 필요한 종속성과 디렉터리 구조가 포함된 Maven 프로젝트를 생성합니다.
사전 요구 사항
- Maven이 설치되어 있어야 합니다. 자세한 내용은 Apache Maven 다운로드를 참조하십시오.
프로세스
mvn명령을 사용하여 Maven 프로젝트를 설정합니다. 명령은 프로젝트에 대한 디렉터리 구조와pom.xml구성 파일을 생성합니다.$ mvn archetype:generate \ -DgroupId=com.example.client \ -DartifactId=client-ssl-context \ -DarchetypeGroupId=org.apache.maven.archetypes \ -DarchetypeArtifactId=maven-archetype-quickstart \ -DinteractiveMode=false애플리케이션 루트 디렉터리로 이동합니다.
$ cd client-ssl-context생성된
pom.xml파일의 내용을 다음 텍스트로 바꿉니다.<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.example.client</groupId> <artifactId>client-ssl-context</artifactId> <version>1.0-SNAPSHOT</version> <name>client-ssl-context</name> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>11</maven.compiler.source> <maven.compiler.target>11</maven.compiler.target> </properties> <repositories> <repository> <id>jboss-public-maven-repository</id> <name>JBoss Public Maven Repository</name> <url>https://repository.jboss.org/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> <repository> <id>redhat-ga-maven-repository</id> <name>Red Hat GA Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <releases> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>never</updatePolicy> </snapshots> <layout>default</layout> </repository> </repositories> <dependencies> <dependency>1 <groupId>org.wildfly.security</groupId> <artifactId>wildfly-elytron-client</artifactId> <version>2.0.0.Final-redhat-00001</version> </dependency> <dependency>2 <groupId>org.wildfly.client</groupId> <artifactId>wildfly-client-config</artifactId> <version>1.0.1.Final-redhat-00001</version> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.4.0</version> <configuration> <mainClass>com.example.client.App</mainClass> </configuration> </plugin> </plugins> </build> </project>src/test디렉토리를 삭제합니다.$ rm -rf src/test/
검증
애플리케이션 루트 디렉터리에 다음 명령을 입력합니다.
$ mvn install다음과 유사한 출력이 표시됩니다.
... [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 1.682 s [INFO] Finished at: 2023-10-31T01:32:17+05:30 [INFO] ------------------------------------------------------------------------
4.2.2. 기본 SSLContext를 로드하는 클라이언트 생성 링크 복사링크가 클립보드에 복사되었습니다!
SSLContext.getDefault() 메서드를 사용하여 SSLContext 를 로드하는 JBoss EAP에 배포된 애플리케이션에 대한 클라이언트를 생성합니다.
이 절차에서 < ;application_home >은 애플리케이션의 pom.xml 구성 파일이 포함된 디렉터리를 나타냅니다.
사전 요구 사항
양방향 TLS를 사용하여 JBoss EAP에 배포된 애플리케이션을 보호했습니다.
이렇게 하려면 다음 절차를 따르십시오.
Maven 프로젝트를 생성했습니다.
자세한 내용은 JBoss EAP 클라이언트에 대한 Maven 프로젝트 생성 을 참조하십시오.
- JBoss EAP가 실행 중입니다.
프로세스
Java 파일을 저장할 디렉터리를 만듭니다.
$ mkdir -p <application_home>/src/main/java/com/example/client새 디렉터리로 이동합니다.
$ cd <application_home>/src/main/java/com/example/client다음 콘텐츠를 사용하여 Java 파일
App.java를 생성합니다.package com.example.client; import java.io.IOException; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.security.NoSuchAlgorithmException; import java.security.Security; import java.util.Properties; import javax.net.ssl.SSLContext; import org.wildfly.security.auth.client.WildFlyElytronClientDefaultSSLContextProvider; public class App { public static void main( String[] args ) { String url = "https://localhost:8443/";1 try { Security.insertProviderAt(new WildFlyElytronClientDefaultSSLContextProvider("src/wildfly-config-two-way-tls.xml"), 1);2 HttpClient httpClient = HttpClient.newBuilder().sslContext(SSLContext.getDefault()).build(); HttpRequest request = HttpRequest.newBuilder() .uri(URI.create(url)) .GET() .build(); HttpResponse<Void> httpRresponse = httpClient.send(request, BodyHandlers.discarding()); String sslContext = SSLContext.getDefault().getProvider().getName();3 System.out.println ("\nSSL Default SSLContext is: " + sslContext); } catch (NoSuchAlgorithmException | IOException | InterruptedException e) { e.printStackTrace(); } System.exit(0); } }<
application_home> /src디렉터리에 "wildfly-config-two-way-tls.xml"이라는 클라이언트 구성 파일을 만듭니다.<?xml version="1.0" encoding="UTF-8"?> <configuration> <authentication-client xmlns="urn:elytron:client:1.7"> <key-stores> <key-store name="truststore" type="PKCS12"> <file name="${path_to_client_truststore}/client.truststore.p12"/> <key-store-clear-password password="secret"/> </key-store> <key-store name="keystore" type="PKCS12"> <file name="${path_to_client_keystore}/exampleclient.keystore.pkcs12"/> <key-store-clear-password password="secret"/> </key-store> </key-stores> <ssl-contexts> <ssl-context name="client-context"> <trust-store key-store-name="truststore"/> <key-store-ssl-certificate key-store-name="keystore" alias="exampleclientkeystore"> <key-store-clear-password password="secret"/> </key-store-ssl-certificate> </ssl-context> </ssl-contexts> <ssl-context-rules> <rule use-ssl-context="client-context"/> </ssl-context-rules> </authentication-client> </configuration>다음 위치 소유자 값을 실제 경로로 바꿉니다.
- ${path_to_client_truststore}
- ${path_to_client_keystore}
검증
- < application_home> 디렉터리 로 이동합니다.
애플리케이션을 실행합니다.
$ mvn compile exec:java출력 예
INFO: ELY00001: WildFly Elytron version 2.0.0.Final-redhat-00001 SSL Default SSLContext is: WildFlyElytronClientDefaultSSLContextProvider