You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by ol...@apache.org on 2013/01/03 21:50:23 UTC

svn commit: r1428586 - in /archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src: main/java/org/apache/archiva/redback/rbac/ldap/ main/resources/META-INF/ test/java/org/apache/archiva/redback/rbac/ldap/ test/resou...

Author: olamy
Date: Thu Jan  3 20:50:23 2013
New Revision: 1428586

URL: http://svn.apache.org/viewvc?rev=1428586&view=rev
Log:
baseDn can be different from groups dn

Modified:
    archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java
    archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/resources/META-INF/spring-context.xml
    archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java
    archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml

Modified: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java?rev=1428586&r1=1428585&r2=1428586&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java (original)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java Thu Jan  3 20:50:23 2013
@@ -69,12 +69,16 @@ public class DefaultLdapRoleMapper
 
     private String groupsDn;
 
+    private String baseDn;
+
     @PostConstruct
     public void initialize()
     {
         this.ldapGroupClass = userConf.getString( UserConfigurationKeys.LDAP_GROUPS_CLASS, this.ldapGroupClass );
 
         this.groupsDn = userConf.getString( UserConfigurationKeys.LDAP_GROUPS_BASEDN, this.groupsDn );
+
+        this.baseDn = userConf.getString( UserConfigurationKeys.LDAP_BASEDN, this.baseDn );
     }
 
     public String getLdapGroup( String role )
@@ -225,6 +229,7 @@ public class DefaultLdapRoleMapper
         throws MappingException
     {
         // TODO caching and a filter with uid
+
         List<String> allGroups = getAllGroups();
         List<String> userGroups = new ArrayList<String>();
         for ( String group : allGroups )
@@ -236,6 +241,81 @@ public class DefaultLdapRoleMapper
             }
         }
         return userGroups;
+        /*
+        List<String> userGroups = new ArrayList<String>();
+
+        LdapConnection ldapConnection = null;
+
+        NamingEnumeration<SearchResult> namingEnumeration = null;
+        try
+        {
+            ldapConnection = ldapConnectionFactory.getConnection();
+
+            DirContext context = ldapConnection.getDirContext();
+
+            SearchControls searchControls = new SearchControls();
+
+            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 );
+
+            List<String> allMembers = new ArrayList<String>();
+
+            while ( namingEnumeration.hasMore() )
+            {
+                SearchResult searchResult = namingEnumeration.next();
+
+                Attribute uniqueMemberAttr = searchResult.getAttributes().get( "uniquemember" );
+
+                if ( uniqueMemberAttr != null )
+                {
+                    NamingEnumeration<String> allMembersEnum = (NamingEnumeration<String>) uniqueMemberAttr.getAll();
+                    while ( allMembersEnum.hasMore() )
+                    {
+                        String userName = allMembersEnum.next();
+                        // uid=blabla we only want bla bla
+                        userName = StringUtils.substringAfter( userName, "=" );
+                        userName = StringUtils.substringBefore( userName, "," );
+                        //log.debug( "found group for username {}: '{}", group, userName );
+
+                        allMembers.add( userName );
+                    }
+                    close( allMembersEnum );
+                }
+
+
+            }
+
+            return userGroups;
+        }
+        catch ( LdapException e )
+        {
+            throw new MappingException( e.getMessage(), e );
+        }
+        catch ( NamingException e )
+        {
+            throw new MappingException( e.getMessage(), e );
+        }
+
+        finally
+        {
+            if ( ldapConnection != null )
+            {
+                ldapConnection.close();
+            }
+            close( namingEnumeration );
+        }
+        */
     }
 
     private void close( NamingEnumeration namingEnumeration )
@@ -303,4 +383,14 @@ public class DefaultLdapRoleMapper
     {
         this.ldapConnectionFactory = ldapConnectionFactory;
     }
+
+    public String getBaseDn()
+    {
+        return baseDn;
+    }
+
+    public void setBaseDn( String baseDn )
+    {
+        this.baseDn = baseDn;
+    }
 }

Modified: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/resources/META-INF/spring-context.xml?rev=1428586&r1=1428585&r2=1428586&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/resources/META-INF/spring-context.xml (original)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/resources/META-INF/spring-context.xml Thu Jan  3 20:50:23 2013
@@ -31,85 +31,6 @@
   <context:component-scan 
     base-package="org.apache.archiva.redback.rbac.ldap"/>
 
-  <bean name="cache#operations" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="operations"/>
-    <property name="timeToIdleSeconds" value="1800"/>
-    <property name="timeToLiveSeconds" value="14400"/>
-  </bean>
 
-  <bean name="cache#permissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="permissions"/>
-    <property name="timeToIdleSeconds" value="1800"/>
-    <property name="timeToLiveSeconds" value="14400"/>
-  </bean>
-
-  <bean name="cache#resources" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="resources"/>
-    <property name="timeToIdleSeconds" value="1800"/>
-    <property name="timeToLiveSeconds" value="14400"/>
-  </bean>
-
-  <bean name="cache#roles" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="roles"/>
-    <property name="timeToIdleSeconds" value="1800"/>
-    <property name="timeToLiveSeconds" value="14400"/>
-  </bean>
-
-  <bean name="cache#effectiveRoleSet" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="effectiveRoleSet"/>
-    <property name="timeToIdleSeconds" value="1800"/>
-    <property name="timeToLiveSeconds" value="14400"/>
-  </bean>
-
-  <!-- ================================================================
-         Caches with Short Term entries
-       ================================================================ -->
-
-  <bean name="cache#userAssignments" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="userAssignments"/>
-    <property name="timeToIdleSeconds" value="300"/>
-    <property name="timeToLiveSeconds" value="600"/>
-  </bean>
-
-  <bean name="cache#userPermissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
-      init-method="initialize">
-    <property name="diskPersistent" value="false"/>
-    <property name="eternal" value="false"/>
-    <property name="maxElementsInMemory" value="1000"/>
-    <property name="memoryEvictionPolicy" value="LRU"/>
-    <property name="name" value="userPermissions"/>
-    <property name="timeToIdleSeconds" value="300"/>
-    <property name="timeToLiveSeconds" value="600"/>
-  </bean>
 
 </beans>
\ No newline at end of file

Modified: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java?rev=1428586&r1=1428585&r2=1428586&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java (original)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java Thu Jan  3 20:50:23 2013
@@ -37,6 +37,7 @@ import org.springframework.test.context.
 
 import javax.inject.Inject;
 import javax.inject.Named;
+import javax.naming.NameClassPair;
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
 import javax.naming.directory.Attribute;
@@ -110,15 +111,27 @@ public class TestLdapRoleMapper
 
         passwordEncoder = new SHA1PasswordEncoder();
 
-        groupSuffix = "dc=archiva,dc=apache,dc=org";
+        groupSuffix = apacheDs.addSimplePartition( "test", new String[]{ "archiva", "apache", "org" } ).getSuffix();
+
         log.info( "groupSuffix: {}", groupSuffix );
 
-        suffix = apacheDs.addSimplePartition( "test", new String[]{ "archiva", "apache", "org" } ).getSuffix();
+        suffix = "ou=People,dc=archiva,dc=apache,dc=org";
 
         log.info( "DN Suffix: {}", suffix );
 
         apacheDs.startServer();
 
+        BasicAttribute objectClass = new BasicAttribute( "objectClass" );
+        objectClass.add( "top" );
+        objectClass.add( "organizationalUnit" );
+
+        Attributes attributes = new BasicAttributes( true );
+        attributes.put( objectClass );
+        attributes.put( "organizationalUnitName", "foo" );
+        //attributes.put( "ou", "People" );
+
+        apacheDs.getAdminContext().createSubcontext( suffix, attributes );
+
         clearManyUsers();
 
         makeUsers();
@@ -145,6 +158,8 @@ public class TestLdapRoleMapper
             context.unbind( createGroupDn( group.getKey() ) );
         }
 
+        context.unbind( suffix );
+
         apacheDs.stopServer();
 
         super.tearDown();

Modified: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml?rev=1428586&r1=1428585&r2=1428586&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml (original)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/resources/spring-context.xml Thu Jan  3 20:50:23 2013
@@ -54,8 +54,96 @@
   <bean name="ldapRoleMapper#test" class="org.apache.archiva.redback.rbac.ldap.DefaultLdapRoleMapper">
     <property name="groupsDn" value="dc=archiva,dc=apache,dc=org"/>
     <property name="ldapGroupClass" value="groupOfUniqueNames"/>
+    <property name="baseDn" value="ou=People,dc=archiva,dc=apache,dc=org"/>
     <property name="ldapConnectionFactory" ref="ldapConnectionFactory#configurable"/>
     <property name="userConf" ref="userConfiguration#default"/>
   </bean>
 
+
+
+
+
+
+
+  <bean name="cache#operations" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="operations"/>
+    <property name="timeToIdleSeconds" value="1800"/>
+    <property name="timeToLiveSeconds" value="14400"/>
+  </bean>
+
+  <bean name="cache#permissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="permissions"/>
+    <property name="timeToIdleSeconds" value="1800"/>
+    <property name="timeToLiveSeconds" value="14400"/>
+  </bean>
+
+  <bean name="cache#resources" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="resources"/>
+    <property name="timeToIdleSeconds" value="1800"/>
+    <property name="timeToLiveSeconds" value="14400"/>
+  </bean>
+
+  <bean name="cache#roles" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="roles"/>
+    <property name="timeToIdleSeconds" value="1800"/>
+    <property name="timeToLiveSeconds" value="14400"/>
+  </bean>
+
+  <bean name="cache#effectiveRoleSet" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="effectiveRoleSet"/>
+    <property name="timeToIdleSeconds" value="1800"/>
+    <property name="timeToLiveSeconds" value="14400"/>
+  </bean>
+
+  <!-- ================================================================
+         Caches with Short Term entries
+       ================================================================ -->
+
+  <bean name="cache#userAssignments" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="userAssignments"/>
+    <property name="timeToIdleSeconds" value="300"/>
+    <property name="timeToLiveSeconds" value="600"/>
+  </bean>
+
+  <bean name="cache#userPermissions" class="org.apache.archiva.redback.components.cache.ehcache.EhcacheCache"
+        init-method="initialize">
+    <property name="diskPersistent" value="false"/>
+    <property name="eternal" value="false"/>
+    <property name="maxElementsInMemory" value="1000"/>
+    <property name="memoryEvictionPolicy" value="LRU"/>
+    <property name="name" value="userPermissions"/>
+    <property name="timeToIdleSeconds" value="300"/>
+    <property name="timeToLiveSeconds" value="600"/>
+  </bean>
+
 </beans>
\ No newline at end of file