/**
- * LdapUserManagerTest
+ * LdapUserManagerTest
*
* @author <a href="mailto:jesse@codehaus.org">Jesse McConnell</a>
- *
- */
+ */
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
public class LdapUserManagerTest
extends TestCase
{
-
+
protected Logger log = LoggerFactory.getLogger( getClass() );
@Inject
private UserManager userManager;
@Inject
- @Named( value = "apacheDS#test" )
+ @Named(value = "apacheDS#test")
private ApacheDs apacheDs;
private String suffix;
passwordEncoder = new SHA1PasswordEncoder();
- suffix = apacheDs.addSimplePartition( "test", new String[] { "redback", "plexus", "codehaus", "org" } )
- .getSuffix();
+ suffix =
+ apacheDs.addSimplePartition( "test", new String[]{ "redback", "plexus", "codehaus", "org" } ).getSuffix();
log.info( "DN Suffix: " + suffix );
apacheDs.startServer();
-
+
clearManyUsers();
makeUsers();
{
assertNotNull( connectionFactory );
- LdapConnection connection = null;
+ LdapConnection connection = null;
try
{
- connection = connectionFactory.getConnection();
+ connection = connectionFactory.getConnection();
- assertNotNull( connection );
+ assertNotNull( connection );
- DirContext context = connection.getDirContext();
+ DirContext context = connection.getDirContext();
- assertNotNull( context );
- } finally {
+ assertNotNull( context );
+ }
+ finally
+ {
connection.close();
}
}
public void testDirectUsersExistence()
throws Exception
{
- LdapConnection connection = null;
+ LdapConnection connection = null;
try
{
- connection = connectionFactory.getConnection();
+ connection = connectionFactory.getConnection();
- DirContext context = connection.getDirContext();
+ DirContext context = connection.getDirContext();
- assertExist( context, createDn( "jesse" ), "cn", "jesse" );
- assertExist( context, createDn( "joakim" ), "cn", "joakim" );
- } finally {
+ assertExist( context, createDn( "jesse" ), "cn", "jesse" );
+ assertExist( context, createDn( "joakim" ), "cn", "joakim" );
+ }
+ finally
+ {
connection.close();
}
-
+
}
@Test
assertEquals( "jesse", jesse.getUsername() );
assertEquals( "jesse@apache.org", jesse.getEmail() );
assertEquals( "foo", jesse.getFullName() );
- log.info( "=====>{}",jesse.getEncodedPassword());
- log.info( "=====>{}",passwordEncoder.encodePassword( "foo" ));
+ log.info( "=====>{}", jesse.getEncodedPassword() );
+ log.info( "=====>{}", passwordEncoder.encodePassword( "foo" ) );
assertTrue( passwordEncoder.isPasswordValid( jesse.getEncodedPassword(), "foo" ) );
}
throws Exception
{
makeManyUsers();
-
+
assertNotNull( userManager );
assertTrue( userManager.userExists( "user10" ) );
assertNotNull( user10 );
}
-
+
private void makeManyUsers()
throws Exception
{
InitialDirContext context = apacheDs.getAdminContext();
-
- for ( int i = 0 ; i < 10000 ; i++ )
- {
- String cn = "user"+i;
+
+ for ( int i = 0; i < 10000; i++ )
+ {
+ String cn = "user" + i;
bindUserObject( context, cn, createDn( cn ) );
}
-
+
}
-
+
private void clearManyUsers()
throws Exception
{
InitialDirContext context = apacheDs.getAdminContext();
-
- for ( int i = 0 ; i < 10000 ; i++ )
- {
- String cn = "user"+i;
+
+ for ( int i = 0; i < 10000; i++ )
+ {
+ String cn = "user" + i;
try
{
context.unbind( createDn( cn ) );
// OK lets try with next one
}
}
-
+
}
-
+
private void bindUserObject( DirContext context, String cn, String dn )
throws Exception
{
attributes.put( objectClass );
attributes.put( "cn", cn );
attributes.put( "sn", "foo" );
- attributes.put( "mail", cn+"@apache.org" );
+ attributes.put( "mail", cn + "@apache.org" );
attributes.put( "userPassword", passwordEncoder.encodePassword( "foo" ) );
attributes.put( "givenName", "foo" );
context.createSubcontext( dn, attributes );
ctls.setDerefLinkFlag( true );
ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
- ctls.setReturningAttributes( new String[] { "*" } );
+ ctls.setReturningAttributes( new String[]{ "*" } );
BasicAttributes matchingAttributes = new BasicAttributes();
matchingAttributes.put( attribute, value );