From: Olivier Lamy Date: Thu, 3 Jan 2013 21:42:57 +0000 (+0000) Subject: improve performance to retrieve all groups of a user X-Git-Tag: redback-2.1~159 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=94ee7125c3a5b08e34f9aabfbb232651c5d73eb8;p=archiva.git 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 --- diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java index 097136d5a..4df4bc731 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java @@ -230,7 +230,7 @@ public class DefaultLdapRoleMapper { // TODO caching and a filter with uid - List allGroups = getAllGroups(); + /*List allGroups = getAllGroups(); List userGroups = new ArrayList(); for ( String group : allGroups ) { @@ -241,7 +241,8 @@ public class DefaultLdapRoleMapper } } return userGroups; - /* + */ + List userGroups = new ArrayList(); 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 allMembers = new ArrayList(); + namingEnumeration = context.search( getGroupsDn(), filter, searchControls ); while ( namingEnumeration.hasMore() ) { SearchResult searchResult = namingEnumeration.next(); + List allMembers = new ArrayList(); + 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 ) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java index 0694a3332..bf977ea90 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java @@ -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> 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 {