Skip to content

Commit

Permalink
[RESTEASY-1926]: Add needClientAuth and wantClientAuth support
Browse files Browse the repository at this point in the history
  • Loading branch information
jimma committed Jun 22, 2021
1 parent 6243158 commit 9e619ec
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

import javax.net.ssl.SSLParameters;

import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.MediaTypeMap;
import org.jboss.resteasy.core.ResteasyContext;
Expand Down Expand Up @@ -1708,17 +1710,18 @@ public SeBootstrap.Instance get()
server.setRootResourcePath(configuration.rootPath());
if (configuration.sslContext() != null)
{
SSLParameters sslParams = configuration.sslContext().getDefaultSSLParameters();
if (configuration.sslClientAuthentication() == SeBootstrap.Configuration.SSLClientAuthentication.NONE)
{
configuration.sslContext().getDefaultSSLParameters().setNeedClientAuth(false);
sslParams.setNeedClientAuth(false);
}
if (configuration.sslClientAuthentication() == SeBootstrap.Configuration.SSLClientAuthentication.OPTIONAL)
{
configuration.sslContext().getDefaultSSLParameters().setWantClientAuth(true);
sslParams.setWantClientAuth(true);
}
if (configuration.sslClientAuthentication() == SeBootstrap.Configuration.SSLClientAuthentication.MANDATORY)
{
configuration.sslContext().getDefaultSSLParameters().setNeedClientAuth(true);
sslParams.setNeedClientAuth(true);
}
server.setSSLContext(configuration.sslContext());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.net.InetSocketAddress;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLParameters;

import org.jboss.resteasy.plugins.server.embedded.EmbeddedJaxrsServer;
import org.jboss.resteasy.plugins.server.embedded.SecurityDomain;
Expand All @@ -13,6 +14,7 @@

import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer;

/**
Expand All @@ -30,6 +32,7 @@ public class SunHttpJaxrsServer implements EmbeddedJaxrsServer<SunHttpJaxrsServe
protected int runtimePort = -1;
protected String host;
protected SSLContext sslContext;
protected SSLParameters sslParameters;
protected String protocol;
protected ResteasyDeployment deployment;
private EmbeddedServerHelper serverHelper = new EmbeddedServerHelper();
Expand Down Expand Up @@ -79,6 +82,17 @@ public void setProtocol(String protocol)
{
this.protocol = protocol;
}

public SSLParameters getSslParameters()
{
return sslParameters;
}

public void setSslParameters(SSLParameters sslParameters)
{
this.sslParameters = sslParameters;
}

@Override
public SunHttpJaxrsServer start()
{
Expand All @@ -103,7 +117,22 @@ public SunHttpJaxrsServer start()
}
if ("HTTPS".equalsIgnoreCase(protocol) || this.sslContext != null) {
HttpsServer sslServer = HttpsServer.create(address, 10);
sslServer.setHttpsConfigurator(new HttpsConfigurator(sslContext));
sslServer.setHttpsConfigurator(new HttpsConfigurator(sslContext)
{
@Override
public void configure(HttpsParameters params)
{
if (sslParameters != null)
{
params.setSSLParameters(sslParameters);
}
else
{
super.configure(params);
}

}
});
httpServer = sslServer;
} else {
httpServer = HttpServer.create(address, 10);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void testFailedStartJAXRS() throws Exception {
}
}
@Test
public void testSSL() throws Exception {
public void testSSLClientAuthNone() throws Exception {
SeBootstrap.Configuration configuration = SeBootstrap.Configuration.builder().host("localhost").port(8443)
.rootPath("ssl").sslContext(SSLCerts.DEFAULT_SERVER_KEYSTORE.getSslContext())
.sslClientAuthentication(SSLClientAuthentication.NONE).build();
Expand All @@ -69,8 +69,7 @@ public void testSSL() throws Exception {
client.target("https://localhost:8443/ssl/produces/string").request().get(String.class));
}

@org.junit.Ignore
//TODO:Fix this
@Test
public void testSSLClientAuthRequired() throws Exception {
SeBootstrap.Configuration configuration = SeBootstrap.Configuration.builder().host("localhost").port(8444)
.rootPath("needclientauth").sslContext(SSLCerts.DEFAULT_SERVER_KEYSTORE.getSslContext())
Expand All @@ -86,8 +85,7 @@ public void testSSLClientAuthRequired() throws Exception {
}
}

@org.junit.Ignore
//TODO:Fix this
@Test
public void testSSLClientAuthWant() throws Exception {
SeBootstrap.Configuration configuration = SeBootstrap.Configuration.builder().host("localhost").port(8445)
.rootPath("wantclientauth").sslContext(SSLCerts.DEFAULT_SERVER_KEYSTORE.getSslContext())
Expand Down

0 comments on commit 9e619ec

Please sign in to comment.