]> source.dussan.org Git - archiva.git/commitdiff
add method to get directly roles for a user
authorOlivier Lamy <olamy@apache.org>
Tue, 15 Jan 2013 13:19:24 +0000 (13:19 +0000)
committerOlivier Lamy <olamy@apache.org>
Tue, 15 Jan 2013 13:19:24 +0000 (13:19 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1433392 13f79535-47bb-0310-9956-ffa450edef68

redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
redback-common/redback-common-ldap/src/test/java/org/apache/archiva/redback/common/ldap/role/TestLdapRoleMapper.java
redback-common/redback-common-ldap/src/test/resources/spring-context-role-mapper.xml
redback-common/redback-common-ldap/src/test/security.properties [new file with mode: 0644]
redback-rbac/redback-rbac-providers/pom.xml

index f1d7c03d628475f27fe65c86fa73c918af69d431..fc902c626783b1f235572953f94f6cd70b2a8678 100644 (file)
@@ -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>();
index 3ba48c07bc8466abb0730baf8b308ddbf018809b..43bb08d02a57d4b5dffc968c700bd2fbc62aee91 100644 (file)
@@ -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;
+
 }
index c519784a8d94cfcfdb9e24ae748f11fe393c6304..60d5c5e1ac38796b5dce8654762a3b34c9f997fc 100644 (file)
@@ -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" );
     }
+
 }
index c30308064b48ad7ecf1927fc03df826e9c1bc17a..ad2dc1b9f1c266b16e5875c60906caab2cbdb863 100755 (executable)
 
   <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"/>
diff --git a/redback-common/redback-common-ldap/src/test/security.properties b/redback-common/redback-common-ldap/src/test/security.properties
new file mode 100644 (file)
index 0000000..1df8892
--- /dev/null
@@ -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
index 897b535e9d9efbc892bb6629064d7ce46e7cedba..4717d9f1ebd36d7199a5543582161cd7211e4e46 100644 (file)
@@ -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>