in redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java [908:971]
public boolean removeUserRole( String roleName, String username, DirContext context )
throws MappingException
{
String groupName = findGroupName( roleName );
if ( groupName == null )
{
log.warn( "no group found for role '{}", roleName );
return false;
}
NamingEnumeration<SearchResult> namingEnumeration = null;
try
{
SearchControls searchControls = new SearchControls( );
searchControls.setDerefLinkFlag( true );
searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
String filter = "objectClass=" + getLdapGroupClass( );
namingEnumeration = context.search( groupNameAttribute + "=" + groupName + "," + getGroupsDn( ), filter, searchControls );
if ( namingEnumeration.hasMore( ) )
{
SearchResult searchResult = namingEnumeration.next( );
Attribute attribute = searchResult.getAttributes( ).get( getLdapGroupMemberAttribute( ) );
if ( attribute != null )
{
BasicAttribute basicAttribute = new BasicAttribute( getLdapGroupMemberAttribute( ) );
basicAttribute.add( this.userIdAttribute + "=" + username + "," + getGroupsDn( ) );
context.modifyAttributes( groupNameAttribute + "=" + groupName + "," + getGroupsDn( ), new ModificationItem[]{
new ModificationItem( DirContext.REMOVE_ATTRIBUTE, basicAttribute )} );
}
return true;
}
return false;
}
catch ( LdapException e )
{
throw new MappingException( e.getMessage( ), e );
}
catch ( NamingException e )
{
throw new MappingException( e.getMessage( ), e );
}
finally
{
if ( namingEnumeration != null )
{
try
{
namingEnumeration.close( );
}
catch ( NamingException e )
{
log.warn( "failed to close search results", e );
}
}
}
}