throws Exception
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
UserManager um = getUserManager();
// create and add a few users
User u1 = um.createUser( "admin", "Administrator", "admin@somedomain.com" );
u1.setPassword( "adminpass" );
um.addUser( u1 );
u1 = um.createUser( "administrator", "Administrator User", "administrator@somedomain.com" );
u1.setPassword( "password" );
um.addUser( u1 );
u1 = um.createUser( "root", "Root User", "root@somedomain.com" );
u1.setPassword( "rootpass" );
um.addUser( u1 );
assertEquals( 3, um.getUsers().size() );
// find an existing user
User user = um.findUser( "root" );
assertNotNull( user );
assertEquals( "root@somedomain.com", user.getEmail() );
assertEquals( "root", user.getPrincipal() );
assertEquals( "Root User", user.getFullName() );
// test if the plain string password is encoded and NULL'ified
assertNull( user.getPassword() );
// test if encoded password was as expected
assertTrue( securityPolicy.getPasswordEncoder().isPasswordValid( user.getEncodedPassword(), "rootpass" ) );
// attempt finding a non-existent user
try
{
um.findUser( "non-existent" );
fail( "Expected UserNotFoundException!" );
}
catch ( UserNotFoundException e )
{
// do nothing, expected!