|
20 | 20 |
|
21 | 21 | package com.arangodb.example.ssl; |
22 | 22 |
|
23 | | -import static org.hamcrest.Matchers.is; |
24 | | -import static org.hamcrest.Matchers.notNullValue; |
25 | | -import static org.junit.Assert.assertThat; |
26 | | - |
27 | | -import java.security.KeyStore; |
| 23 | +import com.arangodb.ArangoDB; |
| 24 | +import com.arangodb.entity.ArangoDBVersion; |
| 25 | +import org.junit.Ignore; |
| 26 | +import org.junit.Test; |
28 | 27 |
|
29 | 28 | import javax.net.ssl.KeyManagerFactory; |
30 | 29 | import javax.net.ssl.SSLContext; |
31 | 30 | import javax.net.ssl.TrustManagerFactory; |
| 31 | +import java.security.KeyStore; |
32 | 32 |
|
33 | | -import org.junit.Ignore; |
34 | | -import org.junit.Test; |
35 | | - |
36 | | -import com.arangodb.ArangoDB; |
37 | | -import com.arangodb.entity.ArangoDBVersion; |
| 33 | +import static org.hamcrest.Matchers.is; |
| 34 | +import static org.hamcrest.Matchers.notNullValue; |
| 35 | +import static org.junit.Assert.assertThat; |
38 | 36 |
|
39 | 37 | /** |
40 | 38 | * @author Mark Vollmary |
41 | | - * |
42 | 39 | */ |
43 | 40 | public class SslExample { |
44 | 41 |
|
45 | | - /*- |
46 | | - * a SSL trust store |
47 | | - * |
48 | | - * create the trust store for the self signed certificate: |
49 | | - * keytool -import -alias "my arangodb server cert" -file UnitTests/server.pem -keystore example.truststore |
50 | | - * |
51 | | - * Documentation: |
52 | | - * https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/conn/ssl/SSLSocketFactory.html |
53 | | - */ |
54 | | - private static final String SSL_TRUSTSTORE = "/example.truststore"; |
55 | | - private static final String SSL_TRUSTSTORE_PASSWORD = "12345678"; |
| 42 | + /*- |
| 43 | + * a SSL trust store |
| 44 | + * |
| 45 | + * create the trust store for the self signed certificate: |
| 46 | + * keytool -import -alias "my arangodb server cert" -file server.pem -keystore example.truststore |
| 47 | + * |
| 48 | + * Documentation: |
| 49 | + * https://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/org/apache/http/conn/ssl/SSLSocketFactory.html |
| 50 | + */ |
| 51 | + private static final String SSL_TRUSTSTORE = "/example.truststore"; |
| 52 | + private static final String SSL_TRUSTSTORE_PASSWORD = "12345678"; |
56 | 53 |
|
57 | | - @Test |
| 54 | + @Test |
58 | 55 | @Ignore |
59 | | - public void connect() throws Exception { |
60 | | - final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); |
61 | | - ks.load(this.getClass().getResourceAsStream(SSL_TRUSTSTORE), SSL_TRUSTSTORE_PASSWORD.toCharArray()); |
| 56 | + public void connect() throws Exception { |
| 57 | + final KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); |
| 58 | + ks.load(this.getClass().getResourceAsStream(SSL_TRUSTSTORE), SSL_TRUSTSTORE_PASSWORD.toCharArray()); |
| 59 | + |
| 60 | + final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
| 61 | + kmf.init(ks, SSL_TRUSTSTORE_PASSWORD.toCharArray()); |
62 | 62 |
|
63 | | - final KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
64 | | - kmf.init(ks, SSL_TRUSTSTORE_PASSWORD.toCharArray()); |
| 63 | + final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
| 64 | + tmf.init(ks); |
65 | 65 |
|
66 | | - final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); |
67 | | - tmf.init(ks); |
| 66 | + final SSLContext sc = SSLContext.getInstance("TLS"); |
| 67 | + sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); |
68 | 68 |
|
69 | | - final SSLContext sc = SSLContext.getInstance("TLS"); |
70 | | - sc.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null); |
71 | 69 |
|
72 | | - final ArangoDB arangoDB = new ArangoDB.Builder() |
73 | | - .loadProperties(SslExample.class.getResourceAsStream("/arangodb-ssl.properties")).useSsl(true) |
74 | | - .sslContext(sc).build(); |
75 | | - final ArangoDBVersion version = arangoDB.getVersion(); |
76 | | - assertThat(version, is(notNullValue())); |
77 | | - } |
| 70 | + final ArangoDB arangoDB = new ArangoDB.Builder() |
| 71 | + .host("172.28.4.1", 8529) |
| 72 | + .password("test") |
| 73 | + .useSsl(true) |
| 74 | + .sslContext(sc) |
| 75 | + .build(); |
| 76 | + final ArangoDBVersion version = arangoDB.getVersion(); |
| 77 | + assertThat(version, is(notNullValue())); |
| 78 | + System.out.println(version.getVersion()); |
| 79 | + } |
78 | 80 |
|
79 | 81 | } |
0 commit comments