Skip to content

Commit

Permalink
Change transaction and connection management procedures to be built-ins
Browse files Browse the repository at this point in the history
  • Loading branch information
boggle authored and systay committed Sep 14, 2016
1 parent 1148c06 commit be3079b
Show file tree
Hide file tree
Showing 18 changed files with 405 additions and 309 deletions.
Expand Up @@ -28,6 +28,8 @@
*/ */
public class AuthorizationViolationException extends RuntimeException implements Status.HasStatus public class AuthorizationViolationException extends RuntimeException implements Status.HasStatus
{ {
public static final String PERMISSION_DENIED = "Permission denied.";

private Status statusCode = Status.Security.Forbidden; private Status statusCode = Status.Security.Forbidden;


public AuthorizationViolationException( String msg, Status statusCode ) public AuthorizationViolationException( String msg, Status statusCode )
Expand Down
Expand Up @@ -35,8 +35,13 @@ public class ExecutingQuery
private final Map<String, Object> queryParameters; private final Map<String, Object> queryParameters;
private final long startTime; private final long startTime;


public ExecutingQuery( long queryId, String authSubjectName, String queryText, Map<String,Object> public ExecutingQuery(
queryParameters, long startTime ) long queryId,
String authSubjectName,
String queryText,
Map<String,Object> queryParameters,
long startTime
)
{ {
this.queryId = queryId; this.queryId = queryId;
this.authSubjectName = authSubjectName; this.authSubjectName = authSubjectName;
Expand Down
Expand Up @@ -53,6 +53,22 @@ public interface AuthSubject extends AccessMode
*/ */
String username(); String username();


/**
* @param username a username
* @return true if the provided username is the underlying user name of this subject
*/
boolean hasUsername( String username );

/**
* Ensure that the provided username is the name of an existing user known to the system.
*
* @param username a username
* @throws InvalidArgumentsException if the provided user name is not the name of an existing user
*/
default void ensureUserExistsWithName( String username ) throws InvalidArgumentsException {
throw new InvalidArgumentsException( "User '" + username + "' does not exit." );
}

/** /**
* Implementation to use when authentication has not yet been performed. Allows nothing. * Implementation to use when authentication has not yet been performed. Allows nothing.
*/ */
Expand All @@ -77,7 +93,7 @@ public void setPassword( String password, boolean requirePasswordChange )
} }


@Override @Override
public boolean doesUsernameMatch( String username ) public boolean hasUsername( String username )
{ {
return false; return false;
} }
Expand Down Expand Up @@ -196,7 +212,7 @@ public void setPassword( String password, boolean requirePasswordChange )
} }


@Override @Override
public boolean doesUsernameMatch( String username ) public boolean hasUsername( String username )
{ {
return false; return false;
} }
Expand All @@ -207,6 +223,4 @@ public boolean allowsProcedureWith( String[] roleNames )
return true; return true;
} }
}; };

boolean doesUsernameMatch( String username );
} }
Expand Up @@ -416,6 +416,12 @@ private Procedures setupProcedures( PlatformModule platform, EditionModule editi
internalLog.error( "Failed to register built-in edition procedures at start up: " + e.getMessage() ); internalLog.error( "Failed to register built-in edition procedures at start up: " + e.getMessage() );
} }


// Service providers
for ( ProceduresProvider candidate : Service.load( ProceduresProvider.class ) )
{
candidate.registerProcedures( procedures );
}

return procedures; return procedures;
} }


Expand Down
Expand Up @@ -56,7 +56,7 @@ public void createUser(
public void deleteUser( @Name( "username" ) String username ) throws InvalidArgumentsException, IOException public void deleteUser( @Name( "username" ) String username ) throws InvalidArgumentsException, IOException
{ {
BasicAuthSubject subject = BasicAuthSubject.castOrFail( authSubject ); BasicAuthSubject subject = BasicAuthSubject.castOrFail( authSubject );
if ( subject.doesUsernameMatch( username ) ) if ( subject.hasUsername( username ) )
{ {
throw new InvalidArgumentsException( "Deleting yourself (user '" + username + "') is not allowed." ); throw new InvalidArgumentsException( "Deleting yourself (user '" + username + "') is not allowed." );
} }
Expand Down
Expand Up @@ -161,7 +161,7 @@ public void setPassword( AuthSubject authSubject, String username, String passwo
{ {
BasicAuthSubject basicAuthSubject = BasicAuthSubject.castOrFail( authSubject ); BasicAuthSubject basicAuthSubject = BasicAuthSubject.castOrFail( authSubject );


if ( !basicAuthSubject.doesUsernameMatch( username ) ) if ( !basicAuthSubject.hasUsername( username ) )
{ {
throw new AuthorizationViolationException( "Invalid attempt to change the password for user " + username ); throw new AuthorizationViolationException( "Invalid attempt to change the password for user " + username );
} }
Expand Down
Expand Up @@ -113,7 +113,7 @@ public BasicAuthManager getAuthManager()
} }


@Override @Override
public boolean doesUsernameMatch( String username ) public boolean hasUsername( String username )
{ {
return user.name().equals( username ); return user.name().equals( username );
} }
Expand Down
Expand Up @@ -85,7 +85,6 @@
import org.neo4j.kernel.internal.DefaultKernelData; import org.neo4j.kernel.internal.DefaultKernelData;
import org.neo4j.kernel.lifecycle.LifeSupport; import org.neo4j.kernel.lifecycle.LifeSupport;
import org.neo4j.kernel.lifecycle.LifecycleStatus; import org.neo4j.kernel.lifecycle.LifecycleStatus;
import org.neo4j.logging.Log;
import org.neo4j.logging.LogProvider; import org.neo4j.logging.LogProvider;
import org.neo4j.storageengine.api.StorageEngine; import org.neo4j.storageengine.api.StorageEngine;
import org.neo4j.time.Clocks; import org.neo4j.time.Clocks;
Expand Down
Expand Up @@ -30,4 +30,18 @@ public interface EnterpriseAuthSubject extends AuthSubject
* Enterprise has the concept of users being admins. * Enterprise has the concept of users being admins.
*/ */
boolean isAdmin(); boolean isAdmin();

static EnterpriseAuthSubject castOrFail( AuthSubject authSubject )
{
return castOrFail( EnterpriseAuthSubject.class, authSubject );
}

static <T extends EnterpriseAuthSubject> T castOrFail( Class<T> clazz, AuthSubject authSubject )
{
if ( !(clazz.isInstance( authSubject )) )
{
throw new IllegalArgumentException( "Incorrect AuthSubject type " + authSubject.getClass().getTypeName() );
}
return clazz.cast( authSubject );
}
} }

0 comments on commit be3079b

Please sign in to comment.