|
15 | 15 | */ |
16 | 16 | package nl.altindag.server.config; |
17 | 17 |
|
| 18 | +import nl.altindag.server.model.EnhanceableSslBundle; |
18 | 19 | import nl.altindag.ssl.SSLFactory; |
19 | 20 | import org.springframework.beans.factory.annotation.Value; |
20 | | -import org.springframework.boot.ssl.NoSuchSslBundleException; |
21 | | -import org.springframework.boot.ssl.SslBundle; |
22 | | -import org.springframework.boot.ssl.SslBundleKey; |
23 | | -import org.springframework.boot.ssl.SslBundles; |
24 | | -import org.springframework.boot.ssl.SslManagerBundle; |
25 | | -import org.springframework.boot.ssl.SslOptions; |
26 | | -import org.springframework.boot.ssl.SslStoreBundle; |
| 21 | +import org.springframework.boot.ssl.SslBundleRegistry; |
27 | 22 | import org.springframework.context.annotation.Bean; |
28 | 23 | import org.springframework.context.annotation.Configuration; |
29 | 24 |
|
30 | | -import javax.net.ssl.KeyManagerFactory; |
31 | | -import javax.net.ssl.TrustManagerFactory; |
32 | | -import java.util.Collections; |
33 | | -import java.util.List; |
34 | | -import java.util.function.BiConsumer; |
35 | | -import java.util.function.Consumer; |
36 | | - |
37 | 25 | @Configuration |
38 | 26 | public class SSLConfig { |
39 | 27 |
|
40 | | - @Bean |
41 | | - public SSLFactory sslFactory(@Value("${ssl.keystore-path}") String keyStorePath, |
42 | | - @Value("${ssl.keystore-password}") char[] keyStorePassword, |
43 | | - @Value("${ssl.truststore-path}") String trustStorePath, |
44 | | - @Value("${ssl.truststore-password}") char[] trustStorePassword, |
45 | | - @Value("${ssl.client-auth}") boolean isClientAuthenticationRequired) { |
| 28 | + private final SSLFactory sslFactory; |
46 | 29 |
|
47 | | - return SSLFactory.builder() |
| 30 | + public SSLConfig(@Value("${ssl.keystore-path}") String keyStorePath, |
| 31 | + @Value("${ssl.keystore-password}") char[] keyStorePassword, |
| 32 | + @Value("${ssl.truststore-path}") String trustStorePath, |
| 33 | + @Value("${ssl.truststore-password}") char[] trustStorePassword, |
| 34 | + @Value("${ssl.client-auth}") boolean isClientAuthenticationRequired, |
| 35 | + SslBundleRegistry registry) { |
| 36 | + |
| 37 | + this.sslFactory = SSLFactory.builder() |
48 | 38 | .withSwappableIdentityMaterial() |
49 | 39 | .withSwappableTrustMaterial() |
50 | 40 | .withIdentityMaterial(keyStorePath, keyStorePassword) |
51 | 41 | .withTrustMaterial(trustStorePath, trustStorePassword) |
52 | 42 | .withNeedClientAuthentication(isClientAuthenticationRequired) |
53 | 43 | .build(); |
| 44 | + |
| 45 | + registry.registerBundle("reloadable-ssl-bundle", new EnhanceableSslBundle(sslFactory)); |
54 | 46 | } |
55 | 47 |
|
56 | 48 | @Bean |
57 | | - public SslBundles sslBundles(SSLFactory sslFactory) { |
58 | | - return new SslBundles() { |
59 | | - @Override |
60 | | - public SslBundle getBundle(String name) throws NoSuchSslBundleException { |
61 | | - return new SslBundle() { |
62 | | - @Override |
63 | | - public SslStoreBundle getStores() { |
64 | | - return null; |
65 | | - } |
66 | | - |
67 | | - @Override |
68 | | - public SslBundleKey getKey() { |
69 | | - return null; |
70 | | - } |
71 | | - |
72 | | - @Override |
73 | | - public SslOptions getOptions() { |
74 | | - return null; |
75 | | - } |
76 | | - |
77 | | - @Override |
78 | | - public String getProtocol() { |
79 | | - return ""; |
80 | | - } |
81 | | - |
82 | | - @Override |
83 | | - public SslManagerBundle getManagers() { |
84 | | - return new SslManagerBundle() { |
85 | | - @Override |
86 | | - public KeyManagerFactory getKeyManagerFactory() { |
87 | | - return sslFactory.getKeyManagerFactory().get(); |
88 | | - } |
89 | | - |
90 | | - @Override |
91 | | - public TrustManagerFactory getTrustManagerFactory() { |
92 | | - return sslFactory.getTrustManagerFactory().get(); |
93 | | - } |
94 | | - }; |
95 | | - } |
96 | | - }; |
97 | | - } |
98 | | - |
99 | | - @Override |
100 | | - public void addBundleUpdateHandler(String name, Consumer<SslBundle> updateHandler) throws NoSuchSslBundleException { |
101 | | - |
102 | | - } |
103 | | - |
104 | | - @Override |
105 | | - public void addBundleRegisterHandler(BiConsumer<String, SslBundle> registerHandler) { |
106 | | - |
107 | | - } |
108 | | - |
109 | | - @Override |
110 | | - public List<String> getBundleNames() { |
111 | | - return Collections.emptyList(); |
112 | | - } |
113 | | - }; |
| 49 | + public SSLFactory sslFactory() { |
| 50 | + return sslFactory; |
114 | 51 | } |
115 | 52 |
|
116 | 53 | } |
0 commit comments