archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r1433392 - in /archiva/redback/redback-core/trunk: redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/ redback-common/redback-common-ldap/src/test/ redback-common/redback-common-ldap/src/test/java/o...
Date Tue, 15 Jan 2013 13:19:25 GMT
Author: olamy
Date: Tue Jan 15 13:19:24 2013
New Revision: 1433392

URL: http://svn.apache.org/viewvc?rev=1433392&view=rev
Log:
add method to get directly roles for a user

Added:
    archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
  (with props)
Modified:
    archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
    archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
    archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java
    archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml
    archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/pom.xml

Modified: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java?rev=1433392&r1=1433391&r2=1433392&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
(original)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
Tue Jan 15 13:19:24 2013
@@ -312,7 +312,27 @@ public class DefaultLdapRoleMapper
             }
             close( namingEnumeration );
         }
+    }
+
+    public List<String> getRoles( String username )
+        throws MappingException
+    {
+        List<String> groups = getGroups( username );
+
+        Map<String, String> rolesMapping = getLdapGroupMappings();
 
+        List<String> roles = new ArrayList<String>( groups.size() );
+
+        for ( String group : groups )
+        {
+            String role = rolesMapping.get( group );
+            if ( role != null )
+            {
+                roles.add( role );
+            }
+        }
+
+        return roles;
     }
 
     private void close( NamingEnumeration namingEnumeration )
@@ -350,6 +370,12 @@ public class DefaultLdapRoleMapper
         log.warn( "removeLdapMapping not implemented" );
     }
 
+    public void setLdapGroupMappings( Map<String, String> mappings )
+        throws MappingException
+    {
+        log.warn( "setLdapGroupMappings not implemented" );
+    }
+
     public Map<String, String> getLdapGroupMappings()
     {
         Map<String, String> map = new HashMap<String, String>();

Modified: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java?rev=1433392&r1=1433391&r2=1433392&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
(original)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
Tue Jan 15 13:19:24 2013
@@ -70,6 +70,9 @@ public interface LdapRoleMapper
     List<String> getGroups( String username )
         throws MappingException;
 
+    List<String> getRoles( String username )
+        throws MappingException;
+
     /**
      * add mapping redback role <-> ldap group
      *
@@ -93,4 +96,7 @@ public interface LdapRoleMapper
     Map<String, String> getLdapGroupMappings()
         throws MappingException;
 
+    void setLdapGroupMappings( Map<String, String> mappings )
+        throws MappingException;
+
 }

Modified: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java?rev=1433392&r1=1433391&r2=1433392&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java
(original)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java
Tue Jan 15 13:19:24 2013
@@ -65,7 +65,7 @@ public class TestLdapRoleMapper
     Logger log = LoggerFactory.getLogger( getClass() );
 
     @Inject
-    @Named( value = "apacheDS#test" )
+    @Named(value = "apacheDS#test")
     private ApacheDs apacheDs;
 
     private String suffix;
@@ -294,21 +294,49 @@ public class TestLdapRoleMapper
     public void getGroups()
         throws Exception
     {
-        List<String> roles = ldapRoleMapper.getGroups( "admin" );
+        List<String> groups = ldapRoleMapper.getGroups( "admin" );
+
+        log.info( "groups for admin: {}", groups );
+
+        Assertions.assertThat( groups ).isNotNull().isNotEmpty().hasSize( 3 ).contains( "archiva-admin",
+                                                                                        "internal-repo-manager",
+                                                                                        "internal-repo-observer"
);
+
+        groups = ldapRoleMapper.getGroups( "user.8" );
+
+        Assertions.assertThat( groups ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "internal-repo-observer"
);
+
+        groups = ldapRoleMapper.getGroups( "user.7" );
+
+        Assertions.assertThat( groups ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "archiva-admin",
+                                                                                        "internal-repo-observer"
);
+    }
+
+    @Test
+    public void getRoles()
+        throws Exception
+    {
+        List<String> roles = ldapRoleMapper.getRoles( "admin" );
 
         log.info( "roles for admin: {}", roles );
 
-        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 3 ).contains( "archiva-admin",
-                                                                                       "internal-repo-manager",
-                                                                                       "internal-repo-observer"
);
+        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 3 ).contains( "Archiva
System Administrator",
+                                                                                       "Internal
Repo Manager",
+                                                                                       "Internal
Repo Observer" );
+
+        roles = ldapRoleMapper.getRoles( "user.7" );
 
-        roles = ldapRoleMapper.getGroups( "user.8" );
+        log.info( "roles for user.7: {}", roles );
 
-        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "internal-repo-observer"
);
+        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "Archiva
System Administrator",
+                                                                                       "Internal
Repo Observer" );
 
-        roles = ldapRoleMapper.getGroups( "user.7" );
+        roles = ldapRoleMapper.getRoles( "user.8" );
+
+        log.info( "roles for user.8: {}", roles );
+
+        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "Internal
Repo Observer" );
 
-        Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "archiva-admin",
-                                                                                       "internal-repo-observer"
);
     }
+
 }

Modified: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml?rev=1433392&r1=1433391&r2=1433392&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml
(original)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml
Tue Jan 15 13:19:24 2013
@@ -30,6 +30,21 @@
 
   <alias name="userConfiguration#redback" alias="userConfiguration#default"/>
 
+  <bean name="commons-configuration" class="org.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"
+        init-method="initialize">
+    <property name="properties">
+      <value>
+        <![CDATA[
+        <configuration>
+          <system/>
+          <properties fileName="${basedir}/src/test/security.properties" config-optional="true"
+                      config-at="org.apache.archiva.redback"/>
+        </configuration>
+        ]]>
+      </value>
+    </property>
+  </bean>
+
   <bean name="apacheDS#test" class="org.apache.archiva.redback.components.apacheds.DefaultApacheDs"
         scope="prototype">
     <property name="basedir" value="${basedir}/target/apacheds"/>

Added: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties?rev=1433392&view=auto
==============================================================================
--- archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
(added)
+++ archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
Tue Jan 15 13:19:24 2013
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+ldap.config.groups.role.archiva-admin=Archiva System Administrator
+ldap.config.groups.role.internal-repo-manager=Internal Repo Manager
+ldap.config.groups.role.internal-repo-observer=Internal Repo Observer
\ No newline at end of file

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: archiva/redback/redback-core/trunk/redback-common/redback-common-ldap/src/test/security.properties
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/pom.xml
URL: http://svn.apache.org/viewvc/archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/pom.xml?rev=1433392&r1=1433391&r2=1433392&view=diff
==============================================================================
--- archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/pom.xml (original)
+++ archiva/redback/redback-core/trunk/redback-rbac/redback-rbac-providers/pom.xml Tue Jan
15 13:19:24 2013
@@ -31,5 +31,6 @@
     <module>redback-rbac-jdo</module>
     <module>redback-rbac-memory</module>
     <module>redback-rbac-cached</module>
+    <module>redback-rbac-ldap</module>
   </modules>
 </project>



Mime
View raw message