1818 */
1919package org .neo4j .driver ;
2020
21- import java .util .Map ;
22- import java .util .Objects ;
23-
24- import org .neo4j .driver .internal .security .InternalAuthToken ;
25-
2621import static java .util .Collections .singletonMap ;
2722import static org .neo4j .driver .Values .value ;
2823import static org .neo4j .driver .internal .security .InternalAuthToken .CREDENTIALS_KEY ;
3227import static org .neo4j .driver .internal .security .InternalAuthToken .SCHEME_KEY ;
3328import static org .neo4j .driver .internal .util .Iterables .newHashMapWithSize ;
3429
30+ import java .util .Map ;
31+ import java .util .Objects ;
32+ import org .neo4j .driver .internal .security .InternalAuthToken ;
33+
3534/**
3635 * This is a listing of the various methods of authentication supported by this
3736 * driver. The scheme used must be supported by the Neo4j Instance you are connecting
3837 * to.
3938 * @see GraphDatabase#driver(String, AuthToken)
4039 * @since 1.0
4140 */
42- public class AuthTokens
43- {
41+ public class AuthTokens {
4442 /**
4543 * The basic authentication scheme, using a username and a password.
4644 * @param username this is the "principal", identifying who this token represents
@@ -49,9 +47,8 @@ public class AuthTokens
4947 * @see GraphDatabase#driver(String, AuthToken)
5048 * @throws NullPointerException when either username or password is {@code null}
5149 */
52- public static AuthToken basic ( String username , String password )
53- {
54- return basic ( username , password , null );
50+ public static AuthToken basic (String username , String password ) {
51+ return basic (username , password , null );
5552 }
5653
5754 /**
@@ -63,20 +60,18 @@ public static AuthToken basic( String username, String password )
6360 * @see GraphDatabase#driver(String, AuthToken)
6461 * @throws NullPointerException when either username or password is {@code null}
6562 */
66- public static AuthToken basic ( String username , String password , String realm )
67- {
68- Objects .requireNonNull ( username , "Username can't be null" );
69- Objects .requireNonNull ( password , "Password can't be null" );
63+ public static AuthToken basic (String username , String password , String realm ) {
64+ Objects .requireNonNull (username , "Username can't be null" );
65+ Objects .requireNonNull (password , "Password can't be null" );
7066
71- Map <String ,Value > map = newHashMapWithSize ( 4 );
72- map .put ( SCHEME_KEY , value ( "basic" ) );
73- map .put ( PRINCIPAL_KEY , value ( username ) );
74- map .put ( CREDENTIALS_KEY , value ( password ) );
75- if ( realm != null )
76- {
77- map .put ( REALM_KEY , value ( realm ) );
67+ Map <String , Value > map = newHashMapWithSize (4 );
68+ map .put (SCHEME_KEY , value ("basic" ));
69+ map .put (PRINCIPAL_KEY , value (username ));
70+ map .put (CREDENTIALS_KEY , value (password ));
71+ if (realm != null ) {
72+ map .put (REALM_KEY , value (realm ));
7873 }
79- return new InternalAuthToken ( map );
74+ return new InternalAuthToken (map );
8075 }
8176
8277 /**
@@ -87,14 +82,13 @@ public static AuthToken basic( String username, String password, String realm )
8782 * @throws NullPointerException when token is {@code null}
8883 * @see GraphDatabase#driver(String, AuthToken)
8984 */
90- public static AuthToken bearer ( String token )
91- {
92- Objects .requireNonNull ( token , "Token can't be null" );
85+ public static AuthToken bearer (String token ) {
86+ Objects .requireNonNull (token , "Token can't be null" );
9387
94- Map <String ,Value > map = newHashMapWithSize ( 2 );
95- map .put ( SCHEME_KEY , value ( "bearer" ) );
96- map .put ( CREDENTIALS_KEY , value ( token ) );
97- return new InternalAuthToken ( map );
88+ Map <String , Value > map = newHashMapWithSize (2 );
89+ map .put (SCHEME_KEY , value ("bearer" ) );
90+ map .put (CREDENTIALS_KEY , value (token ) );
91+ return new InternalAuthToken (map );
9892 }
9993
10094 /**
@@ -106,15 +100,14 @@ public static AuthToken bearer( String token )
106100 * @see GraphDatabase#driver(String, AuthToken)
107101 * @since 1.3
108102 */
109- public static AuthToken kerberos ( String base64EncodedTicket )
110- {
111- Objects .requireNonNull ( base64EncodedTicket , "Ticket can't be null" );
103+ public static AuthToken kerberos (String base64EncodedTicket ) {
104+ Objects .requireNonNull (base64EncodedTicket , "Ticket can't be null" );
112105
113- Map <String ,Value > map = newHashMapWithSize ( 3 );
114- map .put ( SCHEME_KEY , value ( "kerberos" ) );
115- map .put ( PRINCIPAL_KEY , value ( "" ) ); // This empty string is required for backwards compatibility.
116- map .put ( CREDENTIALS_KEY , value ( base64EncodedTicket ) );
117- return new InternalAuthToken ( map );
106+ Map <String , Value > map = newHashMapWithSize (3 );
107+ map .put (SCHEME_KEY , value ("kerberos" ) );
108+ map .put (PRINCIPAL_KEY , value ("" ) ); // This empty string is required for backwards compatibility.
109+ map .put (CREDENTIALS_KEY , value (base64EncodedTicket ) );
110+ return new InternalAuthToken (map );
118111 }
119112
120113 /**
@@ -127,9 +120,8 @@ public static AuthToken kerberos( String base64EncodedTicket )
127120 * @see GraphDatabase#driver(String, AuthToken)
128121 * @throws NullPointerException when either principal, credentials or scheme is {@code null}
129122 */
130- public static AuthToken custom ( String principal , String credentials , String realm , String scheme )
131- {
132- return custom ( principal , credentials , realm , scheme , null );
123+ public static AuthToken custom (String principal , String credentials , String realm , String scheme ) {
124+ return custom (principal , credentials , realm , scheme , null );
133125 }
134126
135127 /**
@@ -143,25 +135,23 @@ public static AuthToken custom( String principal, String credentials, String rea
143135 * @see GraphDatabase#driver(String, AuthToken)
144136 * @throws NullPointerException when either principal, credentials or scheme is {@code null}
145137 */
146- public static AuthToken custom ( String principal , String credentials , String realm , String scheme , Map < String , Object > parameters )
147- {
148- Objects .requireNonNull ( principal , "Principal can't be null" );
149- Objects .requireNonNull ( credentials , "Credentials can't be null" );
150- Objects .requireNonNull ( scheme , "Scheme can't be null" );
138+ public static AuthToken custom (
139+ String principal , String credentials , String realm , String scheme , Map < String , Object > parameters ) {
140+ Objects .requireNonNull (principal , "Principal can't be null" );
141+ Objects .requireNonNull (credentials , "Credentials can't be null" );
142+ Objects .requireNonNull (scheme , "Scheme can't be null" );
151143
152- Map <String ,Value > map = newHashMapWithSize ( 5 );
153- map .put ( SCHEME_KEY , value ( scheme ) );
154- map .put ( PRINCIPAL_KEY , value ( principal ) );
155- map .put ( CREDENTIALS_KEY , value ( credentials ) );
156- if ( realm != null )
157- {
158- map .put ( REALM_KEY , value ( realm ) );
144+ Map <String , Value > map = newHashMapWithSize (5 );
145+ map .put (SCHEME_KEY , value (scheme ));
146+ map .put (PRINCIPAL_KEY , value (principal ));
147+ map .put (CREDENTIALS_KEY , value (credentials ));
148+ if (realm != null ) {
149+ map .put (REALM_KEY , value (realm ));
159150 }
160- if ( parameters != null )
161- {
162- map .put ( PARAMETERS_KEY , value ( parameters ) );
151+ if (parameters != null ) {
152+ map .put (PARAMETERS_KEY , value (parameters ));
163153 }
164- return new InternalAuthToken ( map );
154+ return new InternalAuthToken (map );
165155 }
166156
167157 /**
@@ -170,8 +160,7 @@ public static AuthToken custom( String principal, String credentials, String rea
170160 * @return an authentication token that can be used to connect to Neo4j instances with auth disabled
171161 * @see GraphDatabase#driver(String, AuthToken)
172162 */
173- public static AuthToken none ()
174- {
175- return new InternalAuthToken ( singletonMap ( SCHEME_KEY , value ( "none" ) ) );
163+ public static AuthToken none () {
164+ return new InternalAuthToken (singletonMap (SCHEME_KEY , value ("none" )));
176165 }
177166}
0 commit comments