remove this ugly Object getPrincipal

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1412684 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-11-22 21:55:21 +00:00
parent 0981c39071
commit 318e1f0ea6
20 changed files with 103 additions and 122 deletions

View File

@ -98,7 +98,7 @@ public class LdapBindAuthenticator
+ ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + "(" + mapper.getUserIdAttribute() + "=" + ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + "(" + mapper.getUserIdAttribute() + "="
+ source.getPrincipal() + "))"; + source.getPrincipal() + "))";
log.info( "Searching for users with filter: '{}'" + " from base dn: {}", filter, mapper.getUserBaseDn() ); log.info( "Searching for users with filter: '{}' from base dn: {}", filter, mapper.getUserBaseDn() );
LdapConnection ldapConnection = getLdapConnection(); LdapConnection ldapConnection = getLdapConnection();
LdapConnection authLdapConnection = null; LdapConnection authLdapConnection = null;

View File

@ -32,8 +32,6 @@ public class LdapUser
implements User, Serializable implements User, Serializable
{ {
private String key;
private String username; private String username;
private String fullName; private String fullName;
@ -67,10 +65,9 @@ public class LdapUser
public LdapUser( String username ) public LdapUser( String username )
{ {
key = username;
this.username = username; this.username = username;
previousEncodedPasswords = new ArrayList<String>( 0 ); this.previousEncodedPasswords = new ArrayList<String>( 0 );
failedLoginAttempts = 0; this.failedLoginAttempts = 0;
} }
public LdapUser( String username, String fullName, String email ) public LdapUser( String username, String fullName, String email )
@ -136,10 +133,6 @@ public class LdapUser
return previousEncodedPasswords; return previousEncodedPasswords;
} }
public Object getPrincipal()
{
return key;
}
public String getUsername() public String getUsername()
{ {

View File

@ -188,7 +188,7 @@ public class AdminAutoCreateCheck
private void assignAdminRole( User user ) private void assignAdminRole( User user )
throws RoleManagerException throws RoleManagerException
{ {
roleManager.assignRole( "system-administrator", user.getPrincipal().toString() ); roleManager.assignRole( "system-administrator", user.getUsername() );
} }
private String getAdminUid() private String getAdminUid()

View File

@ -78,7 +78,7 @@ public class GuestUserEnvironmentCheck
try try
{ {
roleManager.assignRole( "guest", guest.getPrincipal().toString() ); roleManager.assignRole( "guest", guest.getUsername() );
} }
catch ( RoleManagerException rpe ) catch ( RoleManagerException rpe )
{ {

View File

@ -191,7 +191,7 @@ public abstract class HttpAuthenticator
User user = securitySystem.getUserManager().findUser( principal ); User user = securitySystem.getUserManager().findUser( principal );
httpSession.setAttribute( SecuritySession.USERKEY, user ); httpSession.setAttribute( SecuritySession.USERKEY, user );
return user.getPrincipal().toString(); return user.getUsername();
} }
catch ( UserNotFoundException e ) catch ( UserNotFoundException e )

View File

@ -100,7 +100,7 @@ public class HttpDigestAuthentication
// Lookup password for presented username // Lookup password for presented username
User user = findUser( digestHeader.username ); User user = findUser( digestHeader.username );
authDataSource.setPrincipal( user.getPrincipal().toString() ); authDataSource.setPrincipal( user.getUsername() );
String serverSideHash = generateDigestHash( digestHeader, user.getPassword(), request.getMethod() ); String serverSideHash = generateDigestHash( digestHeader, user.getPassword(), request.getMethod() );

View File

@ -197,7 +197,7 @@ public class DefaultUserService
} }
try try
{ {
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getPrincipal().toString() ); roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
} }
catch ( RoleManagerException rpe ) catch ( RoleManagerException rpe )
{ {
@ -417,7 +417,7 @@ public class DefaultUserService
org.apache.archiva.redback.users.User user = userManager.createGuestUser(); org.apache.archiva.redback.users.User user = userManager.createGuestUser();
user.setPasswordChangeRequired( false ); user.setPasswordChangeRequired( false );
user = userManager.updateUser( user, false ); user = userManager.updateUser( user, false );
roleManager.assignRole( "guest", user.getPrincipal().toString() ); roleManager.assignRole( "guest", user.getUsername() );
return getSimpleUser( user ); return getSimpleUser( user );
} }
catch ( RoleManagerException e ) catch ( RoleManagerException e )
@ -478,7 +478,7 @@ public class DefaultUserService
try try
{ {
roleManager.assignRole( "system-administrator", user.getPrincipal().toString() ); roleManager.assignRole( "system-administrator", user.getUsername() );
} }
catch ( RoleManagerException e ) catch ( RoleManagerException e )
{ {
@ -584,7 +584,7 @@ public class DefaultUserService
try try
{ {
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getPrincipal().toString() ); roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
} }
catch ( RoleManagerException rpe ) catch ( RoleManagerException rpe )
{ {
@ -599,7 +599,7 @@ public class DefaultUserService
try try
{ {
AuthenticationKey authkey = AuthenticationKey authkey =
securitySystem.getKeyManager().createKey( u.getPrincipal().toString(), "New User Email Validation", securitySystem.getKeyManager().createKey( u.getUsername(), "New User Email Validation",
securityPolicy.getUserValidationSettings().getEmailValidationTimeout() ); securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
String baseUrl = userRegistrationRequest.getApplicationUrl(); String baseUrl = userRegistrationRequest.getApplicationUrl();
@ -658,7 +658,7 @@ public class DefaultUserService
user.setPasswordChangeRequired( true ); user.setPasswordChangeRequired( true );
user.setEncodedPassword( "" ); user.setEncodedPassword( "" );
principal = user.getPrincipal().toString(); principal = user.getUsername();
TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource(); TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource();
authsource.setPrincipal( principal ); authsource.setPrincipal( principal );

View File

@ -19,16 +19,16 @@ package org.apache.archiva.redback.rest.services.interceptors;
* under the License. * under the License.
*/ */
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authorization.AuthorizationException;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
import org.apache.archiva.redback.system.SecuritySession;
import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.ext.RequestHandler; import org.apache.cxf.jaxrs.ext.RequestHandler;
import org.apache.cxf.jaxrs.model.ClassResourceInfo; import org.apache.cxf.jaxrs.model.ClassResourceInfo;
import org.apache.cxf.message.Message; import org.apache.cxf.message.Message;
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authorization.AuthorizationException;
import org.apache.archiva.redback.authorization.RedbackAuthorization;
import org.apache.archiva.redback.system.SecuritySession;
import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.integration.filter.authentication.basic.HttpBasicAuthentication;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -42,18 +42,18 @@ import javax.ws.rs.core.Response;
* @author Olivier Lamy * @author Olivier Lamy
* @since 1.3 * @since 1.3
*/ */
@Service( "permissionInterceptor#rest" ) @Service ("permissionInterceptor#rest")
public class PermissionsInterceptor public class PermissionsInterceptor
extends AbstractInterceptor extends AbstractInterceptor
implements RequestHandler implements RequestHandler
{ {
@Inject @Inject
@Named( value = "securitySystem" ) @Named (value = "securitySystem")
private SecuritySystem securitySystem; private SecuritySystem securitySystem;
@Inject @Inject
@Named( value = "httpAuthenticator#basic" ) @Named (value = "httpAuthenticator#basic")
private HttpBasicAuthentication httpAuthenticator; private HttpBasicAuthentication httpAuthenticator;
private Logger log = LoggerFactory.getLogger( getClass() ); private Logger log = LoggerFactory.getLogger( getClass() );
@ -96,7 +96,7 @@ public class PermissionsInterceptor
} }
else else
{ {
log.debug( "user {} not authorized for permission {}", session.getUser().getPrincipal(), log.debug( "user {} not authorized for permission {}", session.getUser().getUsername(),
permission ); permission );
} }
} }

View File

@ -44,16 +44,16 @@ import javax.annotation.Resource;
* *
* @author: Jesse McConnell <jesse@codehaus.org> * @author: Jesse McConnell <jesse@codehaus.org>
*/ */
@Service( "authenticator#keystore" ) @Service ("authenticator#keystore")
public class KeyStoreAuthenticator public class KeyStoreAuthenticator
implements Authenticator implements Authenticator
{ {
private Logger log = LoggerFactory.getLogger( getClass() ); private Logger log = LoggerFactory.getLogger( getClass() );
@Resource( name = "keyManager#cached" ) @Resource (name = "keyManager#cached")
private KeyManager keystore; private KeyManager keystore;
@Resource( name = "userManager#configurable" ) @Resource (name = "userManager#configurable")
private UserManager userManager; private UserManager userManager;
public String getId() public String getId()
@ -104,7 +104,7 @@ public class KeyStoreAuthenticator
} }
catch ( UserNotFoundException e ) catch ( UserNotFoundException e )
{ {
log.warn( "Login for user " + source.getPrincipal() + " failed. user not found." ); log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
return new AuthenticationResult( false, null, e ); return new AuthenticationResult( false, null, e );
} }
} }

View File

@ -116,7 +116,7 @@ public class RbacAuthorizer
{ {
// Set permissions = manager.getAssignedPermissions( principal.toString(), operation ); // Set permissions = manager.getAssignedPermissions( principal.toString(), operation );
Map<String, List<Permission>> permissionMap = Map<String, List<Permission>> permissionMap =
manager.getAssignedPermissionMap( guest.getPrincipal().toString() ); manager.getAssignedPermissionMap( guest.getUsername() );
if ( permissionMap.keySet().contains( operation.toString() ) ) if ( permissionMap.keySet().contains( operation.toString() ) )
{ {
@ -124,7 +124,7 @@ public class RbacAuthorizer
{ {
log.debug( "checking permission {}", permission.getName() ); log.debug( "checking permission {}", permission.getName() );
if ( evaluator.evaluate( permission, operation, resource, guest.getPrincipal() ) ) if ( evaluator.evaluate( permission, operation, resource, guest.getUsername() ) )
{ {
return new AuthorizationResult( true, permission, null ); return new AuthorizationResult( true, permission, null );
} }

View File

@ -161,7 +161,7 @@ public class DefaultSecuritySystem
User user = session.getUser(); User user = session.getUser();
if ( user != null ) if ( user != null )
{ {
source = new AuthorizationDataSource( user.getPrincipal(), user, permission, resource ); source = new AuthorizationDataSource( user.getUsername(), user, permission, resource );
} }
} }

View File

@ -129,7 +129,7 @@ public class UserManagerAuthenticator
} }
else else
{ {
log.warn( "Password is Invalid for user " + source.getPrincipal() + "." ); log.warn( "Password is Invalid for user {}.", source.getPrincipal() );
authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_NO_SUCH_USER, authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_NO_SUCH_USER,
"Password is Invalid for user " + source.getPrincipal() + "." ); "Password is Invalid for user " + source.getPrincipal() + "." );
@ -150,7 +150,7 @@ public class UserManagerAuthenticator
log.warn( "Login for user {} failed. user not found.", source.getPrincipal() ); log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
resultException = e; resultException = e;
authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_NO_SUCH_USER, authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_NO_SUCH_USER,
"Login for user \" + source.getPrincipal() + \" failed. user not found." ); "Login for user " + source.getPrincipal() + " failed. user not found." );
} }
return new AuthenticationResult( authenticationSuccess, username, resultException, authnResultExceptionsMap ); return new AuthenticationResult( authenticationSuccess, username, resultException, authnResultExceptionsMap );

View File

@ -33,13 +33,6 @@ public interface User
extends Serializable extends Serializable
{ {
/**
* This is the object used to track the user within the provider.
*
* @return the principal for this user.
*/
Object getPrincipal();
// -------------------------------------------------------------------- // --------------------------------------------------------------------
// Standard User Requirements. // Standard User Requirements.
// -------------------------------------------------------------------- // --------------------------------------------------------------------

View File

@ -68,7 +68,7 @@ public class CachedUserManager
{ {
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
return this.userImpl.addUser( user ); return this.userImpl.addUser( user );
} }
@ -82,7 +82,7 @@ public class CachedUserManager
{ {
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
this.userImpl.addUserUnchecked( user ); this.userImpl.addUserUnchecked( user );
} }
@ -235,7 +235,7 @@ public class CachedUserManager
{ {
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
return this.userImpl.updateUser( user, passwordChangeRequired ); return this.userImpl.updateUser( user, passwordChangeRequired );
} }
@ -269,7 +269,7 @@ public class CachedUserManager
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
} }
@ -282,7 +282,7 @@ public class CachedUserManager
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
} }
@ -295,7 +295,7 @@ public class CachedUserManager
if ( user != null ) if ( user != null )
{ {
usersCache.remove( user.getPrincipal() ); usersCache.remove( user.getUsername() );
} }
} }

View File

@ -147,13 +147,9 @@
public JdoUser() public JdoUser()
{ {
// Intentionally initialize List to avoid JPOX NullPointerException Issues. // Intentionally initialize List to avoid JPOX NullPointerException Issues.
previousEncodedPasswords = new java.util.ArrayList(); previousEncodedPasswords = new java.util.ArrayList<String>();
} }
public Object getPrincipal()
{
return username;
}
]]></code> ]]></code>
</codeSegment> </codeSegment>
</codeSegments> </codeSegments>

View File

@ -102,11 +102,11 @@ public class LdapUserManager
} }
catch ( LdapControllerException e ) catch ( LdapControllerException e )
{ {
log.error( "Error mapping user: " + user.getPrincipal() + " to LDAP attributes.", e ); log.error( "Error mapping user: " + user.getUsername() + " to LDAP attributes.", e );
} }
catch ( MappingException e ) catch ( MappingException e )
{ {
log.error( "Error mapping user: " + user.getPrincipal() + " to LDAP attributes.", e ); log.error( "Error mapping user: " + user.getUsername() + " to LDAP attributes.", e );
} }
finally finally
{ {
@ -422,11 +422,11 @@ public class LdapUserManager
} }
catch ( LdapControllerException e ) catch ( LdapControllerException e )
{ {
log.error( "Failed to update user: " + user.getPrincipal(), e ); log.error( "Failed to update user: " + user.getUsername(), e );
} }
catch ( MappingException e ) catch ( MappingException e )
{ {
log.error( "Failed to update user: " + user.getPrincipal(), e ); log.error( "Failed to update user: " + user.getUsername(), e );
} }
finally finally
{ {

View File

@ -209,11 +209,11 @@ public class LdapUserManagerTest
assertNotNull( jesse ); assertNotNull( jesse );
assertEquals( "jesse", jesse.getPrincipal().toString() ); 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" ) );
} }

View File

@ -134,7 +134,7 @@ public class MemoryUserManager
private void saveUser( User user ) private void saveUser( User user )
{ {
triggerInit(); triggerInit();
users.put( user.getPrincipal(), user ); users.put( user.getUsername(), user );
} }
public User updateUser( User user ) public User updateUser( User user )
@ -209,7 +209,7 @@ public class MemoryUserManager
throw new PermanentUserException( "Cannot delete permanent user." ); throw new PermanentUserException( "Cannot delete permanent user." );
} }
users.remove( user.getPrincipal() ); users.remove( user.getUsername() );
fireUserManagerUserRemoved( user ); fireUserManagerUserRemoved( user );
} }

View File

@ -121,11 +121,6 @@ public class SimpleUser
return previousEncodedPasswords; return previousEncodedPasswords;
} }
public Object getPrincipal()
{
return username;
}
public String getUsername() public String getUsername()
{ {
return username; return username;

View File

@ -21,29 +21,28 @@ package org.apache.archiva.redback.users.provider.test;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.PermanentUserException;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.UserQuery; import org.apache.archiva.redback.users.UserQuery;
import org.apache.archiva.redback.users.PermanentUserException;
import org.apache.archiva.redback.users.UserManager;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.List; import java.util.List;
import org.springframework.test.annotation.DirtiesContext;
/** /**
* AbstractUserManagerTestCase * AbstractUserManagerTestCase
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</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" } )
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD ) @DirtiesContext ( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
public class AbstractUserManagerTestCase public class AbstractUserManagerTestCase
extends TestCase extends TestCase
{ {
@ -56,16 +55,16 @@ public class AbstractUserManagerTestCase
@Inject @Inject
private UserSecurityPolicy securityPolicy; private UserSecurityPolicy securityPolicy;
private UserManagerEventTracker eventTracker; private UserManagerEventTracker eventTracker;
private static final int EVENTTRACKERCOUNT = 2; private static final int EVENTTRACKERCOUNT = 2;
// assertCleanUserManager // assertCleanUserManager
// getEventTracker().userManagerInit( true ); is 1 // getEventTracker().userManagerInit( true ); is 1
// userManager.getUsers() is 2 // userManager.getUsers() is 2
// only on clear context // only on clear context
public UserManager getUserManager() public UserManager getUserManager()
{ {
return userManager; return userManager;
@ -100,7 +99,8 @@ public class AbstractUserManagerTestCase
getEventTracker().userManagerInit( true ); getEventTracker().userManagerInit( true );
assertNotNull( getUserManager() ); assertNotNull( getUserManager() );
assertEquals( "New UserManager should contain no users. " + userManager.getUsers(), 0, userManager.getUsers().size() ); assertEquals( "New UserManager should contain no users. " + userManager.getUsers(), 0,
userManager.getUsers().size() );
} }
@Test @Test
@ -131,7 +131,7 @@ public class AbstractUserManagerTestCase
{ {
// Expected Path. // Expected Path.
} }
try try
{ {
String username = ""; String username = "";
@ -142,7 +142,7 @@ public class AbstractUserManagerTestCase
{ {
// Expected Path. // Expected Path.
} }
try try
{ {
String username = " "; String username = " ";
@ -172,53 +172,55 @@ public class AbstractUserManagerTestCase
assertEquals( 1, userManager.getUsers().size() ); assertEquals( 1, userManager.getUsers().size() );
/* Fetch user from userManager using principal returned earlier */ /* Fetch user from userManager using principal returned earlier */
User actual = userManager.findUser( added.getPrincipal() ); User actual = userManager.findUser( added.getUsername() );
assertEquals( added, actual ); assertEquals( added, actual );
/* Check into the event tracker. */ /* Check into the event tracker. */
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
} }
@Test @Test
public void testAddFindUserLockedStatus() throws UserNotFoundException { public void testAddFindUserLockedStatus()
assertCleanUserManager(); throws UserNotFoundException
securityPolicy.setEnabled(false); {
assertCleanUserManager();
securityPolicy.setEnabled( false );
User smcqueen = getUserManager().createUser("smcqueen", "Steve McQueen", "the cooler king"); User smcqueen = getUserManager().createUser( "smcqueen", "Steve McQueen", "the cooler king" );
smcqueen.setLocked( true );
smcqueen.setLocked( true );
/* /*
* Keep a reference to the object that was added. Since it has the * Keep a reference to the object that was added. Since it has the
* actual principal that was managed by jpox/jdo. * actual principal that was managed by jpox/jdo.
*/ */
User added = userManager.addUser( smcqueen ); User added = userManager.addUser( smcqueen );
assertTrue( added.isLocked() ); assertTrue( added.isLocked() );
assertEquals(1, userManager.getUsers().size()); assertEquals( 1, userManager.getUsers().size() );
/* Fetch user from userManager using principal returned earlier */ /* Fetch user from userManager using principal returned earlier */
User actual = userManager.findUser(added.getPrincipal()); User actual = userManager.findUser( added.getUsername() );
assertEquals(added, actual); assertEquals( added, actual );
assertTrue( actual.isLocked() ); assertTrue( actual.isLocked() );
/* Check into the event tracker. */ /* Check into the event tracker. */
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull(getEventTracker().lastDbFreshness); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue(getEventTracker().lastDbFreshness.booleanValue()); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals(1, getEventTracker().addedUsernames.size()); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals(0, getEventTracker().removedUsernames.size()); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals(0, getEventTracker().updatedUsernames.size()); assertEquals( 0, getEventTracker().updatedUsernames.size() );
} }
@Test @Test
public void testAddFindUserByUsername() public void testAddFindUserByUsername()
@ -240,7 +242,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -264,7 +266,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -292,7 +294,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -312,7 +314,7 @@ public class AbstractUserManagerTestCase
assertEquals( 1, um.getUsers().size() ); assertEquals( 1, um.getUsers().size() );
um.deleteUser( user.getPrincipal() ); um.deleteUser( user.getUsername() );
assertEquals( 0, um.getUsers().size() ); assertEquals( 0, um.getUsers().size() );
// attempt finding a non-existent user // attempt finding a non-existent user
@ -330,7 +332,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 1, getEventTracker().removedUsernames.size() ); assertEquals( 1, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -364,7 +366,7 @@ public class AbstractUserManagerTestCase
User user = um.findUser( "root" ); User user = um.findUser( "root" );
assertNotNull( user ); assertNotNull( user );
assertEquals( "root@somedomain.com", user.getEmail() ); assertEquals( "root@somedomain.com", user.getEmail() );
assertEquals( "root", user.getPrincipal() ); assertEquals( "root", user.getUsername() );
assertEquals( "Root User", user.getFullName() ); assertEquals( "Root User", user.getFullName() );
// test if the plain string password is encoded and NULL'ified // test if the plain string password is encoded and NULL'ified
assertNull( user.getPassword() ); assertNull( user.getPassword() );
@ -386,7 +388,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 3, getEventTracker().addedUsernames.size() ); assertEquals( 3, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -520,7 +522,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); assertEquals( 0, getEventTracker().updatedUsernames.size() );
@ -562,7 +564,7 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 1, getEventTracker().updatedUsernames.size() ); assertEquals( 1, getEventTracker().updatedUsernames.size() );
@ -585,13 +587,14 @@ public class AbstractUserManagerTestCase
try try
{ {
um.deleteUser( user.getPrincipal() ); um.deleteUser( user.getUsername() );
fail("Deleting permanent user shold throw PermanentUserException."); fail( "Deleting permanent user shold throw PermanentUserException." );
} catch( PermanentUserException e ) }
catch ( PermanentUserException e )
{ {
// do nothing, expected route. // do nothing, expected route.
} }
assertEquals( 1, um.getUsers().size() ); assertEquals( 1, um.getUsers().size() );
// attempt to finding user // attempt to finding user
@ -604,10 +607,11 @@ public class AbstractUserManagerTestCase
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit ); assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
assertNotNull( getEventTracker().lastDbFreshness ); assertNotNull( getEventTracker().lastDbFreshness );
assertTrue( getEventTracker().lastDbFreshness.booleanValue() ); assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
assertEquals( 1, getEventTracker().addedUsernames.size() ); assertEquals( 1, getEventTracker().addedUsernames.size() );
assertEquals( 0, getEventTracker().removedUsernames.size() ); assertEquals( 0, getEventTracker().removedUsernames.size() );
assertEquals( 0, getEventTracker().updatedUsernames.size() ); } assertEquals( 0, getEventTracker().updatedUsernames.size() );
}
public UserManagerEventTracker getEventTracker() public UserManagerEventTracker getEventTracker()
{ {