* @author Olivier Lamy
* @since 2.1
*/
-@Service("ldapRoleMapper#default")
+@Service( "ldapRoleMapper#default" )
public class DefaultLdapRoleMapper
implements LdapRoleMapper
{
private LdapConnectionFactory ldapConnectionFactory;
@Inject
- @Named(value = "userConfiguration#default")
+ @Named( value = "userConfiguration#default" )
private UserConfiguration userConf;
//---------------------------
}
}
- public List<String> getRoles( String username, DirContext context )
+ public List<String> getRoles( String username, DirContext context, Collection<String> realRoles )
throws MappingException
{
List<String> groups = getGroups( username, context );
Collection<String> rolesPerGroup = rolesMapping.get( group );
if ( rolesPerGroup != null )
{
- for ( String role : rolesPerGroup )
- {
- roles.add( role );
- }
+ roles.addAll( rolesPerGroup );
}
- /*else
+ else
{
- if ( this.useDefaultRoleName )
+ if ( this.useDefaultRoleName && realRoles != null && realRoles.contains( group ) )
{
roles.add( group );
}
- }*/
+ }
}
return new ArrayList<String>( roles );
@Inject
LdapConnectionFactory ldapConnectionFactory;
+ List<String> roleNames =
+ Arrays.asList( "Archiva System Administrator", "Internal Repo Manager", "Internal Repo Observer" );
+
LdapConnection ldapConnection;
DirContext context;
public void getRoles()
throws Exception
{
- List<String> roles = ldapRoleMapper.getRoles( "admin", getDirContext() );
+ List<String> roles = ldapRoleMapper.getRoles( "admin", getDirContext(), roleNames );
log.info( "roles for admin: {}", roles );
"Internal Repo Manager",
"Internal Repo Observer" );
- roles = ldapRoleMapper.getRoles( "user.7", getDirContext() );
+ roles = ldapRoleMapper.getRoles( "user.7", getDirContext(), roleNames );
log.info( "roles for user.7: {}", roles );
Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "Archiva System Administrator",
"Internal Repo Observer" );
- roles = ldapRoleMapper.getRoles( "user.8", getDirContext() );
+ roles = ldapRoleMapper.getRoles( "user.8", getDirContext(), roleNames );
log.info( "roles for user.8: {}", roles );
}
+ protected List<String> getRealRoles()
+ throws RbacManagerException
+ {
+ List<Role> roles = this.rbacImpl.getAllRoles();
+ List<String> roleNames = new ArrayList<String>( roles.size() );
+ for ( Role role : roles )
+ {
+ roleNames.add( role.getName() );
+ }
+ return roleNames;
+ }
+
public Collection<Role> getAssignedRoles( String username )
throws RbacManagerException
{
ldapConnection = ldapConnectionFactory.getConnection();
context = ldapConnection.getDirContext();
- List<String> roleNames = ldapRoleMapper.getRoles( username, context );
+ List<String> roleNames = ldapRoleMapper.getRoles( username, context, getRealRoles() );
if ( roleNames.isEmpty() )
{
context = ldapConnection.getDirContext();
List<String> allRoles = ldapRoleMapper.getAllRoles( context );
- final List<String> userRoles = ldapRoleMapper.getRoles( username, context );
+ final List<String> userRoles = ldapRoleMapper.getRoles( username, context, getRealRoles() );
List<Role> unassignedRoles = new ArrayList<Role>();
{
ldapConnection = ldapConnectionFactory.getConnection();
context = ldapConnection.getDirContext();
- List<String> roles = ldapRoleMapper.getRoles( username, context );
+ List<String> roles = ldapRoleMapper.getRoles( username, context, getRealRoles() );
return new UserAssignmentImpl( username, roles );
}
context = ldapConnection.getDirContext();
List<String> allRoles = ldapRoleMapper.getAllRoles( context );
- List<String> currentUserRoles = ldapRoleMapper.getRoles( userAssignment.getPrincipal(), context );
+ List<String> currentUserRoles =
+ ldapRoleMapper.getRoles( userAssignment.getPrincipal(), context, getRealRoles() );
for ( String role : userAssignment.getRoleNames() )
{
{
ldapConnection = ldapConnectionFactory.getConnection();
context = ldapConnection.getDirContext();
- List<String> roles = ldapRoleMapper.getRoles( principal, context );
+ List<String> roles = ldapRoleMapper.getRoles( principal, context, getRealRoles() );
if ( roles == null || roles.isEmpty() )
{
return false;
}
return true;
}
+ catch ( RbacManagerException e )
+ {
+ log.warn( "fail to call userAssignmentExists: {}", e.getMessage() );
+ }
catch ( LdapException e )
{
log.warn( "fail to call userAssignmentExists: {}", e.getMessage() );