@@ -19,6 +19,7 @@ public class RestClientCertConfiguration {
19
19
20
20
private char [] bobPassword = "bobpassword" .toCharArray ();
21
21
private char [] tomPassword = "tompassword" .toCharArray ();
22
+ private char [] alicePassword = "alicepassword" .toCharArray ();
22
23
23
24
@ Value ("classpath:alice-keystore.p12" )
24
25
private Resource aliceKeystoreResource ;
@@ -28,38 +29,31 @@ public class RestClientCertConfiguration {
28
29
29
30
@ Value ("classpath:client-truststore.jks" )
30
31
private Resource truststoreResource ;
31
- private char [] alicePassword = "alicepassword" .toCharArray ();
32
32
33
33
@ Bean
34
- public HttpComponentsClientHttpRequestFactory serverTomClientHttpRequestFactory () throws Exception {
35
- SSLContext sslContext = SSLContextBuilder
34
+ public SSLContext serverTomSSLContext () throws Exception {
35
+ return SSLContextBuilder
36
36
.create ()
37
37
.loadKeyMaterial (inStream2File (tomKeystoreResource ), tomPassword , tomPassword )
38
38
.loadTrustMaterial (inStream2File (truststoreResource ), bobPassword )
39
39
.build ();
40
-
41
- HttpClient client = HttpClients .custom ()
42
- .setSSLContext (sslContext )
43
- .build ();
44
-
45
- return new HttpComponentsClientHttpRequestFactory (client );
46
40
}
47
41
48
42
@ Bean
49
- public HttpComponentsClientHttpRequestFactory serverAliceClientHttpRequestFactory () throws Exception {
50
- SSLContext sslContext = SSLContextBuilder
43
+ public SSLContext serverAliceSSLContext () throws Exception {
44
+ return SSLContextBuilder
51
45
.create ()
52
46
.loadKeyMaterial (inStream2File (aliceKeystoreResource ), alicePassword , alicePassword )
53
47
.loadTrustMaterial (inStream2File (truststoreResource ), bobPassword )
54
48
.build ();
55
-
56
- HttpClient client = HttpClients .custom ()
57
- .setSSLContext (sslContext )
58
- .build ();
59
-
60
- return new HttpComponentsClientHttpRequestFactory (client );
61
49
}
62
50
51
+
52
+ /**
53
+ * The ugly need to generate a File from a InputStream - because SSLContextBuild.loadKeyMaterial only accepts File,
54
+ * but retrieving Files from within Spring Boot Fatjars is only possible through Resources ->
55
+ * see https://stackoverflow.com/questions/25869428/classpath-resource-not-found-when-running-as-jar
56
+ */
63
57
private File inStream2File (Resource resource ) {
64
58
try {
65
59
File tempFile = File .createTempFile ("file" , ".tmp" );
0 commit comments