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:
Olivier Lamy 2013-01-03 21:42:57 +00:00
parent f7507f4aed
commit 94ee7125c3
2 changed files with 24 additions and 17 deletions

View File

@ -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 )

View File

@ -57,9 +57,9 @@ import java.util.Map;
/**
* @author Olivier Lamy
*/
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class TestLdapRoleMapper
extends TestCase
{
@ -67,11 +67,11 @@ public class TestLdapRoleMapper
Logger log = LoggerFactory.getLogger( getClass() );
@Inject
@Named( value = "userManager#ldap" )
@Named(value = "userManager#ldap")
private UserManager userManager;
@Inject
@Named( value = "apacheDS#test" )
@Named(value = "apacheDS#test")
private ApacheDs apacheDs;
private String suffix;
@ -84,7 +84,7 @@ public class TestLdapRoleMapper
private LdapCacheService ldapCacheService;
@Inject
@Named( value = "ldapRoleMapper#test" )
@Named(value = "ldapRoleMapper#test")
LdapRoleMapper ldapRoleMapper;
private Map<String, List<String>> usersPerGroup;
@ -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
{