]> source.dussan.org Git - archiva.git/commitdiff
improve performance to retrieve all groups of a user
authorOlivier Lamy <olamy@apache.org>
Thu, 3 Jan 2013 21:42:57 +0000 (21:42 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 3 Jan 2013 21:42:57 +0000 (21:42 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1428612 13f79535-47bb-0310-9956-ffa450edef68

redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java
redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java

index 097136d5af21f4d089edd40fff20d86b6e64dd83..4df4bc731672ec0208abf23c82a1ef1cef1a9e1b 100644 (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 )
index 0694a33323cf03041e823edfadd59caa816c14e1..bf977ea908ecf52e50cbd8edfef2830e2f2478ea 100644 (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
     {