Skip to content

Commit

Permalink
Merge pull request wildfly-security-incubator#137 from cam-rod/Issue#122
Browse files Browse the repository at this point in the history
Update client-default-ssl-context to EE10 & WF 27.0.1.
  • Loading branch information
fjuma authored Jan 4, 2023
2 parents 3f19c8b + d5ed8d0 commit 6bbae80
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 41 deletions.
8 changes: 1 addition & 7 deletions client-default-ssl-context-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This example uses java security API to dynamically register a provider. Alternatively, you can use static provider registration and add the `WildFlyElytronClientDefaultSSLContextProvider` to the list of providers in java.security file.

* Configure mutual SSL on your running WildFly instance. You can read how to do it here: [two-way SSL in Wildfly](https://docs.jboss.org/author/display/WFLY/Using%20the%20Elytron%20Subsystem.html#110231569_UsingtheElytronSubsystem-EnableTwowaySSL%2FTLSinWildFlyforApplications)
* Configure mutual SSL on your running WildFly instance. You can read how to do it here: [two-way SSL in Wildfly](https://docs.wildfly.org/27/WildFly_Elytron_Security.html#enable-two-way-ssltls-in-wildfly-for-applications)

* Configure path to client's keystore and truststore in this project's *wildfly-config-two-way-tls.xml* accordingly

Expand All @@ -24,9 +24,3 @@ mvn clean install -Dtest=Client.java

The test registers the `WildFlyElytronClientDefaultSSLContextProvider` with *wildfly-config-two-way-tls.xml* file to have the highest priority. The RESTEasy client which had `SSLContext.getDefault()` configured as its SSLContext can therefore connect to the running server instance.

* To restore wildfly server configuration go to the source folder of this example and run:
```
{path_to_wildfly}/bin/jboss-cli.sh --connect --file=restore.cli
```


22 changes: 10 additions & 12 deletions client-default-ssl-context-provider/client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@
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>elytron-quickstart</groupId>
<version>2.0.0.Alpha1-SNAPSHOT</version>
<artifactId>client</artifactId>

<parent>
<groupId>org.wildfly.security.examples</groupId>
<artifactId>client-default-ssl-context-parent</artifactId>
<version>2.0.0.Alpha1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>client-default-ssl-context-client</artifactId>
<packaging>jar</packaging>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.14.0.Final</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.wildfly/wildfly-client-all -->
<dependency>
<groupId>org.wildfly.security</groupId>
<artifactId>wildfly-elytron-client</artifactId>
<version>1.19.0.Final</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.client</groupId>
<artifactId>wildfly-client-config</artifactId>
<version>1.0.1.Final</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
/*
* JBoss, Home of Professional Open Source.
* Copyright 2020 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.security.NoSuchAlgorithmException;
import java.security.Security;

import javax.net.ssl.SSLContext;

import org.jboss.resteasy.client.jaxrs.ResteasyClient;
import org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder;
import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl;
import org.junit.Assert;
import org.junit.Test;
import org.wildfly.security.auth.client.WildFlyElytronClientDefaultSSLContextProvider;

import javax.net.ssl.SSLContext;
import javax.ws.rs.core.Response;
import java.security.NoSuchAlgorithmException;
import java.security.Security;
import jakarta.ws.rs.core.Response;

/**
* Client test method demonstrating how WildFlyElytronClientDefaultSSLContextProvider can be used to register JVM wide default client SSLContext.
Expand All @@ -19,9 +40,9 @@ public class Client {
@Test
public void test() throws NoSuchAlgorithmException {
Security.insertProviderAt(new WildFlyElytronClientDefaultSSLContextProvider("src/test/wildfly-config-two-way-tls.xml"), 1);
ResteasyClient client = new ResteasyClientBuilder().sslContext(SSLContext.getDefault()).hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
ResteasyClient client = new ResteasyClientBuilderImpl().sslContext(SSLContext.getDefault()).hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
Response response = client
.target("https://127.0.0.1:8443/client-default-ssl-context-provider/rest/hello")
.target("https://127.0.0.1:8443/client-default-ssl-context-endpoint/rest/hello")
.request().get();
Assert.assertNotNull(response);
Assert.assertEquals(200, response.getStatus());
Expand Down
45 changes: 45 additions & 0 deletions client-default-ssl-context-provider/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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>org.wildfly.security.examples</groupId>
<version>2.0.0.Alpha1-SNAPSHOT</version>
<artifactId>client-default-ssl-context-parent</artifactId>

<packaging>pom</packaging>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>

<version.wildfly>27.0.1.Final</version.wildfly>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-ee-with-tools</artifactId>
<scope>import</scope>
<type>pom</type>
<version>${version.wildfly}</version>
</dependency>

<!-- Project Dependecy -->
<dependency>
<groupId>org.wildfly.security.examples</groupId>
<artifactId>client-default-ssl-context-parent</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<modules>
<module>client</module>
<module>server</module>
</modules>

</project>
25 changes: 13 additions & 12 deletions client-default-ssl-context-provider/server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,22 @@
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>elytron-quickstart</groupId>
<version>2.0.0.Alpha1-SNAPSHOT</version>
<artifactId>client-default-ssl-context-provider</artifactId>
<packaging>war</packaging>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<parent>
<groupId>org.wildfly.security.examples</groupId>
<artifactId>client-default-ssl-context-parent</artifactId>
<version>2.0.0.Alpha1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>client-default-ssl-context-endpoint</artifactId>

<packaging>war</packaging>

<dependencies>
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_2.1_spec</artifactId>
<version>1.0.2.Final</version>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
</dependencies>

Expand All @@ -27,7 +28,7 @@
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.0.Final</version>
<version>4.0.0.Final</version>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.wildfly.elytron.resteasy.client.example;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;

/**
* Simple REST endpoint that you can access after accepting server's certificate and providing client's certificate.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/
package org.wildfly.elytron.resteasy.client.example;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

/**
* JAXActivator is an arbitrary name, what is important is that javax.ws.rs.core.Application is extended
Expand Down

0 comments on commit 6bbae80

Please sign in to comment.