add method to get directly roles for a user
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1433392 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b494ed5904
commit
850575cd71
|
@ -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>();
|
||||
|
|
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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.getGroups( "user.8" );
|
||||
roles = ldapRoleMapper.getRoles( "user.7" );
|
||||
|
||||
Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "internal-repo-observer" );
|
||||
log.info( "roles for user.7: {}", roles );
|
||||
|
||||
roles = ldapRoleMapper.getGroups( "user.7" );
|
||||
Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "Archiva System Administrator",
|
||||
"Internal Repo Observer" );
|
||||
|
||||
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" );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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"/>
|
||||
|
|
|
@ -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
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue