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:
parent
0981c39071
commit
318e1f0ea6
|
@ -98,7 +98,7 @@ public class LdapBindAuthenticator
|
|||
+ ( mapper.getUserFilter() != null ? mapper.getUserFilter() : "" ) + "(" + mapper.getUserIdAttribute() + "="
|
||||
+ 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 authLdapConnection = null;
|
||||
|
|
|
@ -32,8 +32,6 @@ public class LdapUser
|
|||
implements User, Serializable
|
||||
{
|
||||
|
||||
private String key;
|
||||
|
||||
private String username;
|
||||
|
||||
private String fullName;
|
||||
|
@ -67,10 +65,9 @@ public class LdapUser
|
|||
|
||||
public LdapUser( String username )
|
||||
{
|
||||
key = username;
|
||||
this.username = username;
|
||||
previousEncodedPasswords = new ArrayList<String>( 0 );
|
||||
failedLoginAttempts = 0;
|
||||
this.previousEncodedPasswords = new ArrayList<String>( 0 );
|
||||
this.failedLoginAttempts = 0;
|
||||
}
|
||||
|
||||
public LdapUser( String username, String fullName, String email )
|
||||
|
@ -136,10 +133,6 @@ public class LdapUser
|
|||
return previousEncodedPasswords;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return key;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
|
|
|
@ -188,7 +188,7 @@ public class AdminAutoCreateCheck
|
|||
private void assignAdminRole( User user )
|
||||
throws RoleManagerException
|
||||
{
|
||||
roleManager.assignRole( "system-administrator", user.getPrincipal().toString() );
|
||||
roleManager.assignRole( "system-administrator", user.getUsername() );
|
||||
}
|
||||
|
||||
private String getAdminUid()
|
||||
|
|
|
@ -78,7 +78,7 @@ public class GuestUserEnvironmentCheck
|
|||
|
||||
try
|
||||
{
|
||||
roleManager.assignRole( "guest", guest.getPrincipal().toString() );
|
||||
roleManager.assignRole( "guest", guest.getUsername() );
|
||||
}
|
||||
catch ( RoleManagerException rpe )
|
||||
{
|
||||
|
|
|
@ -191,7 +191,7 @@ public abstract class HttpAuthenticator
|
|||
User user = securitySystem.getUserManager().findUser( principal );
|
||||
httpSession.setAttribute( SecuritySession.USERKEY, user );
|
||||
|
||||
return user.getPrincipal().toString();
|
||||
return user.getUsername();
|
||||
|
||||
}
|
||||
catch ( UserNotFoundException e )
|
||||
|
|
|
@ -100,7 +100,7 @@ public class HttpDigestAuthentication
|
|||
|
||||
// Lookup password for presented username
|
||||
User user = findUser( digestHeader.username );
|
||||
authDataSource.setPrincipal( user.getPrincipal().toString() );
|
||||
authDataSource.setPrincipal( user.getUsername() );
|
||||
|
||||
String serverSideHash = generateDigestHash( digestHeader, user.getPassword(), request.getMethod() );
|
||||
|
||||
|
|
|
@ -197,7 +197,7 @@ public class DefaultUserService
|
|||
}
|
||||
try
|
||||
{
|
||||
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getPrincipal().toString() );
|
||||
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
|
||||
}
|
||||
catch ( RoleManagerException rpe )
|
||||
{
|
||||
|
@ -417,7 +417,7 @@ public class DefaultUserService
|
|||
org.apache.archiva.redback.users.User user = userManager.createGuestUser();
|
||||
user.setPasswordChangeRequired( false );
|
||||
user = userManager.updateUser( user, false );
|
||||
roleManager.assignRole( "guest", user.getPrincipal().toString() );
|
||||
roleManager.assignRole( "guest", user.getUsername() );
|
||||
return getSimpleUser( user );
|
||||
}
|
||||
catch ( RoleManagerException e )
|
||||
|
@ -478,7 +478,7 @@ public class DefaultUserService
|
|||
|
||||
try
|
||||
{
|
||||
roleManager.assignRole( "system-administrator", user.getPrincipal().toString() );
|
||||
roleManager.assignRole( "system-administrator", user.getUsername() );
|
||||
}
|
||||
catch ( RoleManagerException e )
|
||||
{
|
||||
|
@ -584,7 +584,7 @@ public class DefaultUserService
|
|||
|
||||
try
|
||||
{
|
||||
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getPrincipal().toString() );
|
||||
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
|
||||
}
|
||||
catch ( RoleManagerException rpe )
|
||||
{
|
||||
|
@ -599,7 +599,7 @@ public class DefaultUserService
|
|||
try
|
||||
{
|
||||
AuthenticationKey authkey =
|
||||
securitySystem.getKeyManager().createKey( u.getPrincipal().toString(), "New User Email Validation",
|
||||
securitySystem.getKeyManager().createKey( u.getUsername(), "New User Email Validation",
|
||||
securityPolicy.getUserValidationSettings().getEmailValidationTimeout() );
|
||||
|
||||
String baseUrl = userRegistrationRequest.getApplicationUrl();
|
||||
|
@ -658,7 +658,7 @@ public class DefaultUserService
|
|||
user.setPasswordChangeRequired( true );
|
||||
user.setEncodedPassword( "" );
|
||||
|
||||
principal = user.getPrincipal().toString();
|
||||
principal = user.getUsername();
|
||||
|
||||
TokenBasedAuthenticationDataSource authsource = new TokenBasedAuthenticationDataSource();
|
||||
authsource.setPrincipal( principal );
|
||||
|
|
|
@ -19,16 +19,16 @@ package org.apache.archiva.redback.rest.services.interceptors;
|
|||
* 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.cxf.jaxrs.ext.RequestHandler;
|
||||
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
|
||||
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.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
@ -42,18 +42,18 @@ import javax.ws.rs.core.Response;
|
|||
* @author Olivier Lamy
|
||||
* @since 1.3
|
||||
*/
|
||||
@Service( "permissionInterceptor#rest" )
|
||||
@Service ("permissionInterceptor#rest")
|
||||
public class PermissionsInterceptor
|
||||
extends AbstractInterceptor
|
||||
implements RequestHandler
|
||||
{
|
||||
|
||||
@Inject
|
||||
@Named( value = "securitySystem" )
|
||||
@Named (value = "securitySystem")
|
||||
private SecuritySystem securitySystem;
|
||||
|
||||
@Inject
|
||||
@Named( value = "httpAuthenticator#basic" )
|
||||
@Named (value = "httpAuthenticator#basic")
|
||||
private HttpBasicAuthentication httpAuthenticator;
|
||||
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
@ -96,7 +96,7 @@ public class PermissionsInterceptor
|
|||
}
|
||||
else
|
||||
{
|
||||
log.debug( "user {} not authorized for permission {}", session.getUser().getPrincipal(),
|
||||
log.debug( "user {} not authorized for permission {}", session.getUser().getUsername(),
|
||||
permission );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,16 +44,16 @@ import javax.annotation.Resource;
|
|||
*
|
||||
* @author: Jesse McConnell <jesse@codehaus.org>
|
||||
*/
|
||||
@Service( "authenticator#keystore" )
|
||||
@Service ("authenticator#keystore")
|
||||
public class KeyStoreAuthenticator
|
||||
implements Authenticator
|
||||
{
|
||||
private Logger log = LoggerFactory.getLogger( getClass() );
|
||||
|
||||
@Resource( name = "keyManager#cached" )
|
||||
@Resource (name = "keyManager#cached")
|
||||
private KeyManager keystore;
|
||||
|
||||
@Resource( name = "userManager#configurable" )
|
||||
@Resource (name = "userManager#configurable")
|
||||
private UserManager userManager;
|
||||
|
||||
public String getId()
|
||||
|
@ -104,7 +104,7 @@ public class KeyStoreAuthenticator
|
|||
}
|
||||
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 );
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public class RbacAuthorizer
|
|||
{
|
||||
// Set permissions = manager.getAssignedPermissions( principal.toString(), operation );
|
||||
Map<String, List<Permission>> permissionMap =
|
||||
manager.getAssignedPermissionMap( guest.getPrincipal().toString() );
|
||||
manager.getAssignedPermissionMap( guest.getUsername() );
|
||||
|
||||
if ( permissionMap.keySet().contains( operation.toString() ) )
|
||||
{
|
||||
|
@ -124,7 +124,7 @@ public class RbacAuthorizer
|
|||
{
|
||||
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 );
|
||||
}
|
||||
|
|
|
@ -161,7 +161,7 @@ public class DefaultSecuritySystem
|
|||
User user = session.getUser();
|
||||
if ( user != null )
|
||||
{
|
||||
source = new AuthorizationDataSource( user.getPrincipal(), user, permission, resource );
|
||||
source = new AuthorizationDataSource( user.getUsername(), user, permission, resource );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -129,7 +129,7 @@ public class UserManagerAuthenticator
|
|||
}
|
||||
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,
|
||||
"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() );
|
||||
resultException = e;
|
||||
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 );
|
||||
|
|
|
@ -33,13 +33,6 @@ public interface User
|
|||
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.
|
||||
// --------------------------------------------------------------------
|
||||
|
|
|
@ -68,7 +68,7 @@ public class CachedUserManager
|
|||
{
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
return this.userImpl.addUser( user );
|
||||
}
|
||||
|
@ -82,7 +82,7 @@ public class CachedUserManager
|
|||
{
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
this.userImpl.addUserUnchecked( user );
|
||||
}
|
||||
|
@ -235,7 +235,7 @@ public class CachedUserManager
|
|||
{
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
return this.userImpl.updateUser( user, passwordChangeRequired );
|
||||
}
|
||||
|
@ -269,7 +269,7 @@ public class CachedUserManager
|
|||
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +282,7 @@ public class CachedUserManager
|
|||
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -295,7 +295,7 @@ public class CachedUserManager
|
|||
|
||||
if ( user != null )
|
||||
{
|
||||
usersCache.remove( user.getPrincipal() );
|
||||
usersCache.remove( user.getUsername() );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -147,13 +147,9 @@
|
|||
public JdoUser()
|
||||
{
|
||||
// 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>
|
||||
</codeSegment>
|
||||
</codeSegments>
|
||||
|
|
|
@ -102,11 +102,11 @@ public class LdapUserManager
|
|||
}
|
||||
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 )
|
||||
{
|
||||
log.error( "Error mapping user: " + user.getPrincipal() + " to LDAP attributes.", e );
|
||||
log.error( "Error mapping user: " + user.getUsername() + " to LDAP attributes.", e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
@ -422,11 +422,11 @@ public class LdapUserManager
|
|||
}
|
||||
catch ( LdapControllerException e )
|
||||
{
|
||||
log.error( "Failed to update user: " + user.getPrincipal(), e );
|
||||
log.error( "Failed to update user: " + user.getUsername(), e );
|
||||
}
|
||||
catch ( MappingException e )
|
||||
{
|
||||
log.error( "Failed to update user: " + user.getPrincipal(), e );
|
||||
log.error( "Failed to update user: " + user.getUsername(), e );
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
|
|
@ -209,11 +209,11 @@ public class LdapUserManagerTest
|
|||
|
||||
assertNotNull( jesse );
|
||||
|
||||
assertEquals( "jesse", jesse.getPrincipal().toString() );
|
||||
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" ) );
|
||||
|
||||
}
|
||||
|
|
|
@ -134,7 +134,7 @@ public class MemoryUserManager
|
|||
private void saveUser( User user )
|
||||
{
|
||||
triggerInit();
|
||||
users.put( user.getPrincipal(), user );
|
||||
users.put( user.getUsername(), user );
|
||||
}
|
||||
|
||||
public User updateUser( User user )
|
||||
|
@ -209,7 +209,7 @@ public class MemoryUserManager
|
|||
throw new PermanentUserException( "Cannot delete permanent user." );
|
||||
}
|
||||
|
||||
users.remove( user.getPrincipal() );
|
||||
users.remove( user.getUsername() );
|
||||
|
||||
fireUserManagerUserRemoved( user );
|
||||
}
|
||||
|
|
|
@ -121,11 +121,6 @@ public class SimpleUser
|
|||
return previousEncodedPasswords;
|
||||
}
|
||||
|
||||
public Object getPrincipal()
|
||||
{
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getUsername()
|
||||
{
|
||||
return username;
|
||||
|
|
|
@ -21,29 +21,28 @@ package org.apache.archiva.redback.users.provider.test;
|
|||
|
||||
import junit.framework.TestCase;
|
||||
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.UserManager;
|
||||
import org.apache.archiva.redback.users.UserNotFoundException;
|
||||
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.runner.RunWith;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.util.List;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
|
||||
/**
|
||||
* AbstractUserManagerTestCase
|
||||
* AbstractUserManagerTestCase
|
||||
*
|
||||
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
|
||||
*
|
||||
*/
|
||||
@RunWith( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath*:/spring-context.xml"} )
|
||||
@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
|
||||
@RunWith ( SpringJUnit4ClassRunner.class )
|
||||
@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
|
||||
@DirtiesContext ( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
|
||||
public class AbstractUserManagerTestCase
|
||||
extends TestCase
|
||||
{
|
||||
|
@ -56,16 +55,16 @@ public class AbstractUserManagerTestCase
|
|||
|
||||
@Inject
|
||||
private UserSecurityPolicy securityPolicy;
|
||||
|
||||
|
||||
private UserManagerEventTracker eventTracker;
|
||||
|
||||
|
||||
|
||||
private static final int EVENTTRACKERCOUNT = 2;
|
||||
// assertCleanUserManager
|
||||
// getEventTracker().userManagerInit( true ); is 1
|
||||
// userManager.getUsers() is 2
|
||||
// only on clear context
|
||||
|
||||
|
||||
public UserManager getUserManager()
|
||||
{
|
||||
return userManager;
|
||||
|
@ -100,7 +99,8 @@ public class AbstractUserManagerTestCase
|
|||
getEventTracker().userManagerInit( true );
|
||||
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
|
||||
|
@ -131,7 +131,7 @@ public class AbstractUserManagerTestCase
|
|||
{
|
||||
// Expected Path.
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
String username = "";
|
||||
|
@ -142,7 +142,7 @@ public class AbstractUserManagerTestCase
|
|||
{
|
||||
// Expected Path.
|
||||
}
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
String username = " ";
|
||||
|
@ -172,53 +172,55 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( 1, userManager.getUsers().size() );
|
||||
|
||||
/* Fetch user from userManager using principal returned earlier */
|
||||
User actual = userManager.findUser( added.getPrincipal() );
|
||||
User actual = userManager.findUser( added.getUsername() );
|
||||
assertEquals( added, actual );
|
||||
|
||||
/* Check into the event tracker. */
|
||||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFindUserLockedStatus() throws UserNotFoundException {
|
||||
assertCleanUserManager();
|
||||
securityPolicy.setEnabled(false);
|
||||
public void testAddFindUserLockedStatus()
|
||||
throws UserNotFoundException
|
||||
{
|
||||
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
|
||||
* actual principal that was managed by jpox/jdo.
|
||||
*/
|
||||
User added = userManager.addUser( smcqueen );
|
||||
User added = userManager.addUser( smcqueen );
|
||||
|
||||
assertTrue( added.isLocked() );
|
||||
|
||||
assertEquals(1, userManager.getUsers().size());
|
||||
assertTrue( added.isLocked() );
|
||||
|
||||
assertEquals( 1, userManager.getUsers().size() );
|
||||
|
||||
/* Fetch user from userManager using principal returned earlier */
|
||||
User actual = userManager.findUser(added.getPrincipal());
|
||||
assertEquals(added, actual);
|
||||
User actual = userManager.findUser( added.getUsername() );
|
||||
assertEquals( added, actual );
|
||||
|
||||
assertTrue( actual.isLocked() );
|
||||
assertTrue( actual.isLocked() );
|
||||
|
||||
/* Check into the event tracker. */
|
||||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit);
|
||||
assertNotNull(getEventTracker().lastDbFreshness);
|
||||
assertTrue(getEventTracker().lastDbFreshness.booleanValue());
|
||||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
assertEquals(1, getEventTracker().addedUsernames.size());
|
||||
assertEquals(0, getEventTracker().removedUsernames.size());
|
||||
assertEquals(0, getEventTracker().updatedUsernames.size());
|
||||
}
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddFindUserByUsername()
|
||||
|
@ -240,7 +242,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -264,7 +266,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -292,7 +294,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -312,7 +314,7 @@ public class AbstractUserManagerTestCase
|
|||
|
||||
assertEquals( 1, um.getUsers().size() );
|
||||
|
||||
um.deleteUser( user.getPrincipal() );
|
||||
um.deleteUser( user.getUsername() );
|
||||
assertEquals( 0, um.getUsers().size() );
|
||||
|
||||
// attempt finding a non-existent user
|
||||
|
@ -330,7 +332,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 1, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -364,7 +366,7 @@ public class AbstractUserManagerTestCase
|
|||
User user = um.findUser( "root" );
|
||||
assertNotNull( user );
|
||||
assertEquals( "root@somedomain.com", user.getEmail() );
|
||||
assertEquals( "root", user.getPrincipal() );
|
||||
assertEquals( "root", user.getUsername() );
|
||||
assertEquals( "Root User", user.getFullName() );
|
||||
// test if the plain string password is encoded and NULL'ified
|
||||
assertNull( user.getPassword() );
|
||||
|
@ -386,7 +388,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 3, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -520,7 +522,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -562,7 +564,7 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 1, getEventTracker().updatedUsernames.size() );
|
||||
|
@ -585,13 +587,14 @@ public class AbstractUserManagerTestCase
|
|||
|
||||
try
|
||||
{
|
||||
um.deleteUser( user.getPrincipal() );
|
||||
fail("Deleting permanent user shold throw PermanentUserException.");
|
||||
} catch( PermanentUserException e )
|
||||
um.deleteUser( user.getUsername() );
|
||||
fail( "Deleting permanent user shold throw PermanentUserException." );
|
||||
}
|
||||
catch ( PermanentUserException e )
|
||||
{
|
||||
// do nothing, expected route.
|
||||
}
|
||||
|
||||
|
||||
assertEquals( 1, um.getUsers().size() );
|
||||
|
||||
// attempt to finding user
|
||||
|
@ -604,10 +607,11 @@ public class AbstractUserManagerTestCase
|
|||
assertEquals( EVENTTRACKERCOUNT, getEventTracker().countInit );
|
||||
assertNotNull( getEventTracker().lastDbFreshness );
|
||||
assertTrue( getEventTracker().lastDbFreshness.booleanValue() );
|
||||
|
||||
|
||||
assertEquals( 1, getEventTracker().addedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().removedUsernames.size() );
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() ); }
|
||||
assertEquals( 0, getEventTracker().updatedUsernames.size() );
|
||||
}
|
||||
|
||||
public UserManagerEventTracker getEventTracker()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue