UserManagerException is now a checked Exception

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1419568 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-10 16:34:46 +00:00
parent e0dc1a1966
commit 30c1cfa2a4
33 changed files with 504 additions and 264 deletions

View File

@ -32,6 +32,7 @@ import org.apache.archiva.redback.policy.PolicyViolationException;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -152,6 +153,14 @@ public class UserManagerAuthenticator
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." );
} }
catch ( UserManagerException e )
{
log.warn( "Login for user {} failed, message: {}", source.getPrincipal(), e.getMessage() );
resultException = e;
authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_RUNTIME_EXCEPTION,
"Login for user " + source.getPrincipal() + " failed, message: "
+ e.getMessage() );
}
return new AuthenticationResult( authenticationSuccess, username, resultException, authnResultExceptionsMap ); return new AuthenticationResult( authenticationSuccess, username, resultException, authnResultExceptionsMap );
} }

View File

@ -24,6 +24,7 @@ import org.apache.archiva.redback.authentication.Authenticator;
import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.policy.MustChangePasswordException;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authentication.AuthenticationResult;
@ -117,7 +118,7 @@ public class UserManagerAuthenticatorTest
@Test @Test
public void testAuthenticateLockedPassword() public void testAuthenticateLockedPassword()
throws AuthenticationException, MustChangePasswordException, UserNotFoundException throws AuthenticationException, MustChangePasswordException, UserNotFoundException, UserManagerException
{ {
userSecurityPolicy.setEnabled( true ); userSecurityPolicy.setEnabled( true );
@ -156,7 +157,7 @@ public class UserManagerAuthenticatorTest
@Test @Test
public void testAuthenticateExpiredPassword() public void testAuthenticateExpiredPassword()
throws AuthenticationException, AccountLockedException, UserNotFoundException throws AuthenticationException, AccountLockedException, UserNotFoundException, UserManagerException
{ {
userSecurityPolicy.setEnabled( true ); userSecurityPolicy.setEnabled( true );
userSecurityPolicy.setPasswordExpirationDays( 15 ); userSecurityPolicy.setPasswordExpirationDays( 15 );

View File

@ -23,6 +23,7 @@ import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.keys.KeyManager; import org.apache.archiva.redback.keys.KeyManager;
import org.apache.archiva.redback.rbac.RBACManager; import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.RbacManagerException; import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.users.UserManagerException;
import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamException;
import java.io.File; import java.io.File;
@ -38,7 +39,7 @@ public interface DataManagementTool
throws RbacManagerException, IOException, XMLStreamException; throws RbacManagerException, IOException, XMLStreamException;
void backupUserDatabase( UserManager manager, File backupDirectory ) void backupUserDatabase( UserManager manager, File backupDirectory )
throws IOException, XMLStreamException; throws IOException, XMLStreamException, UserManagerException;
void backupKeyDatabase( KeyManager manager, File backupDirectory ) void backupKeyDatabase( KeyManager manager, File backupDirectory )
throws IOException, XMLStreamException; throws IOException, XMLStreamException;
@ -47,7 +48,7 @@ public interface DataManagementTool
throws IOException, XMLStreamException, RbacManagerException; throws IOException, XMLStreamException, RbacManagerException;
void restoreUsersDatabase( UserManager manager, File backupDirectory ) void restoreUsersDatabase( UserManager manager, File backupDirectory )
throws IOException, XMLStreamException; throws IOException, XMLStreamException, UserManagerException;
void restoreKeysDatabase( KeyManager manager, File backupDirectory ) void restoreKeysDatabase( KeyManager manager, File backupDirectory )
throws IOException, XMLStreamException; throws IOException, XMLStreamException;

View File

@ -52,6 +52,7 @@ import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.Resource; import org.apache.archiva.redback.rbac.Resource;
import org.apache.archiva.redback.rbac.UserAssignment; import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.jdo.UserDatabase; import org.apache.archiva.redback.users.jdo.UserDatabase;
import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxReader; import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxReader;
import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxWriter; import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxWriter;
@ -97,7 +98,7 @@ public class JdoDataManagementTool
} }
public void backupUserDatabase( UserManager manager, File backupDirectory ) public void backupUserDatabase( UserManager manager, File backupDirectory )
throws IOException, XMLStreamException throws IOException, XMLStreamException, UserManagerException
{ {
UserDatabase database = new UserDatabase(); UserDatabase database = new UserDatabase();
database.setUsers( manager.getUsers() ); database.setUsers( manager.getUsers() );
@ -232,7 +233,7 @@ public class JdoDataManagementTool
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public void restoreUsersDatabase( UserManager manager, File backupDirectory ) public void restoreUsersDatabase( UserManager manager, File backupDirectory )
throws IOException, XMLStreamException throws IOException, XMLStreamException, UserManagerException
{ {
UsersManagementStaxReader reader = new UsersManagementStaxReader(); UsersManagementStaxReader reader = new UsersManagementStaxReader();

View File

@ -28,6 +28,7 @@ import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.Role; import org.apache.archiva.redback.rbac.Role;
import org.apache.archiva.redback.rbac.UserAssignment; import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.SystemUtils; import org.apache.commons.lang.SystemUtils;
@ -184,6 +185,7 @@ public class DataManagementTest
} }
private void createUserDatabase( UserManager manager ) private void createUserDatabase( UserManager manager )
throws UserManagerException
{ {
User user = manager.createUser( "smcqueen", "Steve McQueen", "the cooler king" ); User user = manager.createUser( "smcqueen", "Steve McQueen", "the cooler king" );
user.setPassword( "abc123" ); user.setPassword( "abc123" );
@ -373,6 +375,7 @@ public class DataManagementTest
} }
private void assertEmpty( UserManager manager ) private void assertEmpty( UserManager manager )
throws UserManagerException
{ {
List<User> users = manager.getUsers(); List<User> users = manager.getUsers();
assertEquals( 0, users.size() ); assertEquals( 0, users.size() );

View File

@ -30,6 +30,7 @@ import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.system.check.EnvironmentCheck; import org.apache.archiva.redback.system.check.EnvironmentCheck;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -91,13 +92,15 @@ public class AdminAutoCreateCheck
{ {
useForceAdminCreationFile(); useForceAdminCreationFile();
} }
} }
catch ( UserNotFoundException e ) catch ( UserNotFoundException e )
{ {
useForceAdminCreationFile(); useForceAdminCreationFile();
} }
catch ( UserManagerException e )
{
useForceAdminCreationFile();
}
} }
private void useForceAdminCreationFile() private void useForceAdminCreationFile()

View File

@ -22,6 +22,7 @@ package org.apache.archiva.redback.integration.checks.security;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.role.RoleManagerException; import org.apache.archiva.redback.role.RoleManagerException;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.role.RoleManager; import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.system.SecuritySystem; import org.apache.archiva.redback.system.SecuritySystem;
@ -36,7 +37,6 @@ import java.util.List;
* RequiredRolesEnvironmentCheck: * RequiredRolesEnvironmentCheck:
* *
* @author: Jesse McConnell <jesse@codehaus.org> * @author: Jesse McConnell <jesse@codehaus.org>
*
*/ */
@Service("environmentCheck#guest-user-check") @Service("environmentCheck#guest-user-check")
public class GuestUserEnvironmentCheck public class GuestUserEnvironmentCheck
@ -64,15 +64,23 @@ public class GuestUserEnvironmentCheck
UserManager userManager = securitySystem.getUserManager(); UserManager userManager = securitySystem.getUserManager();
UserSecurityPolicy policy = securitySystem.getPolicy(); UserSecurityPolicy policy = securitySystem.getPolicy();
User guest; User guest = null;
try try
{ {
guest = userManager.getGuestUser(); guest = userManager.getGuestUser();
} }
catch ( UserNotFoundException e ) catch ( UserManagerException e )
{ {
policy.setEnabled( false ); policy.setEnabled( false );
try
{
guest = userManager.createGuestUser(); guest = userManager.createGuestUser();
}
catch ( UserManagerException ume )
{
violations.add( "unable to initialize guest user properly: " + ume.getMessage() );
return;
}
policy.setEnabled( true ); policy.setEnabled( true );
} }

View File

@ -26,6 +26,7 @@ import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.system.check.EnvironmentCheck; import org.apache.archiva.redback.system.check.EnvironmentCheck;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -41,7 +42,6 @@ import java.util.List;
* and unlocks them on startup. * and unlocks them on startup.
* *
* @author: Jesse McConnell <jesse@codehaus.org> * @author: Jesse McConnell <jesse@codehaus.org>
*
*/ */
@Service( "environmentCheck#locked-admin-check" ) @Service( "environmentCheck#locked-admin-check" )
public class LockedAdminEnvironmentCheck public class LockedAdminEnvironmentCheck
@ -98,6 +98,11 @@ public class LockedAdminEnvironmentCheck
{ {
log.warn( "Dangling UserAssignment -> {}", userAssignment.getPrincipal() ); log.warn( "Dangling UserAssignment -> {}", userAssignment.getPrincipal() );
} }
catch ( UserManagerException e )
{
log.warn( "fail to find user {} for admin unlock check: {}", userAssignment.getPrincipal(),
e.getMessage() );
}
} }
} }
catch ( RbacManagerException e ) catch ( RbacManagerException e )

View File

@ -22,6 +22,7 @@ package org.apache.archiva.redback.integration.filter.authentication;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.policy.MustChangePasswordException;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.authentication.AuthenticationDataSource; import org.apache.archiva.redback.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authentication.AuthenticationResult;
@ -43,7 +44,6 @@ import java.io.IOException;
* HttpAuthenticator * HttpAuthenticator
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
public abstract class HttpAuthenticator public abstract class HttpAuthenticator
{ {
@ -80,6 +80,11 @@ public abstract class HttpAuthenticator
log.info( "Login attempt against unknown user: {}", ds ); log.info( "Login attempt against unknown user: {}", ds );
throw new HttpAuthenticationException( "User name or password invalid." ); throw new HttpAuthenticationException( "User name or password invalid." );
} }
catch ( UserManagerException e )
{
log.info( "UserManagerException: {}", e.getMessage() );
throw new HttpAuthenticationException( e.getMessage(), e );
}
} }
/** /**
@ -176,28 +181,5 @@ public abstract class HttpAuthenticator
httpSession.setAttribute( SecuritySession.USERKEY, user ); httpSession.setAttribute( SecuritySession.USERKEY, user );
} }
public String storeDefaultUser( String principal, HttpSession httpSession )
{
httpSession.setAttribute( SecuritySession.SESSION_KEY, null );
httpSession.setAttribute( SecuritySession.USERKEY, null );
if ( StringUtils.isEmpty( principal ) )
{
return null;
}
try
{
User user = securitySystem.getUserManager().findUser( principal );
httpSession.setAttribute( SecuritySession.USERKEY, user );
return user.getUsername();
} }
catch ( UserNotFoundException e )
{
log.warn( "Default User '" + principal + "' not found.", e );
return null;
}
}
}

View File

@ -22,6 +22,7 @@ package org.apache.archiva.redback.integration.filter.authentication.digest;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.policy.MustChangePasswordException;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.archiva.redback.authentication.AuthenticationResult; import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource; import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
@ -44,7 +45,6 @@ import java.io.IOException;
* HttpDigestAuthentication methods for working with <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617 HTTP Authentication</a>. * HttpDigestAuthentication methods for working with <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617 HTTP Authentication</a>.
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service("httpAuthenticator#digest") @Service("httpAuthenticator#digest")
public class HttpDigestAuthentication public class HttpDigestAuthentication
@ -61,8 +61,6 @@ public class HttpDigestAuthentication
/** /**
* NOTE: Must be alphanumeric. * NOTE: Must be alphanumeric.
*
*
*/ */
private String digestKey = "OrycteropusAfer"; private String digestKey = "OrycteropusAfer";
@ -126,6 +124,11 @@ public class HttpDigestAuthentication
log.error( msg, e ); log.error( msg, e );
throw new HttpAuthenticationException( msg, e ); throw new HttpAuthenticationException( msg, e );
} }
catch ( UserManagerException e )
{
log.error( "issue find user {}, message: {}", username, e.getMessage(), e );
throw new HttpAuthenticationException( "issue find user " + username + ", message: " + e.getMessage(), e );
}
} }
/** /**
@ -194,8 +197,8 @@ public class HttpDigestAuthentication
} }
else else
{ {
throw new IllegalStateException( "Http Digest Parameter [qop] with value of [" + digestHeader.qop throw new IllegalStateException(
+ "] is unsupported." ); "Http Digest Parameter [qop] with value of [" + digestHeader.qop + "] is unsupported." );
} }
return Digest.md5Hex( digest ); return Digest.md5Hex( digest );

View File

@ -21,6 +21,7 @@ package org.apache.archiva.redback.integration.model;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
@ -54,6 +55,7 @@ public abstract class UserCredentials
private String timestampLastPasswordChange; private String timestampLastPasswordChange;
public User createUser( UserManager um ) public User createUser( UserManager um )
throws UserManagerException
{ {
User user = um.createUser( username, fullName, email ); User user = um.createUser( username, fullName, email );

View File

@ -36,6 +36,7 @@ import org.apache.archiva.redback.rest.api.services.LoginService;
import org.apache.archiva.redback.rest.api.services.RedbackServiceException; import org.apache.archiva.redback.rest.api.services.RedbackServiceException;
import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.system.SecuritySession;
import org.apache.archiva.redback.system.SecuritySystem; import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,6 +49,7 @@ import javax.servlet.http.HttpSession;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -178,6 +180,14 @@ public class DefaultLoginService
{ {
return buildRestUser( e.getUser() ); return buildRestUser( e.getUser() );
} }
catch ( UserManagerException e )
{
log.info( "UserManagerException: {}", e.getMessage() );
List<ErrorMessage> errorMessages =
Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
throw new RedbackServiceException( errorMessages );
}
} }
public Boolean isLogged() public Boolean isLogged()

View File

@ -22,6 +22,7 @@ import org.apache.archiva.redback.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.PasswordRuleViolationException; import org.apache.archiva.redback.policy.PasswordRuleViolationException;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.archiva.redback.keys.AuthenticationKey; import org.apache.archiva.redback.keys.AuthenticationKey;
import org.apache.archiva.redback.keys.KeyManagerException; import org.apache.archiva.redback.keys.KeyManagerException;
@ -42,6 +43,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context; import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -74,12 +76,12 @@ public class DefaultPasswordService
this.passwordValidator = passwordValidator; this.passwordValidator = passwordValidator;
} }
public org.apache.archiva.redback.rest.api.model.User changePasswordWithKey( String password, String passwordConfirmation, public org.apache.archiva.redback.rest.api.model.User changePasswordWithKey( String password,
String passwordConfirmation,
String key ) String key )
throws RedbackServiceException throws RedbackServiceException
{ {
//RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get(); //RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
String principal = null; String principal = null;
@ -130,6 +132,13 @@ public class DefaultPasswordService
errorMessages.add( errorMessage ); errorMessages.add( errorMessage );
throw new RedbackServiceException( errorMessages ); throw new RedbackServiceException( errorMessages );
} }
catch ( UserManagerException e )
{
log.info( "UserManagerException: {}", e.getMessage() );
List<ErrorMessage> errorMessages =
Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
throw new RedbackServiceException( errorMessages );
}
catch ( PasswordRuleViolationException e ) catch ( PasswordRuleViolationException e )
{ {
PasswordRuleViolations violations = e.getViolations(); PasswordRuleViolations violations = e.getViolations();
@ -203,6 +212,13 @@ public class DefaultPasswordService
throw new RedbackServiceException( new ErrorMessage( "user.not.found" ), throw new RedbackServiceException( new ErrorMessage( "user.not.found" ),
Response.Status.BAD_REQUEST.getStatusCode() ); Response.Status.BAD_REQUEST.getStatusCode() );
} }
catch ( UserManagerException e )
{
log.info( "UserManagerException: {}", e.getMessage() );
List<ErrorMessage> errorMessages =
Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
throw new RedbackServiceException( errorMessages );
}
} }
} }

View File

@ -30,6 +30,7 @@ import org.apache.archiva.redback.role.model.ModelRole;
import org.apache.archiva.redback.role.model.ModelTemplate; import org.apache.archiva.redback.role.model.ModelTemplate;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.archiva.redback.integration.model.AdminEditUserCredentials; import org.apache.archiva.redback.integration.model.AdminEditUserCredentials;
@ -404,7 +405,8 @@ public class DefaultRoleManagementService
try try
{ {
User user = userManager.findUser( userAssignment.getPrincipal() ); User user = userManager.findUser( userAssignment.getPrincipal() );
role.getParentsRolesUsers().add( new org.apache.archiva.redback.rest.api.model.User( user ) ); role.getParentsRolesUsers().add(
new org.apache.archiva.redback.rest.api.model.User( user ) );
} }
catch ( UserNotFoundException e ) catch ( UserNotFoundException e )
{ {
@ -418,8 +420,8 @@ public class DefaultRoleManagementService
new ArrayList<org.apache.archiva.redback.rest.api.model.User>(); new ArrayList<org.apache.archiva.redback.rest.api.model.User>();
for ( User u : userManager.getUsers() ) for ( User u : userManager.getUsers() )
{ {
org.apache.archiva.redback.rest.api.model.User org.apache.archiva.redback.rest.api.model.User user =
user = new org.apache.archiva.redback.rest.api.model.User( u ); new org.apache.archiva.redback.rest.api.model.User( u );
if ( role.getParentsRolesUsers().contains( user ) ) if ( role.getParentsRolesUsers().contains( user ) )
{ {
continue; continue;
@ -439,6 +441,10 @@ public class DefaultRoleManagementService
{ {
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) ); throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
public Boolean updateRoleDescription( String roleName, String description ) public Boolean updateRoleDescription( String roleName, String description )
@ -464,14 +470,17 @@ public class DefaultRoleManagementService
for ( org.apache.archiva.redback.rest.api.model.User user : role.getUsers() ) for ( org.apache.archiva.redback.rest.api.model.User user : role.getUsers() )
{ {
String username = user.getUsername(); String username = user.getUsername();
if ( !userManager.userExists( username ) )
{
log.error( "user {} not exits", username );
throw new RedbackServiceException( new ErrorMessage( "user.not.exists", new String[]{ username } ) );
}
try try
{ {
if ( !userManager.userExists( username ) )
{
log.error( "user {} not exits", username );
throw new RedbackServiceException(
new ErrorMessage( "user.not.exists", new String[]{ username } ) );
}
UserAssignment assignment; UserAssignment assignment;
if ( rbacManager.userAssignmentExists( username ) ) if ( rbacManager.userAssignmentExists( username ) )
@ -493,19 +502,26 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( throw new RedbackServiceException(
new ErrorMessage( "error.assign.role.user", new String[]{ role.getName(), username } ) ); new ErrorMessage( "error.assign.role.user", new String[]{ role.getName(), username } ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
for ( org.apache.archiva.redback.rest.api.model.User user : role.getRemovedUsers() ) for ( org.apache.archiva.redback.rest.api.model.User user : role.getRemovedUsers() )
{ {
String username = user.getUsername(); String username = user.getUsername();
if ( !userManager.userExists( username ) )
{
log.error( "user {} not exits", username );
throw new RedbackServiceException( new ErrorMessage( "user.not.exists", new String[]{ username } ) );
}
try try
{ {
if ( !userManager.userExists( username ) )
{
log.error( "user {} not exits", username );
throw new RedbackServiceException(
new ErrorMessage( "user.not.exists", new String[]{ username } ) );
}
UserAssignment assignment; UserAssignment assignment;
if ( rbacManager.userAssignmentExists( username ) ) if ( rbacManager.userAssignmentExists( username ) )
@ -527,6 +543,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( throw new RedbackServiceException(
new ErrorMessage( "error.unassign.role.user", new String[]{ role.getName(), username } ) ); new ErrorMessage( "error.unassign.role.user", new String[]{ role.getName(), username } ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
return Boolean.TRUE; return Boolean.TRUE;
@ -541,13 +561,14 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( new ErrorMessage( "rbac.edit.user.empty.principal" ) ); throw new RedbackServiceException( new ErrorMessage( "rbac.edit.user.empty.principal" ) );
} }
if ( !userManager.userExists( username ) )
{
throw new RedbackServiceException( new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
}
try try
{ {
if ( !userManager.userExists( username ) )
{
throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
}
User u = userManager.findUser( username ); User u = userManager.findUser( username );
if ( u == null ) if ( u == null )
@ -562,6 +583,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) ); new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
try try
{ {
// check first if role assignments for user exist // check first if role assignments for user exist
@ -602,7 +627,8 @@ public class DefaultRoleManagementService
for ( String appRoleName : applicationRoles.getGlobalRoles() ) for ( String appRoleName : applicationRoles.getGlobalRoles() )
{ {
if (!roleFromTemplate( appRoleName, modelApplication.getTemplates() )){ if ( !roleFromTemplate( appRoleName, modelApplication.getTemplates() ) )
{
appRoleNames.add( appRoleName ); appRoleNames.add( appRoleName );
} }
} }
@ -635,13 +661,15 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( new ErrorMessage( "rbac.edit.user.empty.principal" ) ); throw new RedbackServiceException( new ErrorMessage( "rbac.edit.user.empty.principal" ) );
} }
if ( !userManager.userExists( username ) )
{
throw new RedbackServiceException( new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
}
try try
{ {
if ( !userManager.userExists( username ) )
{
throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
}
User u = userManager.findUser( username ); User u = userManager.findUser( username );
if ( u == null ) if ( u == null )
@ -655,6 +683,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException( throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) ); new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
try try
{ {

View File

@ -55,6 +55,7 @@ import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.role.RoleManagerException; import org.apache.archiva.redback.role.RoleManagerException;
import org.apache.archiva.redback.system.SecuritySystem; import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -159,6 +160,10 @@ public class DefaultUserService
//ignore we just want to prevent non human readable error message from backend :-) //ignore we just want to prevent non human readable error message from backend :-)
log.debug( "user {} not exists", user.getUsername() ); log.debug( "user {} not exists", user.getUsername() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
// data validation // data validation
if ( StringUtils.isEmpty( user.getUsername() ) ) if ( StringUtils.isEmpty( user.getUsername() ) )
@ -176,6 +181,9 @@ public class DefaultUserService
throw new RedbackServiceException( new ErrorMessage( "email cannot be empty" ) ); throw new RedbackServiceException( new ErrorMessage( "email cannot be empty" ) );
} }
try
{
org.apache.archiva.redback.users.User u = org.apache.archiva.redback.users.User u =
userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() ); userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
u.setPassword( user.getPassword() ); u.setPassword( user.getPassword() );
@ -197,8 +205,7 @@ public class DefaultUserService
throw new RedbackServiceException( e.getMessage() ); throw new RedbackServiceException( e.getMessage() );
} }
} }
try
{
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() ); roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
} }
catch ( RoleManagerException rpe ) catch ( RoleManagerException rpe )
@ -206,6 +213,10 @@ public class DefaultUserService
log.error( "RoleProfile Error: " + rpe.getMessage(), rpe ); log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) ); throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return Boolean.TRUE; return Boolean.TRUE;
} }
@ -238,6 +249,10 @@ public class DefaultUserService
log.error( e.getMessage(), e ); log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() ); throw new RedbackServiceException( e.getMessage() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
finally finally
{ {
removeFromCache( username ); removeFromCache( username );
@ -257,10 +272,16 @@ public class DefaultUserService
{ {
return null; return null;
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
public List<User> getUsers() public List<User> getUsers()
throws RedbackServiceException throws RedbackServiceException
{
try
{ {
List<org.apache.archiva.redback.users.User> users = userManager.getUsers(); List<org.apache.archiva.redback.users.User> users = userManager.getUsers();
List<User> simpleUsers = new ArrayList<User>( users.size() ); List<User> simpleUsers = new ArrayList<User>( users.size() );
@ -272,6 +293,11 @@ public class DefaultUserService
return simpleUsers; return simpleUsers;
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
}
public Boolean updateMe( User user ) public Boolean updateMe( User user )
throws RedbackServiceException throws RedbackServiceException
@ -322,6 +348,10 @@ public class DefaultUserService
throw new RedbackServiceException( new ErrorMessage( "user not found" ), throw new RedbackServiceException( new ErrorMessage( "user not found" ),
Response.Status.BAD_REQUEST.getStatusCode() ); Response.Status.BAD_REQUEST.getStatusCode() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
// only 3 fields to update // only 3 fields to update
realUser.setFullName( user.getFullName() ); realUser.setFullName( user.getFullName() );
realUser.setEmail( user.getEmail() ); realUser.setEmail( user.getEmail() );
@ -359,6 +389,10 @@ public class DefaultUserService
{ {
throw new RedbackServiceException( e.getMessage() ); throw new RedbackServiceException( e.getMessage() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
public int removeFromCache( String userName ) public int removeFromCache( String userName )
@ -433,6 +467,10 @@ public class DefaultUserService
log.error( e.getMessage(), e ); log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() ); throw new RedbackServiceException( e.getMessage() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
finally finally
{ {
@ -466,6 +504,8 @@ public class DefaultUserService
return Boolean.FALSE; return Boolean.FALSE;
} }
try
{
org.apache.archiva.redback.users.User user = org.apache.archiva.redback.users.User user =
userManager.createUser( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(), userManager.createUser( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(),
adminUser.getEmail() ); adminUser.getEmail() );
@ -477,15 +517,16 @@ public class DefaultUserService
user.setValidated( true ); user.setValidated( true );
userManager.addUser( user ); userManager.addUser( user );
try
{
roleManager.assignRole( "system-administrator", user.getUsername() ); roleManager.assignRole( "system-administrator", user.getUsername() );
} }
catch ( RoleManagerException e ) catch ( RoleManagerException e )
{ {
throw new RedbackServiceException( e.getMessage() ); throw new RedbackServiceException( e.getMessage() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return Boolean.TRUE; return Boolean.TRUE;
} }
@ -501,6 +542,10 @@ public class DefaultUserService
{ {
// ignore // ignore
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return Boolean.FALSE; return Boolean.FALSE;
} }
@ -543,6 +588,10 @@ public class DefaultUserService
log.info( "Unable to issue password reset.", e ); log.info( "Unable to issue password reset.", e );
throw new RedbackServiceException( new ErrorMessage( "password.reset.email.generation.failure" ) ); throw new RedbackServiceException( new ErrorMessage( "password.reset.email.generation.failure" ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
return Boolean.TRUE; return Boolean.TRUE;
} }
@ -570,6 +619,11 @@ public class DefaultUserService
validateCredentialsStrict( user ); validateCredentialsStrict( user );
} }
org.apache.archiva.redback.users.User u = null;
try
{
// NOTE: Do not perform Password Rules Validation Here. // NOTE: Do not perform Password Rules Validation Here.
if ( userManager.userExists( user.getUsername() ) ) if ( userManager.userExists( user.getUsername() ) )
@ -578,14 +632,11 @@ public class DefaultUserService
new ErrorMessage( "user.already.exists", new String[]{ user.getUsername() } ) ); new ErrorMessage( "user.already.exists", new String[]{ user.getUsername() } ) );
} }
org.apache.archiva.redback.users.User u = u = userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
u.setPassword( user.getPassword() ); u.setPassword( user.getPassword() );
u.setValidated( false ); u.setValidated( false );
u.setLocked( false ); u.setLocked( false );
try
{
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() ); roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
} }
catch ( RoleManagerException rpe ) catch ( RoleManagerException rpe )
@ -593,6 +644,10 @@ public class DefaultUserService
log.error( "RoleProfile Error: " + rpe.getMessage(), rpe ); log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) ); throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
if ( emailValidationRequired ) if ( emailValidationRequired )
{ {
@ -624,16 +679,27 @@ public class DefaultUserService
log.error( "Unable to register a new user.", e ); log.error( "Unable to register a new user.", e );
throw new RedbackServiceException( new ErrorMessage( "cannot.register.user", null ) ); throw new RedbackServiceException( new ErrorMessage( "cannot.register.user", null ) );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
finally finally
{ {
securityPolicy.setEnabled( true ); securityPolicy.setEnabled( true );
} }
} }
else else
{
try
{ {
userManager.addUser( u ); userManager.addUser( u );
return new RegistrationKey( "-1" ); return new RegistrationKey( "-1" );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
}
// FIXME log this event // FIXME log this event
/* /*
@ -702,6 +768,10 @@ public class DefaultUserService
{ {
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() ); throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
} }
public Collection<Permission> getCurrentUserPermissions() public Collection<Permission> getCurrentUserPermissions()
@ -845,7 +915,8 @@ public class DefaultUserService
throws RedbackServiceException throws RedbackServiceException
{ {
validateCredentialsLoose( user ); validateCredentialsLoose( user );
try
{
org.apache.archiva.redback.users.User tmpuser = org.apache.archiva.redback.users.User tmpuser =
userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() ); userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
@ -858,6 +929,11 @@ public class DefaultUserService
throw new RedbackServiceException( new ErrorMessage( "password.required", null ) ); throw new RedbackServiceException( new ErrorMessage( "password.required", null ) );
} }
} }
catch ( UserManagerException e )
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
}
private String getBaseUrl() private String getBaseUrl()
{ {

View File

@ -32,6 +32,7 @@ import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.system.SecuritySession;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
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;
@ -168,5 +169,10 @@ public class AuthenticationInterceptor
log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) ); log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
return Response.status( Response.Status.FORBIDDEN ).build(); return Response.status( Response.Status.FORBIDDEN ).build();
} }
catch ( UserManagerException e )
{
log.debug( "UserManagerException: {} for path", e.getMessage(), message.get( Message.REQUEST_URI ) );
return Response.status( Response.Status.FORBIDDEN ).build();
}
} }
} }

View File

@ -20,6 +20,7 @@ package org.apache.archiva.redback.rest.services.utils;
import org.apache.archiva.redback.policy.PasswordRuleViolations; import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.policy.PasswordEncoder; import org.apache.archiva.redback.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.PasswordRuleViolationException; import org.apache.archiva.redback.policy.PasswordRuleViolationException;
@ -32,6 +33,7 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject; import javax.inject.Inject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
/** /**
@ -48,7 +50,6 @@ public class PasswordValidator
private SecuritySystem securitySystem; private SecuritySystem securitySystem;
/** /**
*
* @param password * @param password
* @param principal * @param principal
* @return encoded password * @return encoded password
@ -98,6 +99,13 @@ public class PasswordValidator
} }
throw new RedbackServiceException( errorMessages ); throw new RedbackServiceException( errorMessages );
} }
catch ( UserManagerException e )
{
log.info( "UserManagerException: {}", e.getMessage() );
List<ErrorMessage> errorMessages =
Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
throw new RedbackServiceException( errorMessages );
}
} }
} }

View File

@ -32,6 +32,7 @@ import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.policy.MustChangePasswordException;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -107,6 +108,11 @@ public class KeyStoreAuthenticator
log.warn( "Login for user {} failed. user not found.", source.getPrincipal() ); log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
return new AuthenticationResult( false, null, e ); return new AuthenticationResult( false, null, e );
} }
catch ( UserManagerException e )
{
log.warn( "Login fail for user {} failed. message: {}", source.getPrincipal(), e.getMessage() );
return new AuthenticationResult( false, null, e );
}
} }
public boolean supportsDataSource( AuthenticationDataSource source ) public boolean supportsDataSource( AuthenticationDataSource source )

View File

@ -32,6 +32,7 @@ import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException; import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -115,8 +116,7 @@ public class RbacAuthorizer
if ( !guest.isLocked() ) if ( !guest.isLocked() )
{ {
// 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.getUsername() );
manager.getAssignedPermissionMap( guest.getUsername() );
if ( permissionMap.keySet().contains( operation.toString() ) ) if ( permissionMap.keySet().contains( operation.toString() ) )
{ {
@ -151,6 +151,10 @@ public class RbacAuthorizer
{ {
return new AuthorizationResult( false, null, rme ); return new AuthorizationResult( false, null, rme );
} }
catch ( UserManagerException e )
{
return new AuthorizationResult( false, null, e );
}
} }
public RBACManager getManager() public RBACManager getManager()

View File

@ -21,6 +21,7 @@ package org.apache.archiva.redback.authorization.rbac.evaluator;
import org.apache.archiva.redback.rbac.Resource; import org.apache.archiva.redback.rbac.Resource;
import org.apache.archiva.redback.users.UserManager; import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.rbac.Permission; import org.apache.archiva.redback.rbac.Permission;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -35,7 +36,6 @@ import javax.inject.Named;
* of the person making the authorization check * of the person making the authorization check
* *
* @author Jesse McConnell <jesse@codehaus.org> * @author Jesse McConnell <jesse@codehaus.org>
*
*/ */
@Service("permissionEvaluator") @Service("permissionEvaluator")
public class DefaultPermissionEvaluator public class DefaultPermissionEvaluator
@ -61,9 +61,13 @@ public class DefaultPermissionEvaluator
{ {
permissionResource = userManager.findUser( principal.toString() ).getUsername(); permissionResource = userManager.findUser( principal.toString() ).getUsername();
} }
catch ( UserNotFoundException ne ) catch ( UserNotFoundException e )
{ {
throw new PermissionEvaluationException( "unable to locate user to retrieve username", ne ); throw new PermissionEvaluationException( "unable to locate user to retrieve username", e );
}
catch ( UserManagerException e )
{
throw new PermissionEvaluationException( "trouble finding user: " + e.getMessage(), e );
} }
} }
} }

View File

@ -24,6 +24,7 @@ import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.authentication.AuthenticationDataSource; import org.apache.archiva.redback.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
@ -45,7 +46,6 @@ import javax.inject.Named;
* DefaultSecuritySystem: * DefaultSecuritySystem:
* *
* @author: Jesse McConnell <jesse@codehaus.org> * @author: Jesse McConnell <jesse@codehaus.org>
*
*/ */
@Service("securitySystem") @Service("securitySystem")
public class DefaultSecuritySystem public class DefaultSecuritySystem
@ -92,10 +92,12 @@ public class DefaultSecuritySystem
* @throws UserNotFoundException * @throws UserNotFoundException
* @throws MustChangePasswordException * @throws MustChangePasswordException
* @throws org.apache.archiva.redback.policy.AccountLockedException * @throws org.apache.archiva.redback.policy.AccountLockedException
*
* @throws MustChangePasswordException * @throws MustChangePasswordException
*/ */
public SecuritySession authenticate( AuthenticationDataSource source ) public SecuritySession authenticate( AuthenticationDataSource source )
throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
UserManagerException
{ {
// Perform Authentication. // Perform Authentication.
AuthenticationResult result = authnManager.authenticate( source ); AuthenticationResult result = authnManager.authenticate( source );
@ -127,7 +129,8 @@ public class DefaultSecuritySystem
} }
public boolean isAuthenticated( AuthenticationDataSource source ) public boolean isAuthenticated( AuthenticationDataSource source )
throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
UserManagerException
{ {
return authenticate( source ).getAuthenticationResult().isAuthenticated(); return authenticate( source ).getAuthenticationResult().isAuthenticated();
} }

View File

@ -22,6 +22,7 @@ package org.apache.archiva.redback.system;
import org.apache.archiva.redback.policy.AccountLockedException; import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.MustChangePasswordException; import org.apache.archiva.redback.policy.MustChangePasswordException;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.authentication.AuthenticationDataSource; import org.apache.archiva.redback.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationException; import org.apache.archiva.redback.authentication.AuthenticationException;
@ -34,7 +35,6 @@ import org.apache.archiva.redback.users.UserManager;
* SecuritySystem: * SecuritySystem:
* *
* @author: Jesse McConnell <jesse@codehaus.org> * @author: Jesse McConnell <jesse@codehaus.org>
*
*/ */
public interface SecuritySystem public interface SecuritySystem
{ {
@ -44,10 +44,12 @@ public interface SecuritySystem
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
SecuritySession authenticate( AuthenticationDataSource source ) SecuritySession authenticate( AuthenticationDataSource source )
throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException; throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
UserManagerException;
boolean isAuthenticated( AuthenticationDataSource source ) boolean isAuthenticated( AuthenticationDataSource source )
throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException; throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
UserManagerException;
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Authorization // Authorization
@ -61,6 +63,7 @@ public interface SecuritySystem
/** /**
* return AuthorizationResult without changing authorization * return AuthorizationResult without changing authorization
*
* @param session * @param session
* @param permission * @param permission
* @param resource * @param resource
@ -92,8 +95,8 @@ public interface SecuritySystem
UserSecurityPolicy getPolicy(); UserSecurityPolicy getPolicy();
/** /**
* @since 2.1
* @return is it possible to modify user datas (some userManager cannot i.e ldap) * @return is it possible to modify user datas (some userManager cannot i.e ldap)
* @since 2.1
*/ */
boolean userManagerReadOnly(); boolean userManagerReadOnly();
} }

View File

@ -31,7 +31,6 @@ import javax.annotation.PostConstruct;
* AbstractUserManager * AbstractUserManager
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
public abstract class AbstractUserManager public abstract class AbstractUserManager
implements UserManager implements UserManager
@ -114,12 +113,13 @@ public abstract class AbstractUserManager
} }
public User getGuestUser() public User getGuestUser()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return findUser( GUEST_USERNAME ); return findUser( GUEST_USERNAME );
} }
public User createGuestUser() public User createGuestUser()
throws UserManagerException
{ {
try try
{ {

View File

@ -72,15 +72,19 @@ public interface UserManager
* @param fullName the full name for this user. * @param fullName the full name for this user.
* @param emailAddress the email address for this user. * @param emailAddress the email address for this user.
* @return the new user object ready to use. * @return the new user object ready to use.
* @throws UserManagerException
*/ */
User createUser( String username, String fullName, String emailAddress ); User createUser( String username, String fullName, String emailAddress )
throws UserManagerException;
/** /**
* Factory method to create the guest user. * Factory method to create the guest user.
* *
* @return The guest user * @return The guest user
* @throws UserManagerException
*/ */
User createGuestUser(); User createGuestUser()
throws UserManagerException;
/** /**
* Factory method to create {@link UserQuery}s based on provider specific * Factory method to create {@link UserQuery}s based on provider specific
@ -94,18 +98,23 @@ public interface UserManager
* Get the List of {@link User} objects. * Get the List of {@link User} objects.
* *
* @return the List of {@link User} Objects. * @return the List of {@link User} Objects.
* @throws UserManagerException
*/ */
List<User> getUsers(); List<User> getUsers()
throws UserManagerException;
List<User> getUsers( boolean orderAscending ); List<User> getUsers( boolean orderAscending )
throws UserManagerException;
/** /**
* Add a User. * Add a User.
* *
* @param user the user to add. * @param user the user to add.
* @return the user that was just added. * @return the user that was just added.
* @throws UserManagerException
*/ */
User addUser( User user ); User addUser( User user )
throws UserManagerException;
/** /**
* Update a User. * Update a User.
@ -115,7 +124,7 @@ public interface UserManager
* @throws UserNotFoundException if the user was not found to update. * @throws UserNotFoundException if the user was not found to update.
*/ */
User updateUser( User user ) User updateUser( User user )
throws UserNotFoundException; throws UserNotFoundException, UserManagerException;
/** /**
* Find a User using a User name. * Find a User using a User name.
@ -125,7 +134,7 @@ public interface UserManager
* @throws UserNotFoundException if the user was not found. * @throws UserNotFoundException if the user was not found.
*/ */
User findUser( String username ) User findUser( String username )
throws UserNotFoundException; throws UserNotFoundException, UserManagerException;
/** /**
* Get the guest user. * Get the guest user.
@ -133,13 +142,16 @@ public interface UserManager
* @return the guest user. * @return the guest user.
*/ */
User getGuestUser() User getGuestUser()
throws UserNotFoundException; throws UserNotFoundException, UserManagerException;
List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending ); List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException;
List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending ); List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException;
List<User> findUsersByEmailKey( String emailKey, boolean orderAscending ); List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException;
/** /**
* Find users matching properties, ordering and range as specified by the * Find users matching properties, ordering and range as specified by the
@ -148,7 +160,8 @@ public interface UserManager
* @param query the query. * @param query the query.
* @return a List of {@link User} objects. * @return a List of {@link User} objects.
*/ */
List<User> findUsersByQuery( UserQuery query ); List<User> findUsersByQuery( UserQuery query )
throws UserManagerException;
/** /**
* true if the user exists, false if it doesn't * true if the user exists, false if it doesn't
@ -156,7 +169,8 @@ public interface UserManager
* @param principal * @param principal
* @return true, if user exists * @return true, if user exists
*/ */
boolean userExists( String principal ); boolean userExists( String principal )
throws UserManagerException;
/** /**
* Delete a user using the username. * Delete a user using the username.
@ -165,7 +179,7 @@ public interface UserManager
* @throws UserNotFoundException the user was not found. * @throws UserNotFoundException the user was not found.
*/ */
void deleteUser( String username ) void deleteUser( String username )
throws UserNotFoundException; throws UserNotFoundException, UserManagerException;
/** /**
* Add a user to the database without checking for consistency or adjusting the password. Should only be used for * Add a user to the database without checking for consistency or adjusting the password. Should only be used for
@ -173,30 +187,32 @@ public interface UserManager
* *
* @param user the user to add * @param user the user to add
*/ */
void addUserUnchecked( User user ); void addUserUnchecked( User user )
throws UserManagerException;
void eraseDatabase(); void eraseDatabase();
User updateUser( User user, boolean passwordChangeRequired ) User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException; throws UserNotFoundException, UserManagerException;
/** /**
* consumer of user manager can use it to reload various configuration * consumer of user manager can use it to reload various configuration
* with the configurable implementation is possible to change dynamically the real implementation used. * with the configurable implementation is possible to change dynamically the real implementation used.
*
* @since 2.1 * @since 2.1
*/ */
void initialize(); void initialize();
/** /**
* @since 2.1
* @return true if this implementation is a final one and not a wrapper (configurable, cached) * @return true if this implementation is a final one and not a wrapper (configurable, cached)
* @since 2.1
*/ */
boolean isFinalImplementation(); boolean isFinalImplementation();
/** /**
* @since 2.1
* @return a key to be able to customize label in UI * @return a key to be able to customize label in UI
* @since 2.1
*/ */
String getDescriptionKey(); String getDescriptionKey();
} }

View File

@ -26,7 +26,7 @@ package org.apache.archiva.redback.users;
* *
*/ */
public class UserManagerException public class UserManagerException
extends RuntimeException extends Exception
{ {
public UserManagerException() public UserManagerException()

View File

@ -23,7 +23,7 @@ package org.apache.archiva.redback.users;
* @author Jason van Zyl * @author Jason van Zyl
*/ */
public class UserNotFoundException public class UserNotFoundException
extends Exception extends UserManagerException
{ {
public UserNotFoundException( String string ) public UserNotFoundException( String string )
{ {

View File

@ -21,6 +21,7 @@ package org.apache.archiva.redback.users.cached;
import org.apache.archiva.redback.components.cache.Cache; import org.apache.archiva.redback.components.cache.Cache;
import org.apache.archiva.redback.users.User; import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserManagerListener; import org.apache.archiva.redback.users.UserManagerListener;
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;
@ -37,7 +38,6 @@ import java.util.List;
* CachedUserManager * CachedUserManager
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
@Service( "userManager#cached" ) @Service( "userManager#cached" )
public class CachedUserManager public class CachedUserManager
@ -60,11 +60,13 @@ public class CachedUserManager
} }
public User createGuestUser() public User createGuestUser()
throws UserManagerException
{ {
return userImpl.createGuestUser(); return userImpl.createGuestUser();
} }
public User addUser( User user ) public User addUser( User user )
throws UserManagerException
{ {
if ( user != null ) if ( user != null )
{ {
@ -79,6 +81,7 @@ public class CachedUserManager
} }
public void addUserUnchecked( User user ) public void addUserUnchecked( User user )
throws UserManagerException
{ {
if ( user != null ) if ( user != null )
{ {
@ -88,13 +91,14 @@ public class CachedUserManager
} }
public User createUser( String username, String fullName, String emailAddress ) public User createUser( String username, String fullName, String emailAddress )
throws UserManagerException
{ {
usersCache.remove( username ); usersCache.remove( username );
return this.userImpl.createUser( username, fullName, emailAddress ); return this.userImpl.createUser( username, fullName, emailAddress );
} }
public void deleteUser( String username ) public void deleteUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
usersCache.remove( username ); usersCache.remove( username );
this.userImpl.deleteUser( username ); this.userImpl.deleteUser( username );
@ -113,7 +117,7 @@ public class CachedUserManager
} }
public User findUser( String username ) public User findUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( GUEST_USERNAME.equals( username ) ) if ( GUEST_USERNAME.equals( username ) )
{ {
@ -134,7 +138,7 @@ public class CachedUserManager
} }
public User getGuestUser() public User getGuestUser()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
Object el = usersCache.get( GUEST_USERNAME ); Object el = usersCache.get( GUEST_USERNAME );
if ( el != null ) if ( el != null )
@ -156,24 +160,28 @@ public class CachedUserManager
public List<User> findUsersByQuery( UserQuery query ) public List<User> findUsersByQuery( UserQuery query )
throws UserManagerException
{ {
log.debug( "NOT CACHED - .findUsersByQuery(UserQuery)" ); log.debug( "NOT CACHED - .findUsersByQuery(UserQuery)" );
return this.userImpl.findUsersByQuery( query ); return this.userImpl.findUsersByQuery( query );
} }
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending ) public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException
{ {
log.debug( "NOT CACHED - .findUsersByEmailKey(String, boolean)" ); log.debug( "NOT CACHED - .findUsersByEmailKey(String, boolean)" );
return this.userImpl.findUsersByEmailKey( emailKey, orderAscending ); return this.userImpl.findUsersByEmailKey( emailKey, orderAscending );
} }
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException
{ {
log.debug( "NOT CACHED - .findUsersByFullNameKey(String, boolean)" ); log.debug( "NOT CACHED - .findUsersByFullNameKey(String, boolean)" );
return this.userImpl.findUsersByFullNameKey( fullNameKey, orderAscending ); return this.userImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
} }
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending ) public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException
{ {
log.debug( "NOT CACHED - .findUsersByUsernameKey(String, boolean)" ); log.debug( "NOT CACHED - .findUsersByUsernameKey(String, boolean)" );
return this.userImpl.findUsersByUsernameKey( usernameKey, orderAscending ); return this.userImpl.findUsersByUsernameKey( usernameKey, orderAscending );
@ -185,12 +193,14 @@ public class CachedUserManager
} }
public List<User> getUsers() public List<User> getUsers()
throws UserManagerException
{ {
log.debug( "NOT CACHED - .getUsers()" ); log.debug( "NOT CACHED - .getUsers()" );
return this.userImpl.getUsers(); return this.userImpl.getUsers();
} }
public List<User> getUsers( boolean orderAscending ) public List<User> getUsers( boolean orderAscending )
throws UserManagerException
{ {
log.debug( "NOT CACHED - .getUsers(boolean)" ); log.debug( "NOT CACHED - .getUsers(boolean)" );
return this.userImpl.getUsers( orderAscending ); return this.userImpl.getUsers( orderAscending );
@ -202,13 +212,13 @@ public class CachedUserManager
} }
public User updateUser( User user ) public User updateUser( User user )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return updateUser( user, false ); return updateUser( user, false );
} }
public User updateUser( User user, boolean passwordChangeRequired ) public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( user != null ) if ( user != null )
{ {
@ -218,6 +228,7 @@ public class CachedUserManager
} }
public boolean userExists( String userName ) public boolean userExists( String userName )
throws UserManagerException
{ {
if ( usersCache.hasKey( userName ) ) if ( usersCache.hasKey( userName ) )
{ {

View File

@ -21,6 +21,7 @@ import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.users.AbstractUserManager; import org.apache.archiva.redback.users.AbstractUserManager;
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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
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.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -66,16 +67,19 @@ public class ConfigurableUserManager
} }
public User addUser( User user ) public User addUser( User user )
throws UserManagerException
{ {
return userManagerImpl.addUser( user ); return userManagerImpl.addUser( user );
} }
public void addUserUnchecked( User user ) public void addUserUnchecked( User user )
throws UserManagerException
{ {
userManagerImpl.addUserUnchecked( user ); userManagerImpl.addUserUnchecked( user );
} }
public User createUser( String username, String fullName, String emailAddress ) public User createUser( String username, String fullName, String emailAddress )
throws UserManagerException
{ {
return userManagerImpl.createUser( username, fullName, emailAddress ); return userManagerImpl.createUser( username, fullName, emailAddress );
} }
@ -86,7 +90,7 @@ public class ConfigurableUserManager
} }
public void deleteUser( String username ) public void deleteUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
userManagerImpl.deleteUser( username ); userManagerImpl.deleteUser( username );
} }
@ -97,34 +101,38 @@ public class ConfigurableUserManager
} }
public User findUser( String username ) public User findUser( String username )
throws UserNotFoundException throws UserManagerException, UserNotFoundException
{ {
return userManagerImpl.findUser( username ); return userManagerImpl.findUser( username );
} }
@Override @Override
public User getGuestUser() public User getGuestUser()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return userManagerImpl.getGuestUser(); return userManagerImpl.getGuestUser();
} }
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending ) public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException
{ {
return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending ); return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
} }
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException
{ {
return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending ); return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
} }
public List<User> findUsersByQuery( UserQuery query ) public List<User> findUsersByQuery( UserQuery query )
throws UserManagerException
{ {
return userManagerImpl.findUsersByQuery( query ); return userManagerImpl.findUsersByQuery( query );
} }
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending ) public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException
{ {
return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending ); return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
} }
@ -135,11 +143,13 @@ public class ConfigurableUserManager
} }
public List<User> getUsers() public List<User> getUsers()
throws UserManagerException
{ {
return userManagerImpl.getUsers(); return userManagerImpl.getUsers();
} }
public List<User> getUsers( boolean orderAscending ) public List<User> getUsers( boolean orderAscending )
throws UserManagerException
{ {
return userManagerImpl.getUsers( orderAscending ); return userManagerImpl.getUsers( orderAscending );
} }
@ -150,18 +160,19 @@ public class ConfigurableUserManager
} }
public User updateUser( User user ) public User updateUser( User user )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return updateUser( user, false ); return updateUser( user, false );
} }
public User updateUser( User user, boolean passwordChangeRequired ) public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return userManagerImpl.updateUser( user, passwordChangeRequired ); return userManagerImpl.updateUser( user, passwordChangeRequired );
} }
public boolean userExists( String userName ) public boolean userExists( String userName )
throws UserManagerException
{ {
return userManagerImpl.userExists( userName ); return userManagerImpl.userExists( userName );
} }

View File

@ -209,6 +209,7 @@ public class JdoUserManager
} }
public User addUser( User user ) public User addUser( User user )
throws UserManagerException
{ {
if ( !( user instanceof JdoUser ) ) if ( !( user instanceof JdoUser ) )
{ {
@ -243,6 +244,7 @@ public class JdoUserManager
} }
public void deleteUser( String username ) public void deleteUser( String username )
throws UserManagerException
{ {
try try
{ {
@ -264,6 +266,7 @@ public class JdoUserManager
} }
public void addUserUnchecked( User user ) public void addUserUnchecked( User user )
throws UserManagerException
{ {
if ( !( user instanceof JdoUser ) ) if ( !( user instanceof JdoUser ) )
{ {
@ -287,7 +290,7 @@ public class JdoUserManager
} }
public User findUser( String username ) public User findUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( StringUtils.isEmpty( username ) ) if ( StringUtils.isEmpty( username ) )
{ {
@ -298,6 +301,7 @@ public class JdoUserManager
} }
public boolean userExists( String principal ) public boolean userExists( String principal )
throws UserManagerException
{ {
try try
{ {
@ -311,13 +315,13 @@ public class JdoUserManager
} }
public User updateUser( User user ) public User updateUser( User user )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return updateUser( user, false ); return updateUser( user, false );
} }
public User updateUser( User user, boolean passwordChangeRequired ) public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( !( user instanceof JdoUser ) ) if ( !( user instanceof JdoUser ) )
{ {
@ -385,6 +389,7 @@ public class JdoUserManager
} }
private Object removeObject( Object o ) private Object removeObject( Object o )
throws UserManagerException
{ {
if ( o == null ) if ( o == null )
{ {

View File

@ -21,6 +21,7 @@ package org.apache.archiva.redback.users.jdo;
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory; import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug; import org.apache.archiva.redback.common.jdo.test.StoreManagerDebug;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase; import org.apache.archiva.redback.users.provider.test.AbstractUserManagerTestCase;
import org.jpox.AbstractPersistenceManagerFactory; import org.jpox.AbstractPersistenceManagerFactory;
import org.jpox.SchemaTool; import org.jpox.SchemaTool;
@ -38,7 +39,6 @@ import java.util.Properties;
* JdoUserManagerTest * JdoUserManagerTest
* *
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
*
*/ */
public class JdoUserManagerTest public class JdoUserManagerTest
extends AbstractUserManagerTestCase extends AbstractUserManagerTestCase
@ -106,12 +106,10 @@ public class JdoUserManagerTest
} }
protected void assertCleanUserManager() protected void assertCleanUserManager()
throws UserManagerException
{ {
// database cleanup // database cleanup
( (JdoUserManager) getUserManager() ).eraseDatabase(); ( (JdoUserManager) getUserManager() ).eraseDatabase();
super.assertCleanUserManager(); super.assertCleanUserManager();
} }

View File

@ -74,6 +74,7 @@ public class LdapUserManager
} }
public User addUser( User user ) public User addUser( User user )
throws UserManagerException
{ {
try try
{ {
@ -86,6 +87,7 @@ public class LdapUserManager
} }
public void addUserUnchecked( User user ) public void addUserUnchecked( User user )
throws UserManagerException
{ {
try try
{ {
@ -144,7 +146,7 @@ public class LdapUserManager
public void deleteUser( String username ) public void deleteUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( username != null ) if ( username != null )
{ {
@ -177,7 +179,7 @@ public class LdapUserManager
} }
public User findUser( String username ) public User findUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( username == null ) if ( username == null )
{ {
@ -248,6 +250,7 @@ public class LdapUserManager
} }
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending ) public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
throws UserManagerException
{ {
LdapUserQuery query = new LdapUserQuery(); LdapUserQuery query = new LdapUserQuery();
query.setEmail( emailKey ); query.setEmail( emailKey );
@ -257,6 +260,7 @@ public class LdapUserManager
} }
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
throws UserManagerException
{ {
LdapUserQuery query = new LdapUserQuery(); LdapUserQuery query = new LdapUserQuery();
query.setFullName( fullNameKey ); query.setFullName( fullNameKey );
@ -266,6 +270,7 @@ public class LdapUserManager
} }
public List<User> findUsersByQuery( UserQuery query ) public List<User> findUsersByQuery( UserQuery query )
throws UserManagerException
{ {
if ( query == null ) if ( query == null )
{ {
@ -304,6 +309,7 @@ public class LdapUserManager
* @see org.apache.archiva.redback.users.UserManager#findUsersByUsernameKey(java.lang.String, boolean) * @see org.apache.archiva.redback.users.UserManager#findUsersByUsernameKey(java.lang.String, boolean)
*/ */
public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending ) public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
throws UserManagerException
{ {
LdapUserQuery query = new LdapUserQuery(); LdapUserQuery query = new LdapUserQuery();
query.setUsername( usernameKey ); query.setUsername( usernameKey );
@ -365,13 +371,13 @@ public class LdapUserManager
} }
public User updateUser( User user ) public User updateUser( User user )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
return updateUser( user, false ); return updateUser( user, false );
} }
public User updateUser( User user, boolean passwordChangeRequired ) public User updateUser( User user, boolean passwordChangeRequired )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
if ( user != null ) if ( user != null )
{ {
@ -406,6 +412,7 @@ public class LdapUserManager
} }
public boolean userExists( String principal ) public boolean userExists( String principal )
throws UserManagerException
{ {
if ( principal == null ) if ( principal == null )
{ {

View File

@ -24,6 +24,7 @@ import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.policy.UserSecurityPolicy; import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.AbstractUserManager; import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.PermanentUserException; import org.apache.archiva.redback.users.PermanentUserException;
import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserQuery; import org.apache.archiva.redback.users.UserQuery;
import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.memory.util.UserSorter; import org.apache.archiva.redback.users.memory.util.UserSorter;
@ -163,7 +164,7 @@ public class MemoryUserManager
} }
public void deleteUser( String username ) public void deleteUser( String username )
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
User user = findUser( username ); User user = findUser( username );

View File

@ -24,6 +24,7 @@ import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.PermanentUserException; 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.UserManager;
import org.apache.archiva.redback.users.UserManagerException;
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.junit.Test; import org.junit.Test;
@ -93,6 +94,7 @@ public class AbstractUserManagerTestCase
} }
protected void assertCleanUserManager() protected void assertCleanUserManager()
throws UserManagerException
{ {
getUserManager().eraseDatabase(); getUserManager().eraseDatabase();
@ -105,6 +107,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testFindUserByNullPrincipal() public void testFindUserByNullPrincipal()
throws UserManagerException
{ {
try try
{ {
@ -120,6 +123,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testFindUserByEmptyUsername() public void testFindUserByEmptyUsername()
throws UserManagerException
{ {
try try
{ {
@ -157,7 +161,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testAddFindUserByPrincipal() public void testAddFindUserByPrincipal()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
assertCleanUserManager(); assertCleanUserManager();
securityPolicy.setEnabled( false ); securityPolicy.setEnabled( false );
@ -187,7 +191,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testAddFindUserLockedStatus() public void testAddFindUserLockedStatus()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
assertCleanUserManager(); assertCleanUserManager();
securityPolicy.setEnabled( false ); securityPolicy.setEnabled( false );
@ -224,7 +228,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testAddFindUserByUsername() public void testAddFindUserByUsername()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
assertCleanUserManager(); assertCleanUserManager();
securityPolicy.setEnabled( false ); securityPolicy.setEnabled( false );
@ -396,6 +400,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testFindUsersByQuery() public void testFindUsersByQuery()
throws UserManagerException
{ {
assertCleanUserManager(); assertCleanUserManager();
securityPolicy.setEnabled( false ); securityPolicy.setEnabled( false );
@ -572,7 +577,7 @@ public class AbstractUserManagerTestCase
@Test @Test
public void testDeletePermanentUser() public void testDeletePermanentUser()
throws UserNotFoundException throws UserNotFoundException, UserManagerException
{ {
assertCleanUserManager(); assertCleanUserManager();
securityPolicy.setEnabled( false ); securityPolicy.setEnabled( false );