Skip to content

Commit 509def1

Browse files
bogglejakewins
authored andcommitted
Draft Authentication interface
1 parent 9d30dcc commit 509def1

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package org.neo4j.driver.v1;
2+
3+
import org.neo4j.driver.v1.auth.BasicAuthenticationScheme;
4+
5+
/**
6+
* This class provides access to all authentication schemes supported by
7+
* this driver implementation
8+
*/
9+
public final class AuthenticationSchemes
10+
{
11+
private AuthenticationSchemes()
12+
{
13+
throw new UnsupportedOperationException();
14+
}
15+
16+
public static final BasicAuthenticationScheme BASIC = null;
17+
}

driver/src/main/java/org/neo4j/driver/v1/Driver.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.neo4j.driver.internal.InternalSession;
2424
import org.neo4j.driver.internal.pool.InternalConnectionPool;
2525
import org.neo4j.driver.internal.spi.ConnectionPool;
26+
import org.neo4j.driver.v1.auth.AuthenticationScheme;
2627

2728
/**
2829
* A Neo4j database driver, through which you can create {@link Session sessions} to run statements against the database.
@@ -83,6 +84,18 @@ public Driver( URI url, Config config )
8384
this.config = config;
8485
}
8586

87+
/**
88+
* Create a new driver instance
89+
*
90+
* @param url of the remote database to connect to
91+
* @param token to be used for authentication
92+
* @param config settings of the driver
93+
*/
94+
public Driver( URI url, AuthenticationScheme.Token token, Config config )
95+
{
96+
throw new UnsupportedOperationException();
97+
}
98+
8699
/**
87100
* Establish a session
88101
* @return a session that could be used to run {@link Session#run(String) a statement} or
@@ -93,6 +106,20 @@ public Session session()
93106
return new InternalSession( connections.acquire( url ), config.logging().getLog( "session" ) );
94107
}
95108

109+
/**
110+
* Change the password of the authenticated user on the database server.
111+
*
112+
* More precisely, change the credentials of the currently authenticated principal (the user) of this driver
113+
* <b>on the database server</b>. If this is successful, use the provided new credentials for authentication
114+
* of any sessions that may have to be created by the underlying session pool in the future.
115+
*
116+
* @param newCredential the new credentials of the authenticated user
117+
*/
118+
public void updateCredentials( AuthenticationScheme.Credential newCredential )
119+
{
120+
throw new UnsupportedOperationException();
121+
}
122+
96123
/**
97124
* Close all the resources assigned to this driver
98125
* @throws Exception any error that might happen when releasing all resources
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package org.neo4j.driver.v1.auth;
2+
3+
/**
4+
* An authentication scheme is a method of performing authentication against a Neo4j graph database
5+
*/
6+
public interface AuthenticationScheme
7+
{
8+
/**
9+
* @return the (human readable) name of the authentication scheme
10+
*/
11+
String name();
12+
13+
/**
14+
* A credential encapsulates a critical piece of information (like a password or a certificate)
15+
* for verifying the identify of a subject (a user)
16+
*
17+
* @see AuthenticationScheme
18+
*/
19+
interface Credential
20+
{
21+
/**
22+
* @return the authentication scheme in which this credential may be used
23+
*/
24+
AuthenticationScheme scheme();
25+
}
26+
27+
/**
28+
* A token is the combination of a credential and an associated principal. A principal is a piece
29+
* of information (like a user name) that uniquely describes the subject (user) whose identity
30+
* is verified by the credential.
31+
*
32+
* @see Credential
33+
* @see AuthenticationScheme
34+
*/
35+
interface Token extends Credential
36+
{
37+
/**
38+
* @return the principal of the encapsulated credential
39+
*/
40+
Object principal();
41+
}
42+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.neo4j.driver.v1.auth;
2+
3+
/**
4+
* Basic authentication uses the user name as the principal and transmits
5+
* the password as its credential as clear text as part of establishing a session
6+
*
7+
* Basis authentication should not be used over unencrypted connections
8+
*
9+
* @see AuthenticationScheme
10+
*/
11+
public interface BasicAuthenticationScheme extends AuthenticationScheme
12+
{
13+
/**
14+
* Obtain a {@link Credential} for authentication using the basic authentication scheme
15+
*
16+
* @param password to be used
17+
* @return a credential for authentication using the basic authentication scheme
18+
*/
19+
Credential credential( String password );
20+
21+
/**
22+
* Obtain a {@link Token} for authentication using the basic authentication scheme
23+
*
24+
* @param userName of the user to be authenticated
25+
* @param password of the user to be authenticated
26+
* @return token for authentication using the basic authentication scheme
27+
*/
28+
Token token( String userName, String password );
29+
30+
interface Credential extends AuthenticationScheme.Credential
31+
{
32+
@Override
33+
BasicAuthenticationScheme scheme();
34+
}
35+
36+
interface Token extends AuthenticationScheme.Token, Credential
37+
{
38+
/**
39+
* @return user name of the user to be authenticated using this token
40+
*/
41+
@Override
42+
String principal();
43+
}
44+
}

0 commit comments

Comments
 (0)