diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java index 2cd6a50c..a66e88bf 100644 --- a/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java +++ b/redback-authentication/redback-authentication-providers/redback-authentication-ldap/src/main/java/org/apache/archiva/redback/authentication/ldap/LdapBindAuthenticator.java @@ -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; diff --git a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java index 5622236b..2077261e 100644 --- a/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java +++ b/redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/LdapUser.java @@ -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( 0 ); - failedLoginAttempts = 0; + this.previousEncodedPasswords = new ArrayList( 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() { diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java index e5e7b143..fce83a1b 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java @@ -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() diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/GuestUserEnvironmentCheck.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/GuestUserEnvironmentCheck.java index 083c01b3..21c3626d 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/GuestUserEnvironmentCheck.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/GuestUserEnvironmentCheck.java @@ -78,7 +78,7 @@ public class GuestUserEnvironmentCheck try { - roleManager.assignRole( "guest", guest.getPrincipal().toString() ); + roleManager.assignRole( "guest", guest.getUsername() ); } catch ( RoleManagerException rpe ) { diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/HttpAuthenticator.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/HttpAuthenticator.java index f5d1b4a0..33a10736 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/HttpAuthenticator.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/HttpAuthenticator.java @@ -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 ) diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/digest/HttpDigestAuthentication.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/digest/HttpDigestAuthentication.java index ef6632e9..0a917415 100644 --- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/digest/HttpDigestAuthentication.java +++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/digest/HttpDigestAuthentication.java @@ -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() ); diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java index ce3447b9..0f156313 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java @@ -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 ); diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java index 96bef482..a55b07fc 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/PermissionsInterceptor.java @@ -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 ); } } diff --git a/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java index a825bc00..66cb5583 100644 --- a/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java +++ b/redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java @@ -44,16 +44,16 @@ import javax.annotation.Resource; * * @author: Jesse McConnell */ -@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 ); } } diff --git a/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java b/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java index d00eb56d..d14a2d4e 100644 --- a/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java +++ b/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java @@ -116,7 +116,7 @@ public class RbacAuthorizer { // Set permissions = manager.getAssignedPermissions( principal.toString(), operation ); Map> 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 ); } diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java index 3e7332d4..c37971c6 100644 --- a/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java +++ b/redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java @@ -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 ); } } diff --git a/redback-users/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java b/redback-users/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java index 3296f9ff..5614fa30 100644 --- a/redback-users/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java +++ b/redback-users/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java @@ -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 ); diff --git a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/User.java b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/User.java index d8c9d3f9..a0d4fd18 100644 --- a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/User.java +++ b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/User.java @@ -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. // -------------------------------------------------------------------- diff --git a/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java b/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java index dd768825..b2be9a24 100644 --- a/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java +++ b/redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java @@ -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() ); } } diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo b/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo index a0c90ca1..5a8c9a1f 100644 --- a/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo +++ b/redback-users/redback-users-providers/redback-users-jdo/src/main/mdo/user.mdo @@ -147,13 +147,9 @@ public JdoUser() { // Intentionally initialize List to avoid JPOX NullPointerException Issues. - previousEncodedPasswords = new java.util.ArrayList(); + previousEncodedPasswords = new java.util.ArrayList(); } - public Object getPrincipal() - { - return username; - } ]]> diff --git a/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java b/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java index dcaa661d..7581eef6 100644 --- a/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java +++ b/redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java @@ -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 { diff --git a/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java b/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java index e3c298b2..7283c3b8 100644 --- a/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java +++ b/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java @@ -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" ) ); } diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java index 927e4ba1..ca7e4a55 100644 --- a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java +++ b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java @@ -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 ); } diff --git a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java index 2f37a4c9..e8ae074e 100644 --- a/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java +++ b/redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/SimpleUser.java @@ -121,11 +121,6 @@ public class SimpleUser return previousEncodedPasswords; } - public Object getPrincipal() - { - return username; - } - public String getUsername() { return username; diff --git a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java index ce8aecdd..d4adc137 100644 --- a/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java +++ b/redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java @@ -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 Joakim Erdfelt - * */ -@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() {