23
23
import io .netty .util .concurrent .EventExecutorGroup ;
24
24
import io .netty .util .internal .logging .InternalLoggerFactory ;
25
25
26
- import java .io .IOException ;
27
26
import java .net .URI ;
28
- import java .security .GeneralSecurityException ;
29
27
30
28
import org .neo4j .driver .AuthToken ;
31
29
import org .neo4j .driver .AuthTokens ;
50
48
import org .neo4j .driver .internal .retry .ExponentialBackoffRetryLogic ;
51
49
import org .neo4j .driver .internal .retry .RetryLogic ;
52
50
import org .neo4j .driver .internal .retry .RetrySettings ;
53
- import org .neo4j .driver .internal .security .SecurityPlanImpl ;
54
51
import org .neo4j .driver .internal .security .SecurityPlan ;
55
52
import org .neo4j .driver .internal .spi .ConnectionPool ;
56
53
import org .neo4j .driver .internal .spi .ConnectionProvider ;
59
56
import org .neo4j .driver .net .ServerAddressResolver ;
60
57
61
58
import static java .lang .String .format ;
59
+ import static org .neo4j .driver .internal .Scheme .isRoutingScheme ;
62
60
import static org .neo4j .driver .internal .cluster .IdentityResolver .IDENTITY_RESOLVER ;
63
61
import static org .neo4j .driver .internal .metrics .MetricsProvider .METRICS_DISABLED_PROVIDER ;
64
- import static org .neo4j .driver .internal .security .SecurityPlanImpl .insecure ;
65
62
import static org .neo4j .driver .internal .util .ErrorUtil .addSuppressed ;
66
63
67
64
public class DriverFactory
68
65
{
69
- public static final String BOLT_URI_SCHEME = "bolt" ;
70
- public static final String BOLT_ROUTING_URI_SCHEME = "neo4j" ;
71
66
72
67
public final Driver newInstance ( URI uri , AuthToken authToken , RoutingSettings routingSettings ,
73
- RetrySettings retrySettings , Config config )
68
+ RetrySettings retrySettings , Config config , SecurityPlan securityPlan )
74
69
{
75
- return newInstance ( uri , authToken , routingSettings , retrySettings , config , null , null );
70
+ return newInstance ( uri , authToken , routingSettings , retrySettings , config , null , securityPlan );
76
71
}
77
72
78
73
public final Driver newInstance ( URI uri , AuthToken authToken , RoutingSettings routingSettings ,
79
- RetrySettings retrySettings , Config config , EventLoopGroup eventLoopGroup , SecurityPlan customSecurityPlan )
74
+ RetrySettings retrySettings , Config config , EventLoopGroup eventLoopGroup , SecurityPlan securityPlan )
80
75
{
81
76
Bootstrap bootstrap ;
82
77
boolean ownsEventLoopGroup ;
@@ -96,16 +91,6 @@ public final Driver newInstance ( URI uri, AuthToken authToken, RoutingSettings
96
91
BoltServerAddress address = new BoltServerAddress ( uri );
97
92
RoutingSettings newRoutingSettings = routingSettings .withRoutingContext ( new RoutingContext ( uri ) );
98
93
99
- SecurityPlan securityPlan ;
100
- if ( customSecurityPlan != null )
101
- {
102
- securityPlan = customSecurityPlan ;
103
- }
104
- else
105
- {
106
- securityPlan = createSecurityPlan ( address , config );
107
- }
108
-
109
94
InternalLoggerFactory .setDefaultFactory ( new NettyLogging ( config .logging () ) );
110
95
EventExecutorGroup eventExecutorGroup = bootstrap .config ().group ();
111
96
RetryLogic retryLogic = createRetryLogic ( retrySettings , eventExecutorGroup , config .logging () );
@@ -148,20 +133,21 @@ protected ChannelConnector createConnector( ConnectionSettings settings, Securit
148
133
}
149
134
150
135
private InternalDriver createDriver ( URI uri , SecurityPlan securityPlan , BoltServerAddress address , ConnectionPool connectionPool ,
151
- EventExecutorGroup eventExecutorGroup , RoutingSettings routingSettings , RetryLogic retryLogic , MetricsProvider metricsProvider , Config config )
136
+ EventExecutorGroup eventExecutorGroup , RoutingSettings routingSettings , RetryLogic retryLogic ,
137
+ MetricsProvider metricsProvider , Config config )
152
138
{
153
139
try
154
140
{
155
141
String scheme = uri .getScheme ().toLowerCase ();
156
- switch ( scheme )
142
+
143
+ if ( isRoutingScheme ( scheme ) )
144
+ {
145
+ return createRoutingDriver ( securityPlan , address , connectionPool , eventExecutorGroup , routingSettings , retryLogic , metricsProvider , config );
146
+ }
147
+ else
157
148
{
158
- case BOLT_URI_SCHEME :
159
149
assertNoRoutingContext ( uri , routingSettings );
160
150
return createDirectDriver ( securityPlan , address , connectionPool , retryLogic , metricsProvider , config );
161
- case BOLT_ROUTING_URI_SCHEME :
162
- return createRoutingDriver ( securityPlan , address , connectionPool , eventExecutorGroup , routingSettings , retryLogic , metricsProvider , config );
163
- default :
164
- throw new ClientException ( format ( "Unsupported URI scheme: %s" , scheme ) );
165
151
}
166
152
}
167
153
catch ( Throwable driverError )
@@ -287,47 +273,6 @@ protected Bootstrap createBootstrap( EventLoopGroup eventLoopGroup )
287
273
return BootstrapFactory .newBootstrap ( eventLoopGroup );
288
274
}
289
275
290
- private static SecurityPlan createSecurityPlan ( BoltServerAddress address , Config config )
291
- {
292
- try
293
- {
294
- return createSecurityPlanImpl ( config );
295
- }
296
- catch ( GeneralSecurityException | IOException ex )
297
- {
298
- throw new ClientException ( "Unable to establish SSL parameters" , ex );
299
- }
300
- }
301
-
302
- /*
303
- * Establish a complete SecurityPlan based on the details provided for
304
- * driver construction.
305
- */
306
- private static SecurityPlan createSecurityPlanImpl ( Config config )
307
- throws GeneralSecurityException , IOException
308
- {
309
- if ( config .encrypted () )
310
- {
311
- Config .TrustStrategy trustStrategy = config .trustStrategy ();
312
- boolean hostnameVerificationEnabled = trustStrategy .isHostnameVerificationEnabled ();
313
- switch ( trustStrategy .strategy () )
314
- {
315
- case TRUST_CUSTOM_CA_SIGNED_CERTIFICATES :
316
- return SecurityPlanImpl .forCustomCASignedCertificates ( trustStrategy .certFile (), hostnameVerificationEnabled );
317
- case TRUST_SYSTEM_CA_SIGNED_CERTIFICATES :
318
- return SecurityPlanImpl .forSystemCASignedCertificates ( hostnameVerificationEnabled );
319
- case TRUST_ALL_CERTIFICATES :
320
- return SecurityPlanImpl .forAllCertificates ( hostnameVerificationEnabled );
321
- default :
322
- throw new ClientException (
323
- "Unknown TLS authentication strategy: " + trustStrategy .strategy ().name () );
324
- }
325
- }
326
- else
327
- {
328
- return insecure ();
329
- }
330
- }
331
276
332
277
private static void assertNoRoutingContext ( URI uri , RoutingSettings routingSettings )
333
278
{
0 commit comments