formatting
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1428291 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0fd70854be
commit
9b53cd4e29
@ -54,18 +54,17 @@
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* LdapUserManagerTest
|
* LdapUserManagerTest
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jesse@codehaus.org">Jesse McConnell</a>
|
* @author <a href="mailto:jesse@codehaus.org">Jesse McConnell</a>
|
||||||
*
|
*/
|
||||||
*/
|
|
||||||
|
|
||||||
@RunWith( SpringJUnit4ClassRunner.class )
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" } )
|
@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
|
||||||
public class LdapUserManagerTest
|
public class LdapUserManagerTest
|
||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected Logger log = LoggerFactory.getLogger( getClass() );
|
protected Logger log = LoggerFactory.getLogger( getClass() );
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -73,7 +72,7 @@ public class LdapUserManagerTest
|
|||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@Named( value = "apacheDS#test" )
|
@Named(value = "apacheDS#test")
|
||||||
private ApacheDs apacheDs;
|
private ApacheDs apacheDs;
|
||||||
|
|
||||||
private String suffix;
|
private String suffix;
|
||||||
@ -101,13 +100,13 @@ public void setUp()
|
|||||||
|
|
||||||
passwordEncoder = new SHA1PasswordEncoder();
|
passwordEncoder = new SHA1PasswordEncoder();
|
||||||
|
|
||||||
suffix = apacheDs.addSimplePartition( "test", new String[] { "redback", "plexus", "codehaus", "org" } )
|
suffix =
|
||||||
.getSuffix();
|
apacheDs.addSimplePartition( "test", new String[]{ "redback", "plexus", "codehaus", "org" } ).getSuffix();
|
||||||
|
|
||||||
log.info( "DN Suffix: " + suffix );
|
log.info( "DN Suffix: " + suffix );
|
||||||
|
|
||||||
apacheDs.startServer();
|
apacheDs.startServer();
|
||||||
|
|
||||||
clearManyUsers();
|
clearManyUsers();
|
||||||
|
|
||||||
makeUsers();
|
makeUsers();
|
||||||
@ -153,17 +152,19 @@ public void testConnection()
|
|||||||
{
|
{
|
||||||
assertNotNull( connectionFactory );
|
assertNotNull( connectionFactory );
|
||||||
|
|
||||||
LdapConnection connection = null;
|
LdapConnection connection = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection = connectionFactory.getConnection();
|
connection = connectionFactory.getConnection();
|
||||||
|
|
||||||
assertNotNull( connection );
|
assertNotNull( connection );
|
||||||
|
|
||||||
DirContext context = connection.getDirContext();
|
DirContext context = connection.getDirContext();
|
||||||
|
|
||||||
assertNotNull( context );
|
assertNotNull( context );
|
||||||
} finally {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,19 +173,21 @@ public void testConnection()
|
|||||||
public void testDirectUsersExistence()
|
public void testDirectUsersExistence()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
LdapConnection connection = null;
|
LdapConnection connection = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
connection = connectionFactory.getConnection();
|
connection = connectionFactory.getConnection();
|
||||||
|
|
||||||
DirContext context = connection.getDirContext();
|
DirContext context = connection.getDirContext();
|
||||||
|
|
||||||
assertExist( context, createDn( "jesse" ), "cn", "jesse" );
|
assertExist( context, createDn( "jesse" ), "cn", "jesse" );
|
||||||
assertExist( context, createDn( "joakim" ), "cn", "joakim" );
|
assertExist( context, createDn( "joakim" ), "cn", "joakim" );
|
||||||
} finally {
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -212,8 +215,8 @@ public void testUserManager()
|
|||||||
assertEquals( "jesse", jesse.getUsername() );
|
assertEquals( "jesse", jesse.getUsername() );
|
||||||
assertEquals( "jesse@apache.org", jesse.getEmail() );
|
assertEquals( "jesse@apache.org", jesse.getEmail() );
|
||||||
assertEquals( "foo", jesse.getFullName() );
|
assertEquals( "foo", jesse.getFullName() );
|
||||||
log.info( "=====>{}",jesse.getEncodedPassword());
|
log.info( "=====>{}", jesse.getEncodedPassword() );
|
||||||
log.info( "=====>{}",passwordEncoder.encodePassword( "foo" ));
|
log.info( "=====>{}", passwordEncoder.encodePassword( "foo" ) );
|
||||||
assertTrue( passwordEncoder.isPasswordValid( jesse.getEncodedPassword(), "foo" ) );
|
assertTrue( passwordEncoder.isPasswordValid( jesse.getEncodedPassword(), "foo" ) );
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -238,7 +241,7 @@ public void testWithManyUsers()
|
|||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
makeManyUsers();
|
makeManyUsers();
|
||||||
|
|
||||||
assertNotNull( userManager );
|
assertNotNull( userManager );
|
||||||
|
|
||||||
assertTrue( userManager.userExists( "user10" ) );
|
assertTrue( userManager.userExists( "user10" ) );
|
||||||
@ -253,28 +256,28 @@ public void testWithManyUsers()
|
|||||||
|
|
||||||
assertNotNull( user10 );
|
assertNotNull( user10 );
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeManyUsers()
|
private void makeManyUsers()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
InitialDirContext context = apacheDs.getAdminContext();
|
InitialDirContext context = apacheDs.getAdminContext();
|
||||||
|
|
||||||
for ( int i = 0 ; i < 10000 ; i++ )
|
for ( int i = 0; i < 10000; i++ )
|
||||||
{
|
{
|
||||||
String cn = "user"+i;
|
String cn = "user" + i;
|
||||||
bindUserObject( context, cn, createDn( cn ) );
|
bindUserObject( context, cn, createDn( cn ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearManyUsers()
|
private void clearManyUsers()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
InitialDirContext context = apacheDs.getAdminContext();
|
InitialDirContext context = apacheDs.getAdminContext();
|
||||||
|
|
||||||
for ( int i = 0 ; i < 10000 ; i++ )
|
for ( int i = 0; i < 10000; i++ )
|
||||||
{
|
{
|
||||||
String cn = "user"+i;
|
String cn = "user" + i;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
context.unbind( createDn( cn ) );
|
context.unbind( createDn( cn ) );
|
||||||
@ -284,9 +287,9 @@ private void clearManyUsers()
|
|||||||
// OK lets try with next one
|
// OK lets try with next one
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindUserObject( DirContext context, String cn, String dn )
|
private void bindUserObject( DirContext context, String cn, String dn )
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
@ -299,7 +302,7 @@ private void bindUserObject( DirContext context, String cn, String dn )
|
|||||||
attributes.put( objectClass );
|
attributes.put( objectClass );
|
||||||
attributes.put( "cn", cn );
|
attributes.put( "cn", cn );
|
||||||
attributes.put( "sn", "foo" );
|
attributes.put( "sn", "foo" );
|
||||||
attributes.put( "mail", cn+"@apache.org" );
|
attributes.put( "mail", cn + "@apache.org" );
|
||||||
attributes.put( "userPassword", passwordEncoder.encodePassword( "foo" ) );
|
attributes.put( "userPassword", passwordEncoder.encodePassword( "foo" ) );
|
||||||
attributes.put( "givenName", "foo" );
|
attributes.put( "givenName", "foo" );
|
||||||
context.createSubcontext( dn, attributes );
|
context.createSubcontext( dn, attributes );
|
||||||
@ -317,7 +320,7 @@ private void assertExist( DirContext context, String dn, String attribute, Strin
|
|||||||
|
|
||||||
ctls.setDerefLinkFlag( true );
|
ctls.setDerefLinkFlag( true );
|
||||||
ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
|
ctls.setSearchScope( SearchControls.ONELEVEL_SCOPE );
|
||||||
ctls.setReturningAttributes( new String[] { "*" } );
|
ctls.setReturningAttributes( new String[]{ "*" } );
|
||||||
|
|
||||||
BasicAttributes matchingAttributes = new BasicAttributes();
|
BasicAttributes matchingAttributes = new BasicAttributes();
|
||||||
matchingAttributes.put( attribute, value );
|
matchingAttributes.put( attribute, value );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user