Skip to content

Commit

Permalink
Remove dependency on RoleRecord from EnterpriseUserManager
Browse files Browse the repository at this point in the history
  • Loading branch information
Lojjs committed Jul 18, 2018
1 parent a4841ab commit 6bd19d9
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 43 deletions.
Expand Up @@ -37,13 +37,11 @@ public interface EnterpriseUserManager extends UserManager


void activateUser( String username, boolean requirePasswordChange ) throws IOException, InvalidArgumentsException; void activateUser( String username, boolean requirePasswordChange ) throws IOException, InvalidArgumentsException;


RoleRecord newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException; void newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException;


boolean deleteRole( String roleName ) throws IOException, InvalidArgumentsException; boolean deleteRole( String roleName ) throws IOException, InvalidArgumentsException;


RoleRecord getRole( String roleName ) throws InvalidArgumentsException; void assertRoleExists( String roleName ) throws InvalidArgumentsException;

RoleRecord silentlyGetRole( String roleName );


/** /**
* Assign a role to a user. The role and the user have to exist. * Assign a role to a user. The role and the user have to exist.
Expand Down Expand Up @@ -88,9 +86,8 @@ public void activateUser( String username, boolean requirePasswordChange )
} }


@Override @Override
public RoleRecord newRole( String roleName, String... usernames ) public void newRole( String roleName, String... usernames )
{ {
return null;
} }


@Override @Override
Expand All @@ -100,15 +97,8 @@ public boolean deleteRole( String roleName )
} }


@Override @Override
public RoleRecord getRole( String roleName ) public void assertRoleExists( String roleName )
{
return null;
}

@Override
public RoleRecord silentlyGetRole( String roleName )
{ {
return null;
} }


@Override @Override
Expand Down
Expand Up @@ -467,7 +467,7 @@ public User newUser( String username, String initialPassword, boolean requirePas
} }


@Override @Override
public RoleRecord newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException public void newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException
{ {
roleRepository.assertValidRoleName( roleName ); roleRepository.assertValidRoleName( roleName );
for ( String username : usernames ) for ( String username : usernames )
Expand All @@ -486,8 +486,6 @@ public RoleRecord newRole( String roleName, String... usernames ) throws IOExcep
} }
roleRepository.create( role ); roleRepository.create( role );
} }

return role;
} }


@Override @Override
Expand All @@ -506,14 +504,13 @@ public boolean deleteRole( String roleName ) throws IOException, InvalidArgument
else else
{ {
// We should not get here, but if we do the assert will fail and give a nice error msg // We should not get here, but if we do the assert will fail and give a nice error msg
getRole( roleName ); assertRoleExists( roleName );
} }
} }
return result; return result;
} }


@Override private RoleRecord getRole( String roleName ) throws InvalidArgumentsException
public RoleRecord getRole( String roleName ) throws InvalidArgumentsException
{ {
RoleRecord role = roleRepository.getRoleByName( roleName ); RoleRecord role = roleRepository.getRoleByName( roleName );
if ( role == null ) if ( role == null )
Expand All @@ -524,7 +521,12 @@ public RoleRecord getRole( String roleName ) throws InvalidArgumentsException
} }


@Override @Override
public RoleRecord silentlyGetRole( String roleName ) public void assertRoleExists( String roleName ) throws InvalidArgumentsException
{
getRole( roleName );
}

private RoleRecord silentlyGetRole( String roleName )
{ {
return roleRepository.getRoleByName( roleName ); return roleRepository.getRoleByName( roleName );
} }
Expand Down
Expand Up @@ -146,15 +146,14 @@ public User silentlyGetUser( String username )
} }


@Override @Override
public RoleRecord newRole( String roleName, String... usernames ) public void newRole( String roleName, String... usernames )
throws IOException, InvalidArgumentsException, AuthorizationViolationException throws IOException, InvalidArgumentsException, AuthorizationViolationException
{ {
try try
{ {
assertUserManager(); assertUserManager();
RoleRecord newRole = userManager.newRole( roleName, usernames ); userManager.newRole( roleName, usernames );
securityLog.info( subject, "created role `%s`", roleName ); securityLog.info( subject, "created role `%s`", roleName );
return newRole;
} }
catch ( AuthorizationViolationException | IOException | InvalidArgumentsException e ) catch ( AuthorizationViolationException | IOException | InvalidArgumentsException e )
{ {
Expand Down Expand Up @@ -233,15 +232,9 @@ public Set<String> getAllUsernames() throws AuthorizationViolationException
} }


@Override @Override
public RoleRecord getRole( String roleName ) throws InvalidArgumentsException public void assertRoleExists( String roleName ) throws InvalidArgumentsException
{ {
return userManager.getRole( roleName ); userManager.assertRoleExists( roleName );
}

@Override
public RoleRecord silentlyGetRole( String roleName )
{
return userManager.silentlyGetRole( roleName );
} }


@Override @Override
Expand Down
Expand Up @@ -596,7 +596,7 @@ public void shouldAllowAddingAndRemovingUserFromMultipleRoles() throws Exception
public void shouldCreateRole() throws Exception public void shouldCreateRole() throws Exception
{ {
assertEmpty( adminSubject, "CALL dbms.security.createRole('new_role')" ); assertEmpty( adminSubject, "CALL dbms.security.createRole('new_role')" );
userManager.getRole( "new_role" ); userManager.assertRoleExists( "new_role" );
} }


@Test @Test
Expand Down
Expand Up @@ -184,14 +184,14 @@ public void activateUser( String username, boolean requirePasswordChange )
} }


@Override @Override
public RoleRecord newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException public void newRole( String roleName, String... usernames ) throws IOException, InvalidArgumentsException
{ {
if ( failNextCall ) if ( failNextCall )
{ {
failNextCall = false; failNextCall = false;
throw new IOException( "newRoleException" ); throw new IOException( "newRoleException" );
} }
return delegate.newRole( roleName, usernames ); delegate.newRole( roleName, usernames );
} }


@Override @Override
Expand All @@ -206,20 +206,14 @@ public boolean deleteRole( String roleName ) throws IOException, InvalidArgument
} }


@Override @Override
public RoleRecord getRole( String roleName ) throws InvalidArgumentsException public void assertRoleExists( String roleName ) throws InvalidArgumentsException
{ {
if ( failNextCall ) if ( failNextCall )
{ {
failNextCall = false; failNextCall = false;
throw new InvalidArgumentsException( "getRoleException" ); throw new InvalidArgumentsException( "getRoleException" );
} }
return delegate.getRole( roleName ); delegate.assertRoleExists( roleName );
}

@Override
public RoleRecord silentlyGetRole( String roleName )
{
return delegate.silentlyGetRole( roleName );
} }


@Override @Override
Expand Down

0 comments on commit 6bd19d9

Please sign in to comment.