improve performance to retrieve all groups of a user
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1428612 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f7507f4aed
commit
94ee7125c3
|
@ -230,7 +230,7 @@ public class DefaultLdapRoleMapper
|
|||
{
|
||||
// TODO caching and a filter with uid
|
||||
|
||||
List<String> allGroups = getAllGroups();
|
||||
/*List<String> allGroups = getAllGroups();
|
||||
List<String> userGroups = new ArrayList<String>();
|
||||
for ( String group : allGroups )
|
||||
{
|
||||
|
@ -241,7 +241,8 @@ public class DefaultLdapRoleMapper
|
|||
}
|
||||
}
|
||||
return userGroups;
|
||||
/*
|
||||
*/
|
||||
|
||||
List<String> userGroups = new ArrayList<String>();
|
||||
|
||||
LdapConnection ldapConnection = null;
|
||||
|
@ -258,23 +259,21 @@ public class DefaultLdapRoleMapper
|
|||
searchControls.setDerefLinkFlag( true );
|
||||
searchControls.setSearchScope( SearchControls.SUBTREE_SCOPE );
|
||||
|
||||
//String filter =
|
||||
// "(&(objectClass=" + getLdapGroupClass() + ") (uniquemember=uid" + username + "," + this.getGroupsDn()
|
||||
// + "))";
|
||||
|
||||
String filter =
|
||||
new StringBuilder().append( "(&" ).append( "(objectClass=" + getLdapGroupClass() + ")" ).append(
|
||||
"(uniquemember=" ).append( "uid=" + username + "," + this.getBaseDn() ).append( ")" ).append(
|
||||
")" ).toString();
|
||||
|
||||
namingEnumeration = context.search( getGroupsDn(), filter, searchControls );
|
||||
log.debug( "filter: {}", filter );
|
||||
|
||||
List<String> allMembers = new ArrayList<String>();
|
||||
namingEnumeration = context.search( getGroupsDn(), filter, searchControls );
|
||||
|
||||
while ( namingEnumeration.hasMore() )
|
||||
{
|
||||
SearchResult searchResult = namingEnumeration.next();
|
||||
|
||||
List<String> allMembers = new ArrayList<String>();
|
||||
|
||||
Attribute uniqueMemberAttr = searchResult.getAttributes().get( "uniquemember" );
|
||||
|
||||
if ( uniqueMemberAttr != null )
|
||||
|
@ -293,6 +292,15 @@ public class DefaultLdapRoleMapper
|
|||
close( allMembersEnum );
|
||||
}
|
||||
|
||||
if ( allMembers.contains( username ) )
|
||||
{
|
||||
String groupName = searchResult.getName();
|
||||
// cn=blabla we only want bla bla
|
||||
groupName = StringUtils.substringAfter( groupName, "=" );
|
||||
userGroups.add( groupName );
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -315,7 +323,7 @@ public class DefaultLdapRoleMapper
|
|||
}
|
||||
close( namingEnumeration );
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
private void close( NamingEnumeration namingEnumeration )
|
||||
|
|
|
@ -188,7 +188,7 @@ public class TestLdapRoleMapper
|
|||
BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
|
||||
for ( String user : users )
|
||||
{
|
||||
basicAttribute.add( "uid=" + user + ",dc=archiva,dc=apache,dc=org" );
|
||||
basicAttribute.add( "uid=" + user + "," + suffix );// dc=archiva,dc=apache,dc=org" );
|
||||
}
|
||||
|
||||
attributes.put( basicAttribute );
|
||||
|
@ -234,7 +234,6 @@ public class TestLdapRoleMapper
|
|||
}
|
||||
|
||||
|
||||
|
||||
private void assertExist( DirContext context, String dn, String attribute, String value )
|
||||
throws NamingException
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue