Skip to content

Commit db82ca4

Browse files
authored
Move default SSLContext to main module (#289)
1 parent b3215fa commit db82ca4

File tree

5 files changed

+19
-26
lines changed

5 files changed

+19
-26
lines changed

avaje-jex-ssl/src/main/java/io/avaje/jex/ssl/DSslConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ String identityPassword() {
3838
return identityPassword;
3939
}
4040

41-
public X509ExtendedKeyManager keyManager() {
41+
X509ExtendedKeyManager keyManager() {
4242
return keyManager;
4343
}
4444

45-
public KeyStore keyStore() {
45+
KeyStore keyStore() {
4646
return keyStore;
4747
}
4848

avaje-jex-ssl/src/main/java/io/avaje/jex/ssl/DSslPlugin.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.util.function.Consumer;
44

5-
import javax.net.ssl.SSLContext;
6-
75
import com.sun.net.httpserver.HttpsConfigurator;
86

97
import io.avaje.jex.Jex;
@@ -17,12 +15,7 @@ final class DSslPlugin implements SslPlugin {
1715
final var config = new DSslConfig();
1816

1917
consumer.accept(config);
20-
sslConfigurator = SslHttpConfigurator.create(config);
21-
}
22-
23-
DSslPlugin(SSLContext context) {
24-
25-
this.sslConfigurator = new HttpsConfigurator(context);
18+
sslConfigurator = SSLConfigurator.create(config);
2619
}
2720

2821
@Override

avaje-jex-ssl/src/main/java/io/avaje/jex/ssl/SslHttpConfigurator.java renamed to avaje-jex-ssl/src/main/java/io/avaje/jex/ssl/SSLConfigurator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
import com.sun.net.httpserver.HttpsConfigurator;
1818
import com.sun.net.httpserver.HttpsParameters;
1919

20-
final class SslHttpConfigurator extends HttpsConfigurator {
20+
final class SSLConfigurator extends HttpsConfigurator {
2121

2222
private static final String SSL_PROTOCOL = "TLSv1.3";
2323
private static final String KEY_MANAGER_ALGORITHM = "SunX509";
2424
private static final String TRUST_MANAGER_ALGORITHM = "PKIX";
2525

2626
private final boolean clientAuth;
2727

28-
public SslHttpConfigurator(SSLContext context, boolean clientAuth) {
28+
public SSLConfigurator(SSLContext context, boolean clientAuth) {
2929
super(context);
3030
this.clientAuth = clientAuth;
3131
}
@@ -37,7 +37,7 @@ public void configure(HttpsParameters params) {
3737
params.setSSLParameters(sslParams);
3838
}
3939

40-
static SslHttpConfigurator create(DSslConfig sslConfig) throws SslConfigException {
40+
static SSLConfigurator create(DSslConfig sslConfig) throws SslConfigException {
4141
try {
4242
var sslContext = createContext(sslConfig);
4343

@@ -46,7 +46,7 @@ static SslHttpConfigurator create(DSslConfig sslConfig) throws SslConfigExceptio
4646

4747
sslContext.init(keyManagers, trustManagers, new SecureRandom());
4848

49-
return new SslHttpConfigurator(sslContext, trustManagers != null);
49+
return new SSLConfigurator(sslContext, trustManagers != null);
5050
} catch (Exception e) {
5151
throw new SslConfigException("Failed to build SSLContext", e);
5252
}

avaje-jex-ssl/src/main/java/io/avaje/jex/ssl/SslPlugin.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.util.function.Consumer;
44

5-
import javax.net.ssl.SSLContext;
6-
75
import io.avaje.jex.spi.JexPlugin;
86

97
/**
@@ -24,15 +22,6 @@
2422
*/
2523
public sealed interface SslPlugin extends JexPlugin permits DSslPlugin {
2624

27-
/**
28-
* Configure SSL using an existing SSL Context
29-
*
30-
* @param sslContext The SSL Context to use for SSL.
31-
*/
32-
static SslPlugin fromSslContext(SSLContext sslContext) {
33-
return new DSslPlugin(sslContext);
34-
}
35-
3625
/**
3726
* Configure SSL using an existing SSL Context
3827
*

avaje-jex/src/main/java/io/avaje/jex/JexConfig.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.concurrent.Executors;
66
import java.util.function.Consumer;
77

8+
import javax.net.ssl.SSLContext;
9+
810
import com.sun.net.httpserver.HttpServer;
911
import com.sun.net.httpserver.HttpsConfigurator;
1012
import com.sun.net.httpserver.spi.HttpServerProvider;
@@ -80,12 +82,21 @@ public interface JexConfig {
8082
HttpsConfigurator httpsConfig();
8183

8284
/**
83-
* Enable https with the provided {@link HttpsConfigurator}
85+
* Enable HTTPS and SSL with the provided {@link HttpsConfigurator}
8486
*
8587
* @param https The HTTPS configuration.
8688
*/
8789
JexConfig httpsConfig(HttpsConfigurator https);
8890

91+
/**
92+
* Configure HTTPS and SSL with the provided {@link SSLContext}.
93+
*
94+
* @param sslContext The SSLContext to use for HTTPS.
95+
*/
96+
default JexConfig httpsConfig(SSLContext sslContext) {
97+
return httpsConfig(new HttpsConfigurator(sslContext));
98+
}
99+
89100
/** Returns whether trailing slashes in request URIs are ignored. */
90101
boolean ignoreTrailingSlashes();
91102

0 commit comments

Comments
 (0)