import javax.naming.directory.InitialDirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* @author Olivier Lamy
@Named( value = "ldapRoleMapper#test" )
LdapRoleMapper ldapRoleMapper;
+ private Map<String, List<String>> usersPerGroup;
+
+ private List<String> users;
+
@Before
public void setUp()
throws Exception
{
super.setUp();
+ usersPerGroup = new HashMap<String, List<String>>( 3 );
+
+ usersPerGroup.put( "internal-repo-manager", Arrays.asList( "admin", "user.9" ) );
+ usersPerGroup.put( "internal-repo-observer", Arrays.asList( "admin", "user.7", "user.8" ) );
+ usersPerGroup.put( "archiva-admin", Arrays.asList( "admin", "user.7" ) );
+
+ users = new ArrayList<String>( 4 );
+ users.add( "admin" );
+ users.add( "user.7" );
+ users.add( "user.8" );
+ users.add( "user.9" );
+
passwordEncoder = new SHA1PasswordEncoder();
groupSuffix = "dc=archiva,dc=apache,dc=org";
InitialDirContext context = apacheDs.getAdminContext();
- context.unbind( createDn( "admin" ) );
-
- context.unbind( createDn( "user.7" ) );
-
- context.unbind( createGroupDn( "internal-repo-manager" ) );
+ for ( String uid : users )
+ {
+ context.unbind( createDn( uid ) );
+ }
- context.unbind( createGroupDn( "archiva-admin" ) );
+ for ( Map.Entry<String, List<String>> group : usersPerGroup.entrySet() )
+ {
+ context.unbind( createGroupDn( group.getKey() ) );
+ }
apacheDs.stopServer();
{
InitialDirContext context = apacheDs.getAdminContext();
- createGroup( context, "internal-repo-manager", createGroupDn( "internal-repo-manager" ) );
+ for ( Map.Entry<String, List<String>> group : usersPerGroup.entrySet() )
+ {
+ createGroup( context, group.getKey(), createGroupDn( group.getKey() ), group.getValue() );
+ }
- createGroup( context, "archiva-admin", createGroupDn( "archiva-admin" ) );
}
- private void createGroup( DirContext context, String groupName, String dn )
+ private void createGroup( DirContext context, String groupName, String dn, List<String> users )
throws Exception
{
objectClass.add( "groupOfUniqueNames" );
attributes.put( objectClass );
attributes.put( "cn", groupName );
- BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
- basicAttribute.add( "uid=admin,dc=archiva,dc=apache,dc=org" );
- basicAttribute.add( "uid=user.7,dc=archiva,dc=apache,dc=org" );
- attributes.put( basicAttribute );
- //attributes.put( "uniquemember", "uid=admin,dc=archiva,dc=apache,dc=org" );
- //attributes.put( "uniquemember", "uid=user.7,dc=archiva,dc=apache,dc=org" );
+ BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
+ for ( String user : users )
+ {
+ basicAttribute.add( "uid=" + user + ",dc=archiva,dc=apache,dc=org" );
+ }
+ attributes.put( basicAttribute );
context.createSubcontext( dn, attributes );
}
private void makeUsers()
throws Exception
{
- InitialDirContext context = apacheDs.getAdminContext();
- String cn = "admin";
- bindUserObject( context, cn, createDn( cn ) );
- assertExist( context, createDn( cn ), "cn", cn );
+ for ( String uid : users )
+ {
+ makeUser( uid );
+ }
- cn = "user.7";
- bindUserObject( context, cn, createDn( cn ) );
- assertExist( context, createDn( cn ), "cn", cn );
+ }
+ private void makeUser( String uid )
+ throws Exception
+ {
+ InitialDirContext context = apacheDs.getAdminContext();
+
+ bindUserObject( context, uid, createDn( uid ) );
+ assertExist( context, createDn( uid ), "cn", uid );
}
private void clearManyUsers()
log.info( "users for archiva-admin: {}", users );
- Assertions.assertThat( users ).isNotNull().isNotEmpty().contains( "admin", "user.7" );
+ Assertions.assertThat( users ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "admin", "user.7" );
+
+ users = ldapRoleMapper.getGroupsMember( "internal-repo-observer" );
+
+ Assertions.assertThat( users ).isNotNull().isNotEmpty().hasSize( 3 ).contains( "admin", "user.7", "user.8" );
}
@Test
log.info( "roles for admin: {}", roles );
- Assertions.assertThat( roles ).isNotNull().isNotEmpty().contains( "archiva-admin", "internal-repo-manager" );
+ Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 3 ).contains( "archiva-admin",
+ "internal-repo-manager",
+ "internal-repo-observer" );
+
+ roles = ldapRoleMapper.getGroups( "user.8" );
+
+ Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "internal-repo-observer" );
+
+ roles = ldapRoleMapper.getGroups( "user.7" );
+
+ Assertions.assertThat( roles ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "archiva-admin",
+ "internal-repo-observer" );
}
}