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;

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;

RoleRecord getRole( String roleName ) throws InvalidArgumentsException;

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

/**
* 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
public RoleRecord newRole( String roleName, String... usernames )
public void newRole( String roleName, String... usernames )
{
return null;
}

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

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

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

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

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

return role;
}

@Override
Expand All @@ -506,14 +504,13 @@ public boolean deleteRole( String roleName ) throws IOException, InvalidArgument
else
{
// 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;
}

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

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

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

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

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

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

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

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

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

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

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

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

@Override
Expand Down

0 comments on commit 6bd19d9

Please sign in to comment.