diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java index 097136d5..4df4bc73 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/main/java/org/apache/archiva/redback/rbac/ldap/DefaultLdapRoleMapper.java @@ -230,7 +230,7 @@ public class DefaultLdapRoleMapper { // TODO caching and a filter with uid - List allGroups = getAllGroups(); + /*List allGroups = getAllGroups(); List userGroups = new ArrayList(); for ( String group : allGroups ) { @@ -241,7 +241,8 @@ public class DefaultLdapRoleMapper } } return userGroups; - /* + */ + List userGroups = new ArrayList(); 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 allMembers = new ArrayList(); + namingEnumeration = context.search( getGroupsDn(), filter, searchControls ); while ( namingEnumeration.hasMore() ) { SearchResult searchResult = namingEnumeration.next(); + List allMembers = new ArrayList(); + 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 ) diff --git a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java index 0694a333..bf977ea9 100644 --- a/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java +++ b/redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/TestLdapRoleMapper.java @@ -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> 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 {