diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
index 5614fa30..eb982dda 100644
--- a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
+++ b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
@@ -32,6 +32,7 @@ import org.apache.archiva.redback.policy.PolicyViolationException;
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,14 +48,14 @@ import java.util.Map;
*
* @author Rahul Thakur
*/
-@Service ("authenticator#user-manager")
+@Service("authenticator#user-manager")
public class UserManagerAuthenticator
implements Authenticator
{
private Logger log = LoggerFactory.getLogger( getClass() );
@Inject
- @Named (value = "userManager#configurable")
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
@@ -152,6 +153,14 @@ public class UserManagerAuthenticator
authnResultExceptionsMap.put( AuthenticationConstants.AUTHN_NO_SUCH_USER,
"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 );
}
diff --git a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticatorTest.java b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticatorTest.java
index ea80a894..70d289e9 100644
--- a/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticatorTest.java
+++ b/redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticatorTest.java
@@ -24,6 +24,7 @@ import org.apache.archiva.redback.authentication.Authenticator;
import org.apache.archiva.redback.policy.MustChangePasswordException;
import org.apache.archiva.redback.users.User;
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.authentication.AuthenticationException;
import org.apache.archiva.redback.authentication.AuthenticationResult;
@@ -46,8 +47,8 @@ import java.util.Date;
*
* @author Rahul Thakur
*/
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
public class UserManagerAuthenticatorTest
extends TestCase
{
@@ -117,7 +118,7 @@ public class UserManagerAuthenticatorTest
@Test
public void testAuthenticateLockedPassword()
- throws AuthenticationException, MustChangePasswordException, UserNotFoundException
+ throws AuthenticationException, MustChangePasswordException, UserNotFoundException, UserManagerException
{
userSecurityPolicy.setEnabled( true );
@@ -156,7 +157,7 @@ public class UserManagerAuthenticatorTest
@Test
public void testAuthenticateExpiredPassword()
- throws AuthenticationException, AccountLockedException, UserNotFoundException
+ throws AuthenticationException, AccountLockedException, UserNotFoundException, UserManagerException
{
userSecurityPolicy.setEnabled( true );
userSecurityPolicy.setPasswordExpirationDays( 15 );
diff --git a/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java b/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
index 8949cf53..343120c7 100644
--- a/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
+++ b/redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
@@ -23,6 +23,7 @@ import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.keys.KeyManager;
import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.RbacManagerException;
+import org.apache.archiva.redback.users.UserManagerException;
import javax.xml.stream.XMLStreamException;
import java.io.File;
@@ -38,7 +39,7 @@ public interface DataManagementTool
throws RbacManagerException, IOException, XMLStreamException;
void backupUserDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException;
+ throws IOException, XMLStreamException, UserManagerException;
void backupKeyDatabase( KeyManager manager, File backupDirectory )
throws IOException, XMLStreamException;
@@ -47,7 +48,7 @@ public interface DataManagementTool
throws IOException, XMLStreamException, RbacManagerException;
void restoreUsersDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException;
+ throws IOException, XMLStreamException, UserManagerException;
void restoreKeysDatabase( KeyManager manager, File backupDirectory )
throws IOException, XMLStreamException;
diff --git a/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java b/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java
index 22c5fbda..2f8ca63f 100644
--- a/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java
+++ b/redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java
@@ -52,6 +52,7 @@ import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.Resource;
import org.apache.archiva.redback.rbac.UserAssignment;
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.io.stax.UsersManagementStaxReader;
import org.apache.archiva.redback.users.jdo.io.stax.UsersManagementStaxWriter;
@@ -97,7 +98,7 @@ public class JdoDataManagementTool
}
public void backupUserDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException
+ throws IOException, XMLStreamException, UserManagerException
{
UserDatabase database = new UserDatabase();
database.setUsers( manager.getUsers() );
@@ -232,7 +233,7 @@ public class JdoDataManagementTool
@SuppressWarnings("unchecked")
public void restoreUsersDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException
+ throws IOException, XMLStreamException, UserManagerException
{
UsersManagementStaxReader reader = new UsersManagementStaxReader();
diff --git a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
index 01342ea8..cf29e6c6 100644
--- a/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
+++ b/redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
@@ -28,6 +28,7 @@ import org.apache.archiva.redback.rbac.RBACManager;
import org.apache.archiva.redback.rbac.Role;
import org.apache.archiva.redback.rbac.UserAssignment;
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.IOUtils;
import org.apache.commons.lang.SystemUtils;
@@ -56,8 +57,8 @@ import java.util.List;
import java.util.Locale;
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
public class DataManagementTest
extends TestCase
{
@@ -67,20 +68,20 @@ public class DataManagementTest
private File targetDirectory;
@Inject
- @Named( value = "jdoFactory#users" )
+ @Named(value = "jdoFactory#users")
UserConfigurableJdoFactory jdoFactory;
@Inject
- @Named( value = "userManager#jdo" )
+ @Named(value = "userManager#jdo")
UserManager userManager;
@Inject
- @Named( value = "keyManager#jdo" )
+ @Named(value = "keyManager#jdo")
KeyManager keyManager;
@Inject
- @Named( value = "rBACManager#jdo" )
+ @Named(value = "rBACManager#jdo")
RBACManager rbacManager;
@Before
@@ -184,6 +185,7 @@ public class DataManagementTest
}
private void createUserDatabase( UserManager manager )
+ throws UserManagerException
{
User user = manager.createUser( "smcqueen", "Steve McQueen", "the cooler king" );
user.setPassword( "abc123" );
@@ -250,7 +252,7 @@ public class DataManagementTest
FileWriter fw = new FileWriter( backupFile );
- IOUtils.copy( is, fw);
+ IOUtils.copy( is, fw );
is.close();
@@ -373,6 +375,7 @@ public class DataManagementTest
}
private void assertEmpty( UserManager manager )
+ throws UserManagerException
{
List users = manager.getUsers();
assertEquals( 0, users.size() );
@@ -392,7 +395,7 @@ public class DataManagementTest
FileWriter fw = new FileWriter( backupFile );
- IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), fw);
+ IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), fw );
fw.close();
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 fb0c625d..ebd4b6ab 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
@@ -30,6 +30,7 @@ import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.system.check.EnvironmentCheck;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
@@ -49,7 +50,7 @@ import java.util.Properties;
* @author Olivier Lamy
* @since 2.0
*/
-@Service( "environmentCheck#adminAutoCreateCheck" )
+@Service("environmentCheck#adminAutoCreateCheck")
public class AdminAutoCreateCheck
implements EnvironmentCheck
{
@@ -65,11 +66,11 @@ public class AdminAutoCreateCheck
public static final String ADMIN_PASSWORD_KEY = "redback.admin.password";
@Inject
- @Named( value = "userManager#configurable" )
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
- @Named( value = "userConfiguration#default" )
+ @Named(value = "userConfiguration#default")
private UserConfiguration config;
@Inject
@@ -79,7 +80,7 @@ public class AdminAutoCreateCheck
private RoleManager roleManager;
@Inject
- @Named( value = "rBACManager#cached" )
+ @Named(value = "rBACManager#cached")
private RBACManager rbacManager;
public void validateEnvironment( List violations )
@@ -91,13 +92,15 @@ public class AdminAutoCreateCheck
{
useForceAdminCreationFile();
}
-
-
}
catch ( UserNotFoundException e )
{
useForceAdminCreationFile();
}
+ catch ( UserManagerException e )
+ {
+ useForceAdminCreationFile();
+ }
}
private void useForceAdminCreationFile()
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 21c3626d..17d891ab 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
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.integration.checks.security;
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.role.RoleManagerException;
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.role.RoleManager;
import org.apache.archiva.redback.system.SecuritySystem;
@@ -36,9 +37,8 @@ import java.util.List;
* RequiredRolesEnvironmentCheck:
*
* @author: Jesse McConnell
- *
*/
-@Service( "environmentCheck#guest-user-check" )
+@Service("environmentCheck#guest-user-check")
public class GuestUserEnvironmentCheck
implements EnvironmentCheck
{
@@ -64,15 +64,23 @@ public class GuestUserEnvironmentCheck
UserManager userManager = securitySystem.getUserManager();
UserSecurityPolicy policy = securitySystem.getPolicy();
- User guest;
+ User guest = null;
try
{
guest = userManager.getGuestUser();
}
- catch ( UserNotFoundException e )
+ catch ( UserManagerException e )
{
policy.setEnabled( false );
- guest = userManager.createGuestUser();
+ try
+ {
+ guest = userManager.createGuestUser();
+ }
+ catch ( UserManagerException ume )
+ {
+ violations.add( "unable to initialize guest user properly: " + ume.getMessage() );
+ return;
+ }
policy.setEnabled( true );
}
diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java
index 3e9b881c..27b148a9 100644
--- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java
+++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java
@@ -26,6 +26,7 @@ import org.apache.archiva.redback.rbac.UserAssignment;
import org.apache.archiva.redback.system.check.EnvironmentCheck;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -41,7 +42,6 @@ import java.util.List;
* and unlocks them on startup.
*
* @author: Jesse McConnell
- *
*/
@Service( "environmentCheck#locked-admin-check" )
public class LockedAdminEnvironmentCheck
@@ -98,6 +98,11 @@ public class LockedAdminEnvironmentCheck
{
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 )
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 c2c4b856..ed8ef614 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
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.integration.filter.authentication;
import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.policy.MustChangePasswordException;
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.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationResult;
@@ -43,7 +44,6 @@ import java.io.IOException;
* HttpAuthenticator
*
* @author Joakim Erdfelt
- *
*/
public abstract class HttpAuthenticator
{
@@ -80,6 +80,11 @@ public abstract class HttpAuthenticator
log.info( "Login attempt against unknown user: {}", ds );
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 );
}
- 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;
- }
- }
}
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 2ca4255e..0cd7a64e 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
@@ -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.policy.MustChangePasswordException;
import org.apache.archiva.redback.users.User;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.codec.binary.Base64;
import org.apache.archiva.redback.authentication.AuthenticationResult;
import org.apache.archiva.redback.authentication.TokenBasedAuthenticationDataSource;
@@ -44,14 +45,13 @@ import java.io.IOException;
* HttpDigestAuthentication methods for working with RFC 2617 HTTP Authentication.
*
* @author Joakim Erdfelt
- *
*/
@Service("httpAuthenticator#digest")
public class HttpDigestAuthentication
extends HttpAuthenticator
{
@Inject
- @Named(value="userManager#configurable")
+ @Named(value = "userManager#configurable")
private UserManager userManager;
/**
@@ -61,10 +61,8 @@ public class HttpDigestAuthentication
/**
* NOTE: Must be alphanumeric.
- *
- *
*/
- private String digestKey ="OrycteropusAfer";
+ private String digestKey = "OrycteropusAfer";
private String realm;
@@ -126,6 +124,11 @@ public class HttpDigestAuthentication
log.error( 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 );
+ }
}
/**
@@ -135,7 +138,7 @@ public class HttpDigestAuthentication
* @param response the response to use.
* @param realmName the realm name to state.
* @param exception the exception to base the message off of.
- * @throws IOException if there was a problem with the {@link HttpServletResponse#sendError(int,String)} call.
+ * @throws IOException if there was a problem with the {@link HttpServletResponse#sendError(int, String)} call.
*/
public void challenge( HttpServletRequest request, HttpServletResponse response, String realmName,
AuthenticationException exception )
@@ -194,8 +197,8 @@ public class HttpDigestAuthentication
}
else
{
- throw new IllegalStateException( "Http Digest Parameter [qop] with value of [" + digestHeader.qop
- + "] is unsupported." );
+ throw new IllegalStateException(
+ "Http Digest Parameter [qop] with value of [" + digestHeader.qop + "] is unsupported." );
}
return Digest.md5Hex( digest );
diff --git a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/model/UserCredentials.java b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/model/UserCredentials.java
index e743c439..2cde9002 100644
--- a/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/model/UserCredentials.java
+++ b/redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/model/UserCredentials.java
@@ -21,6 +21,7 @@ package org.apache.archiva.redback.integration.model;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.lang.StringUtils;
@@ -54,6 +55,7 @@ public abstract class UserCredentials
private String timestampLastPasswordChange;
public User createUser( UserManager um )
+ throws UserManagerException
{
User user = um.createUser( username, fullName, email );
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLoginService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLoginService.java
index 03940bd5..0c1626ed 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLoginService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLoginService.java
@@ -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.system.SecuritySession;
import org.apache.archiva.redback.system.SecuritySystem;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -48,6 +49,7 @@ import javax.servlet.http.HttpSession;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Calendar;
import java.util.List;
import java.util.Map;
@@ -178,6 +180,14 @@ public class DefaultLoginService
{
return buildRestUser( e.getUser() );
}
+ catch ( UserManagerException e )
+ {
+ log.info( "UserManagerException: {}", e.getMessage() );
+ List errorMessages =
+ Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+ throw new RedbackServiceException( errorMessages );
+ }
+
}
public Boolean isLogged()
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultPasswordService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultPasswordService.java
index 79cd4af7..e112de9a 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultPasswordService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultPasswordService.java
@@ -22,6 +22,7 @@ import org.apache.archiva.redback.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.PasswordRuleViolationException;
import org.apache.archiva.redback.policy.PasswordRuleViolations;
import org.apache.archiva.redback.users.User;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.commons.lang.StringUtils;
import org.apache.archiva.redback.keys.AuthenticationKey;
import org.apache.archiva.redback.keys.KeyManagerException;
@@ -42,13 +43,14 @@ import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
* @author Olivier Lamy
* @since 1.4
*/
-@Service( "passwordService#rest" )
+@Service("passwordService#rest")
public class DefaultPasswordService
implements PasswordService
{
@@ -66,7 +68,7 @@ public class DefaultPasswordService
@Inject
public DefaultPasswordService( SecuritySystem securitySystem,
- @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator,
+ @Named("httpAuthenticator#basic") HttpAuthenticator httpAuthenticator,
PasswordValidator passwordValidator )
{
this.securitySystem = securitySystem;
@@ -74,12 +76,12 @@ public class DefaultPasswordService
this.passwordValidator = passwordValidator;
}
- public org.apache.archiva.redback.rest.api.model.User changePasswordWithKey( String password, String passwordConfirmation,
- String key )
+ public org.apache.archiva.redback.rest.api.model.User changePasswordWithKey( String password,
+ String passwordConfirmation,
+ String key )
throws RedbackServiceException
{
-
//RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
String principal = null;
@@ -130,6 +132,13 @@ public class DefaultPasswordService
errorMessages.add( errorMessage );
throw new RedbackServiceException( errorMessages );
}
+ catch ( UserManagerException e )
+ {
+ log.info( "UserManagerException: {}", e.getMessage() );
+ List errorMessages =
+ Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+ throw new RedbackServiceException( errorMessages );
+ }
catch ( PasswordRuleViolationException e )
{
PasswordRuleViolations violations = e.getViolations();
@@ -147,7 +156,7 @@ public class DefaultPasswordService
}
public org.apache.archiva.redback.rest.api.model.User changePassword( String userName, String previousPassword,
- String password, String passwordConfirmation )
+ String password, String passwordConfirmation )
throws RedbackServiceException
{
if ( StringUtils.isEmpty( userName ) )
@@ -203,6 +212,13 @@ public class DefaultPasswordService
throw new RedbackServiceException( new ErrorMessage( "user.not.found" ),
Response.Status.BAD_REQUEST.getStatusCode() );
}
+ catch ( UserManagerException e )
+ {
+ log.info( "UserManagerException: {}", e.getMessage() );
+ List errorMessages =
+ Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+ throw new RedbackServiceException( errorMessages );
+ }
}
}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java
index 28496bec..643d2198 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java
@@ -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.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.lang.StringUtils;
import org.apache.archiva.redback.integration.model.AdminEditUserCredentials;
@@ -62,7 +63,7 @@ import java.util.Set;
* @author Olivier Lamy
* @since 1.3
*/
-@Service( "roleManagementService#rest" )
+@Service("roleManagementService#rest")
public class DefaultRoleManagementService
implements RoleManagementService
{
@@ -77,8 +78,8 @@ public class DefaultRoleManagementService
@Inject
public DefaultRoleManagementService( RoleManager roleManager,
- @Named( value = "rBACManager#cached" ) RBACManager rbacManager,
- @Named( value = "userManager#cached" ) UserManager userManager )
+ @Named(value = "rBACManager#cached") RBACManager rbacManager,
+ @Named(value = "userManager#cached") UserManager userManager )
{
this.roleManager = roleManager;
this.rbacManager = rbacManager;
@@ -404,7 +405,8 @@ public class DefaultRoleManagementService
try
{
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 )
{
@@ -418,8 +420,8 @@ public class DefaultRoleManagementService
new ArrayList();
for ( User u : userManager.getUsers() )
{
- org.apache.archiva.redback.rest.api.model.User
- user = new org.apache.archiva.redback.rest.api.model.User( u );
+ org.apache.archiva.redback.rest.api.model.User user =
+ new org.apache.archiva.redback.rest.api.model.User( u );
if ( role.getParentsRolesUsers().contains( user ) )
{
continue;
@@ -439,6 +441,10 @@ public class DefaultRoleManagementService
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
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() )
{
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
{
+
+ if ( !userManager.userExists( username ) )
+ {
+ log.error( "user {} not exits", username );
+ throw new RedbackServiceException(
+ new ErrorMessage( "user.not.exists", new String[]{ username } ) );
+ }
+
UserAssignment assignment;
if ( rbacManager.userAssignmentExists( username ) )
@@ -493,19 +502,26 @@ public class DefaultRoleManagementService
throw new RedbackServiceException(
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() )
{
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
{
+
+ if ( !userManager.userExists( username ) )
+ {
+ log.error( "user {} not exits", username );
+ throw new RedbackServiceException(
+ new ErrorMessage( "user.not.exists", new String[]{ username } ) );
+ }
+
UserAssignment assignment;
if ( rbacManager.userAssignmentExists( username ) )
@@ -527,6 +543,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException(
new ErrorMessage( "error.unassign.role.user", new String[]{ role.getName(), username } ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
return Boolean.TRUE;
@@ -541,13 +561,14 @@ public class DefaultRoleManagementService
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
{
+ if ( !userManager.userExists( username ) )
+ {
+ throw new RedbackServiceException(
+ new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
+ }
+
User u = userManager.findUser( username );
if ( u == null )
@@ -562,6 +583,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
try
{
// check first if role assignments for user exist
@@ -597,18 +622,19 @@ public class DefaultRoleManagementService
applicationRoles.setRoleTemplates( toRoleTemplates( modelApplication.getTemplates() ) );
// cleanup app roles remove roles coming from templates
-
+
List appRoleNames = new ArrayList( appRoles.size() );
-
- for (String appRoleName : applicationRoles.getGlobalRoles())
+
+ for ( String appRoleName : applicationRoles.getGlobalRoles() )
{
- if (!roleFromTemplate( appRoleName, modelApplication.getTemplates() )){
+ if ( !roleFromTemplate( appRoleName, modelApplication.getTemplates() ) )
+ {
appRoleNames.add( appRoleName );
}
}
-
+
applicationRoles.setGlobalRoles( appRoleNames );
-
+
applicationRolesList.add( applicationRoles );
}
@@ -635,13 +661,15 @@ public class DefaultRoleManagementService
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
{
+
+ if ( !userManager.userExists( username ) )
+ {
+ throw new RedbackServiceException(
+ new ErrorMessage( "user.does.not.exist", new String[]{ username } ) );
+ }
+
User u = userManager.findUser( username );
if ( u == null )
@@ -655,6 +683,10 @@ public class DefaultRoleManagementService
throw new RedbackServiceException(
new ErrorMessage( "user.does.not.exist", new String[]{ username, e.getMessage() } ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
try
{
@@ -692,7 +724,7 @@ public class DefaultRoleManagementService
//----------------------------------------------------------------
private org.apache.archiva.redback.rbac.Role isInList( String roleName,
- Collection roles )
+ Collection roles )
{
for ( org.apache.archiva.redback.rbac.Role role : roles )
{
@@ -705,8 +737,8 @@ public class DefaultRoleManagementService
}
private Collection filterApplicationRoles( ModelApplication application,
- List allRoles,
- List applicationTemplates )
+ List allRoles,
+ List applicationTemplates )
{
Set applicationRoles =
new HashSet();
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 90fa8f45..35d1078e 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
@@ -55,6 +55,7 @@ import org.apache.archiva.redback.role.RoleManager;
import org.apache.archiva.redback.role.RoleManagerException;
import org.apache.archiva.redback.system.SecuritySystem;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -159,6 +160,10 @@ public class DefaultUserService
//ignore we just want to prevent non human readable error message from backend :-)
log.debug( "user {} not exists", user.getUsername() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
// data validation
if ( StringUtils.isEmpty( user.getUsername() ) )
@@ -176,29 +181,31 @@ public class DefaultUserService
throw new RedbackServiceException( new ErrorMessage( "email cannot be empty" ) );
}
- org.apache.archiva.redback.users.User u =
- userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
- u.setPassword( user.getPassword() );
- u.setLocked( user.isLocked() );
- u.setPasswordChangeRequired( user.isPasswordChangeRequired() );
- u.setPermanent( user.isPermanent() );
- u.setValidated( user.isValidated() );
- u = userManager.addUser( u );
- if ( !user.isPasswordChangeRequired() )
- {
- u.setPasswordChangeRequired( false );
- try
- {
- u = userManager.updateUser( u );
- log.debug( "user {} created", u.getUsername() );
- }
- catch ( UserNotFoundException e )
- {
- throw new RedbackServiceException( e.getMessage() );
- }
- }
try
{
+
+ org.apache.archiva.redback.users.User u =
+ userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
+ u.setPassword( user.getPassword() );
+ u.setLocked( user.isLocked() );
+ u.setPasswordChangeRequired( user.isPasswordChangeRequired() );
+ u.setPermanent( user.isPermanent() );
+ u.setValidated( user.isValidated() );
+ u = userManager.addUser( u );
+ if ( !user.isPasswordChangeRequired() )
+ {
+ u.setPasswordChangeRequired( false );
+ try
+ {
+ u = userManager.updateUser( u );
+ log.debug( "user {} created", u.getUsername() );
+ }
+ catch ( UserNotFoundException e )
+ {
+ throw new RedbackServiceException( e.getMessage() );
+ }
+ }
+
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
}
catch ( RoleManagerException rpe )
@@ -206,6 +213,10 @@ public class DefaultUserService
log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
return Boolean.TRUE;
}
@@ -238,6 +249,10 @@ public class DefaultUserService
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
finally
{
removeFromCache( username );
@@ -257,20 +272,31 @@ public class DefaultUserService
{
return null;
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public List getUsers()
throws RedbackServiceException
{
- List users = userManager.getUsers();
- List simpleUsers = new ArrayList( users.size() );
-
- for ( org.apache.archiva.redback.users.User user : users )
+ try
{
- simpleUsers.add( getSimpleUser( user ) );
- }
+ List users = userManager.getUsers();
+ List simpleUsers = new ArrayList( users.size() );
- return simpleUsers;
+ for ( org.apache.archiva.redback.users.User user : users )
+ {
+ simpleUsers.add( getSimpleUser( user ) );
+ }
+
+ return simpleUsers;
+ }
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public Boolean updateMe( User user )
@@ -322,6 +348,10 @@ public class DefaultUserService
throw new RedbackServiceException( new ErrorMessage( "user not found" ),
Response.Status.BAD_REQUEST.getStatusCode() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
// only 3 fields to update
realUser.setFullName( user.getFullName() );
realUser.setEmail( user.getEmail() );
@@ -359,6 +389,10 @@ public class DefaultUserService
{
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public int removeFromCache( String userName )
@@ -433,6 +467,10 @@ public class DefaultUserService
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
finally
{
@@ -466,26 +504,29 @@ public class DefaultUserService
return Boolean.FALSE;
}
- org.apache.archiva.redback.users.User user =
- userManager.createUser( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(),
- adminUser.getEmail() );
- user.setPassword( adminUser.getPassword() );
-
- user.setLocked( false );
- user.setPasswordChangeRequired( false );
- user.setPermanent( true );
- user.setValidated( true );
-
- userManager.addUser( user );
-
try
{
+ org.apache.archiva.redback.users.User user =
+ userManager.createUser( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminUser.getFullName(),
+ adminUser.getEmail() );
+ user.setPassword( adminUser.getPassword() );
+
+ user.setLocked( false );
+ user.setPasswordChangeRequired( false );
+ user.setPermanent( true );
+ user.setValidated( true );
+
+ userManager.addUser( user );
roleManager.assignRole( "system-administrator", user.getUsername() );
}
catch ( RoleManagerException e )
{
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
return Boolean.TRUE;
}
@@ -501,6 +542,10 @@ public class DefaultUserService
{
// ignore
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
return Boolean.FALSE;
}
@@ -543,6 +588,10 @@ public class DefaultUserService
log.info( "Unable to issue password reset.", e );
throw new RedbackServiceException( new ErrorMessage( "password.reset.email.generation.failure" ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
return Boolean.TRUE;
}
@@ -570,22 +619,24 @@ public class DefaultUserService
validateCredentialsStrict( user );
}
- // NOTE: Do not perform Password Rules Validation Here.
-
- if ( userManager.userExists( user.getUsername() ) )
- {
- throw new RedbackServiceException(
- new ErrorMessage( "user.already.exists", new String[]{ user.getUsername() } ) );
- }
-
- org.apache.archiva.redback.users.User u =
- userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
- u.setPassword( user.getPassword() );
- u.setValidated( false );
- u.setLocked( false );
+ org.apache.archiva.redback.users.User u = null;
try
{
+
+ // NOTE: Do not perform Password Rules Validation Here.
+
+ if ( userManager.userExists( user.getUsername() ) )
+ {
+ throw new RedbackServiceException(
+ new ErrorMessage( "user.already.exists", new String[]{ user.getUsername() } ) );
+ }
+
+ u = userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
+ u.setPassword( user.getPassword() );
+ u.setValidated( false );
+ u.setLocked( false );
+
roleManager.assignRole( RedbackRoleConstants.REGISTERED_USER_ROLE_ID, u.getUsername() );
}
catch ( RoleManagerException rpe )
@@ -593,6 +644,10 @@ public class DefaultUserService
log.error( "RoleProfile Error: " + rpe.getMessage(), rpe );
throw new RedbackServiceException( new ErrorMessage( "assign.role.failure", null ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
if ( emailValidationRequired )
{
@@ -624,6 +679,10 @@ public class DefaultUserService
log.error( "Unable to register a new user.", e );
throw new RedbackServiceException( new ErrorMessage( "cannot.register.user", null ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
finally
{
securityPolicy.setEnabled( true );
@@ -631,8 +690,15 @@ public class DefaultUserService
}
else
{
- userManager.addUser( u );
- return new RegistrationKey( "-1" );
+ try
+ {
+ userManager.addUser( u );
+ return new RegistrationKey( "-1" );
+ }
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
// FIXME log this event
@@ -702,6 +768,10 @@ public class DefaultUserService
{
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public Collection getCurrentUserPermissions()
@@ -845,17 +915,23 @@ public class DefaultUserService
throws RedbackServiceException
{
validateCredentialsLoose( user );
-
- org.apache.archiva.redback.users.User tmpuser =
- userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
-
- user.setPassword( user.getPassword() );
-
- securitySystem.getPolicy().validatePassword( tmpuser );
-
- if ( ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getPassword() ) ) )
+ try
{
- throw new RedbackServiceException( new ErrorMessage( "password.required", null ) );
+ org.apache.archiva.redback.users.User tmpuser =
+ userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
+
+ user.setPassword( user.getPassword() );
+
+ securitySystem.getPolicy().validatePassword( tmpuser );
+
+ if ( ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getPassword() ) ) )
+ {
+ throw new RedbackServiceException( new ErrorMessage( "password.required", null ) );
+ }
+ }
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
index 57578955..5ab5a545 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
@@ -32,6 +32,7 @@ import org.apache.archiva.redback.rest.services.RedbackRequestInformation;
import org.apache.archiva.redback.system.SecuritySession;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.cxf.jaxrs.ext.RequestHandler;
import org.apache.cxf.jaxrs.model.ClassResourceInfo;
@@ -54,17 +55,17 @@ import javax.ws.rs.core.Response;
* @author Olivier Lamy
* @since 1.3
*/
-@Service ("authenticationInterceptor#rest")
+@Service("authenticationInterceptor#rest")
public class AuthenticationInterceptor
extends AbstractInterceptor
implements RequestHandler
{
@Inject
- @Named (value = "userManager#configurable")
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
- @Named (value = "httpAuthenticator#basic")
+ @Named(value = "httpAuthenticator#basic")
private HttpBasicAuthentication httpAuthenticator;
private Logger log = LoggerFactory.getLogger( getClass() );
@@ -168,5 +169,10 @@ public class AuthenticationInterceptor
log.debug( "failed to authenticate for path {}", message.get( Message.REQUEST_URI ) );
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();
+ }
}
}
diff --git a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/utils/PasswordValidator.java b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/utils/PasswordValidator.java
index 454d0508..b0510c9d 100644
--- a/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/utils/PasswordValidator.java
+++ b/redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/utils/PasswordValidator.java
@@ -20,6 +20,7 @@ package org.apache.archiva.redback.rest.services.utils;
import org.apache.archiva.redback.policy.PasswordRuleViolations;
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.policy.PasswordEncoder;
import org.apache.archiva.redback.policy.PasswordRuleViolationException;
@@ -32,13 +33,14 @@ import org.springframework.stereotype.Service;
import javax.inject.Inject;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
* @author Olivier Lamy
* @since 1.4
*/
-@Service( "passwordValidator#rest" )
+@Service("passwordValidator#rest")
public class PasswordValidator
{
@@ -48,7 +50,6 @@ public class PasswordValidator
private SecuritySystem securitySystem;
/**
- *
* @param password
* @param principal
* @return encoded password
@@ -98,6 +99,13 @@ public class PasswordValidator
}
throw new RedbackServiceException( errorMessages );
}
+ catch ( UserManagerException e )
+ {
+ log.info( "UserManagerException: {}", e.getMessage() );
+ List errorMessages =
+ Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+ throw new RedbackServiceException( errorMessages );
+ }
}
}
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 66cb5583..f3d549f3 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
@@ -32,6 +32,7 @@ import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.MustChangePasswordException;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,16 +45,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()
@@ -107,6 +108,11 @@ public class KeyStoreAuthenticator
log.warn( "Login for user {} failed. user not found.", source.getPrincipal() );
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 )
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 d14a2d4e..eefca1a8 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
@@ -32,6 +32,7 @@ import org.apache.archiva.redback.rbac.RbacManagerException;
import org.apache.archiva.redback.rbac.RbacObjectNotFoundException;
import org.apache.archiva.redback.users.User;
import org.apache.archiva.redback.users.UserManager;
+import org.apache.archiva.redback.users.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,18 +48,18 @@ import java.util.Map;
*
* @author Jesse McConnell
*/
-@Service ( "authorizer#rbac" )
+@Service("authorizer#rbac")
public class RbacAuthorizer
implements Authorizer
{
private Logger log = LoggerFactory.getLogger( getClass() );
@Inject
- @Named ( value = "rBACManager#cached" )
+ @Named(value = "rBACManager#cached")
private RBACManager manager;
@Inject
- @Named ( value = "userManager#configurable" )
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
@@ -115,8 +116,7 @@ public class RbacAuthorizer
if ( !guest.isLocked() )
{
// Set permissions = manager.getAssignedPermissions( principal.toString(), operation );
- Map> permissionMap =
- manager.getAssignedPermissionMap( guest.getUsername() );
+ Map> permissionMap = manager.getAssignedPermissionMap( guest.getUsername() );
if ( permissionMap.keySet().contains( operation.toString() ) )
{
@@ -151,6 +151,10 @@ public class RbacAuthorizer
{
return new AuthorizationResult( false, null, rme );
}
+ catch ( UserManagerException e )
+ {
+ return new AuthorizationResult( false, null, e );
+ }
}
public RBACManager getManager()
diff --git a/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/evaluator/DefaultPermissionEvaluator.java b/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/evaluator/DefaultPermissionEvaluator.java
index 6e694918..0db1f4f8 100644
--- a/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/evaluator/DefaultPermissionEvaluator.java
+++ b/redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/evaluator/DefaultPermissionEvaluator.java
@@ -21,6 +21,7 @@ package org.apache.archiva.redback.authorization.rbac.evaluator;
import org.apache.archiva.redback.rbac.Resource;
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.rbac.Permission;
import org.springframework.stereotype.Service;
@@ -35,14 +36,13 @@ import javax.inject.Named;
* of the person making the authorization check
*
* @author Jesse McConnell
- *
*/
@Service("permissionEvaluator")
public class DefaultPermissionEvaluator
implements PermissionEvaluator
{
@Inject
- @Named(value="userManager#configurable")
+ @Named(value = "userManager#configurable")
private UserManager userManager;
public boolean evaluate( Permission permission, Object operation, Object resource, Object principal )
@@ -61,9 +61,13 @@ public class DefaultPermissionEvaluator
{
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 );
}
}
}
@@ -82,7 +86,7 @@ public class DefaultPermissionEvaluator
{
return true;
}
-
+
// check if the resource identifier of the permission matches the resource we are checking against
// if it does then return true
if ( permissionResource.equals( resource.toString() ) )
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 29112a78..58171a8f 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
@@ -24,6 +24,7 @@ import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.User;
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.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationException;
@@ -45,9 +46,8 @@ import javax.inject.Named;
* DefaultSecuritySystem:
*
* @author: Jesse McConnell
- *
*/
-@Service( "securitySystem" )
+@Service("securitySystem")
public class DefaultSecuritySystem
implements SecuritySystem
{
@@ -57,15 +57,15 @@ public class DefaultSecuritySystem
private AuthenticationManager authnManager;
@Inject
- @Named( value = "authorizer#rbac" )
+ @Named(value = "authorizer#rbac")
private Authorizer authorizer;
@Inject
- @Named( value = "userManager#configurable" )
+ @Named(value = "userManager#configurable")
private UserManager userManager;
@Inject
- @Named( value = "keyManager#cached" )
+ @Named(value = "keyManager#cached")
private KeyManager keyManager;
@Inject
@@ -92,10 +92,12 @@ public class DefaultSecuritySystem
* @throws UserNotFoundException
* @throws MustChangePasswordException
* @throws org.apache.archiva.redback.policy.AccountLockedException
+ *
* @throws MustChangePasswordException
*/
public SecuritySession authenticate( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException
+ throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
+ UserManagerException
{
// Perform Authentication.
AuthenticationResult result = authnManager.authenticate( source );
@@ -105,7 +107,7 @@ public class DefaultSecuritySystem
// Process Results.
if ( result.isAuthenticated() )
{
- log.debug( "User '{}' authenticated.", result.getPrincipal());
+ log.debug( "User '{}' authenticated.", result.getPrincipal() );
User user = userManager.findUser( result.getPrincipal() );
if ( user != null )
{
@@ -127,7 +129,8 @@ public class DefaultSecuritySystem
}
public boolean isAuthenticated( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException
+ throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
+ UserManagerException
{
return authenticate( source ).getAuthenticationResult().isAuthenticated();
}
diff --git a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
index 8b199faf..66f775e7 100644
--- a/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
+++ b/redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
@@ -22,6 +22,7 @@ package org.apache.archiva.redback.system;
import org.apache.archiva.redback.policy.AccountLockedException;
import org.apache.archiva.redback.policy.MustChangePasswordException;
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.authentication.AuthenticationDataSource;
import org.apache.archiva.redback.authentication.AuthenticationException;
@@ -34,7 +35,6 @@ import org.apache.archiva.redback.users.UserManager;
* SecuritySystem:
*
* @author: Jesse McConnell
- *
*/
public interface SecuritySystem
{
@@ -44,10 +44,12 @@ public interface SecuritySystem
// ----------------------------------------------------------------------------
SecuritySession authenticate( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException;
+ throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
+ UserManagerException;
boolean isAuthenticated( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException;
+ throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
+ UserManagerException;
// ----------------------------------------------------------------------------
// Authorization
@@ -61,6 +63,7 @@ public interface SecuritySystem
/**
* return AuthorizationResult without changing authorization
+ *
* @param session
* @param permission
* @param resource
@@ -78,22 +81,22 @@ public interface SecuritySystem
// ----------------------------------------------------------------------------
UserManager getUserManager();
-
+
// ----------------------------------------------------------------------------
// Key Management
// ----------------------------------------------------------------------------
-
+
KeyManager getKeyManager();
// ----------------------------------------------------------------------------
// Policy Management
// ----------------------------------------------------------------------------
-
+
UserSecurityPolicy getPolicy();
/**
- * @since 2.1
* @return is it possible to modify user datas (some userManager cannot i.e ldap)
+ * @since 2.1
*/
boolean userManagerReadOnly();
}
diff --git a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/AbstractUserManager.java b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/AbstractUserManager.java
index fcb903df..e98dae97 100644
--- a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/AbstractUserManager.java
+++ b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/AbstractUserManager.java
@@ -31,13 +31,12 @@ import javax.annotation.PostConstruct;
* AbstractUserManager
*
* @author Joakim Erdfelt
- *
*/
public abstract class AbstractUserManager
implements UserManager
{
protected Logger log = LoggerFactory.getLogger( getClass() );
-
+
private List listeners = new ArrayList();
public void addUserManagerListener( UserManagerListener listener )
@@ -114,12 +113,13 @@ public abstract class AbstractUserManager
}
public User getGuestUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return findUser( GUEST_USERNAME );
}
public User createGuestUser()
+ throws UserManagerException
{
try
{
diff --git a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManager.java b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManager.java
index e610f047..d9a1a0c4 100644
--- a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManager.java
+++ b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManager.java
@@ -29,7 +29,7 @@ import java.util.List;
*/
public interface UserManager
{
-
+
static final String GUEST_USERNAME = "guest";
/**
@@ -72,15 +72,19 @@ public interface UserManager
* @param fullName the full name for this user.
* @param emailAddress the email address for this user.
* @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.
*
* @return The guest user
+ * @throws UserManagerException
*/
- User createGuestUser();
+ User createGuestUser()
+ throws UserManagerException;
/**
* 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.
*
* @return the List of {@link User} Objects.
+ * @throws UserManagerException
*/
- List getUsers();
+ List getUsers()
+ throws UserManagerException;
- List getUsers( boolean orderAscending );
+ List getUsers( boolean orderAscending )
+ throws UserManagerException;
/**
* Add a User.
*
* @param user the user to add.
* @return the user that was just added.
+ * @throws UserManagerException
*/
- User addUser( User user );
+ User addUser( User user )
+ throws UserManagerException;
/**
* Update a User.
@@ -115,7 +124,7 @@ public interface UserManager
* @throws UserNotFoundException if the user was not found to update.
*/
User updateUser( User user )
- throws UserNotFoundException;
+ throws UserNotFoundException, UserManagerException;
/**
* Find a User using a User name.
@@ -125,7 +134,7 @@ public interface UserManager
* @throws UserNotFoundException if the user was not found.
*/
User findUser( String username )
- throws UserNotFoundException;
+ throws UserNotFoundException, UserManagerException;
/**
* Get the guest user.
@@ -133,13 +142,16 @@ public interface UserManager
* @return the guest user.
*/
User getGuestUser()
- throws UserNotFoundException;
+ throws UserNotFoundException, UserManagerException;
- List findUsersByUsernameKey( String usernameKey, boolean orderAscending );
+ List findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+ throws UserManagerException;
- List findUsersByFullNameKey( String fullNameKey, boolean orderAscending );
+ List findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ throws UserManagerException;
- List findUsersByEmailKey( String emailKey, boolean orderAscending );
+ List findUsersByEmailKey( String emailKey, boolean orderAscending )
+ throws UserManagerException;
/**
* Find users matching properties, ordering and range as specified by the
@@ -148,7 +160,8 @@ public interface UserManager
* @param query the query.
* @return a List of {@link User} objects.
*/
- List findUsersByQuery( UserQuery query );
+ List findUsersByQuery( UserQuery query )
+ throws UserManagerException;
/**
* true if the user exists, false if it doesn't
@@ -156,7 +169,8 @@ public interface UserManager
* @param principal
* @return true, if user exists
*/
- boolean userExists( String principal );
+ boolean userExists( String principal )
+ throws UserManagerException;
/**
* Delete a user using the username.
@@ -165,7 +179,7 @@ public interface UserManager
* @throws UserNotFoundException the user was not found.
*/
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
@@ -173,30 +187,32 @@ public interface UserManager
*
* @param user the user to add
*/
- void addUserUnchecked( User user );
+ void addUserUnchecked( User user )
+ throws UserManagerException;
void eraseDatabase();
User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException;
+ throws UserNotFoundException, UserManagerException;
/**
* consumer of user manager can use it to reload various configuration
* with the configurable implementation is possible to change dynamically the real implementation used.
+ *
* @since 2.1
*/
void initialize();
/**
- * @since 2.1
* @return true if this implementation is a final one and not a wrapper (configurable, cached)
+ * @since 2.1
*/
boolean isFinalImplementation();
/**
- * @since 2.1
* @return a key to be able to customize label in UI
+ * @since 2.1
*/
String getDescriptionKey();
}
diff --git a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManagerException.java b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManagerException.java
index 84f95fd4..aa0b0dc4 100644
--- a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManagerException.java
+++ b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManagerException.java
@@ -26,7 +26,7 @@ package org.apache.archiva.redback.users;
*
*/
public class UserManagerException
- extends RuntimeException
+ extends Exception
{
public UserManagerException()
diff --git a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserNotFoundException.java b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserNotFoundException.java
index ab8006ad..ba319dba 100644
--- a/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserNotFoundException.java
+++ b/redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserNotFoundException.java
@@ -23,7 +23,7 @@ package org.apache.archiva.redback.users;
* @author Jason van Zyl
*/
public class UserNotFoundException
- extends Exception
+ extends UserManagerException
{
public UserNotFoundException( String string )
{
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 7cebc1f8..82cfcb8a 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
@@ -21,6 +21,7 @@ package org.apache.archiva.redback.users.cached;
import org.apache.archiva.redback.components.cache.Cache;
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.UserNotFoundException;
import org.apache.archiva.redback.users.UserQuery;
@@ -37,7 +38,6 @@ import java.util.List;
* CachedUserManager
*
* @author Joakim Erdfelt
- *
*/
@Service( "userManager#cached" )
public class CachedUserManager
@@ -60,11 +60,13 @@ public class CachedUserManager
}
public User createGuestUser()
+ throws UserManagerException
{
return userImpl.createGuestUser();
}
public User addUser( User user )
+ throws UserManagerException
{
if ( user != null )
{
@@ -79,6 +81,7 @@ public class CachedUserManager
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
if ( user != null )
{
@@ -88,13 +91,14 @@ public class CachedUserManager
}
public User createUser( String username, String fullName, String emailAddress )
+ throws UserManagerException
{
usersCache.remove( username );
return this.userImpl.createUser( username, fullName, emailAddress );
}
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
usersCache.remove( username );
this.userImpl.deleteUser( username );
@@ -113,7 +117,7 @@ public class CachedUserManager
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( GUEST_USERNAME.equals( username ) )
{
@@ -134,7 +138,7 @@ public class CachedUserManager
}
public User getGuestUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
Object el = usersCache.get( GUEST_USERNAME );
if ( el != null )
@@ -156,24 +160,28 @@ public class CachedUserManager
public List findUsersByQuery( UserQuery query )
+ throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByQuery(UserQuery)" );
return this.userImpl.findUsersByQuery( query );
}
public List findUsersByEmailKey( String emailKey, boolean orderAscending )
+ throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByEmailKey(String, boolean)" );
return this.userImpl.findUsersByEmailKey( emailKey, orderAscending );
}
public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByFullNameKey(String, boolean)" );
return this.userImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
}
public List findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+ throws UserManagerException
{
log.debug( "NOT CACHED - .findUsersByUsernameKey(String, boolean)" );
return this.userImpl.findUsersByUsernameKey( usernameKey, orderAscending );
@@ -185,12 +193,14 @@ public class CachedUserManager
}
public List getUsers()
+ throws UserManagerException
{
log.debug( "NOT CACHED - .getUsers()" );
return this.userImpl.getUsers();
}
public List getUsers( boolean orderAscending )
+ throws UserManagerException
{
log.debug( "NOT CACHED - .getUsers(boolean)" );
return this.userImpl.getUsers( orderAscending );
@@ -202,13 +212,13 @@ public class CachedUserManager
}
public User updateUser( User user )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
public User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( user != null )
{
@@ -218,6 +228,7 @@ public class CachedUserManager
}
public boolean userExists( String userName )
+ throws UserManagerException
{
if ( usersCache.hasKey( userName ) )
{
diff --git a/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java b/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java
index 848aba37..e6f42429 100644
--- a/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java
+++ b/redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java
@@ -21,6 +21,7 @@ import org.apache.archiva.redback.configuration.UserConfigurationKeys;
import org.apache.archiva.redback.users.AbstractUserManager;
import org.apache.archiva.redback.users.User;
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.UserQuery;
import org.springframework.context.ApplicationContext;
@@ -66,16 +67,19 @@ public class ConfigurableUserManager
}
public User addUser( User user )
+ throws UserManagerException
{
return userManagerImpl.addUser( user );
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
userManagerImpl.addUserUnchecked( user );
}
public User createUser( String username, String fullName, String emailAddress )
+ throws UserManagerException
{
return userManagerImpl.createUser( username, fullName, emailAddress );
}
@@ -86,7 +90,7 @@ public class ConfigurableUserManager
}
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
userManagerImpl.deleteUser( username );
}
@@ -97,34 +101,38 @@ public class ConfigurableUserManager
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserManagerException, UserNotFoundException
{
return userManagerImpl.findUser( username );
}
@Override
public User getGuestUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return userManagerImpl.getGuestUser();
}
public List findUsersByEmailKey( String emailKey, boolean orderAscending )
+ throws UserManagerException
{
return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
}
public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ throws UserManagerException
{
return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
}
public List findUsersByQuery( UserQuery query )
+ throws UserManagerException
{
return userManagerImpl.findUsersByQuery( query );
}
public List findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+ throws UserManagerException
{
return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
}
@@ -135,11 +143,13 @@ public class ConfigurableUserManager
}
public List getUsers()
+ throws UserManagerException
{
return userManagerImpl.getUsers();
}
public List getUsers( boolean orderAscending )
+ throws UserManagerException
{
return userManagerImpl.getUsers( orderAscending );
}
@@ -150,18 +160,19 @@ public class ConfigurableUserManager
}
public User updateUser( User user )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
public User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return userManagerImpl.updateUser( user, passwordChangeRequired );
}
public boolean userExists( String userName )
+ throws UserManagerException
{
return userManagerImpl.userExists( userName );
}
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java
index 8a68c083..75a3088e 100644
--- a/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java
+++ b/redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java
@@ -50,12 +50,12 @@ import java.util.List;
*
* @author Joakim Erdfelt
*/
-@Service ("userManager#jdo")
+@Service("userManager#jdo")
public class JdoUserManager
extends AbstractUserManager
{
@Inject
- @Named (value = "jdoFactory#users")
+ @Named(value = "jdoFactory#users")
private JdoFactory jdoFactory;
@Inject
@@ -104,7 +104,7 @@ public class JdoUserManager
return getAllObjectsDetached( ordering );
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
private List getAllObjectsDetached( String ordering )
{
return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null );
@@ -125,7 +125,7 @@ public class JdoUserManager
return findUsers( "email", emailKey, orderAscending );
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
public List findUsersByQuery( UserQuery userQuery )
{
JdoUserQuery uq = (JdoUserQuery) userQuery;
@@ -169,7 +169,7 @@ public class JdoUserManager
}
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
private List findUsers( String searchField, String searchKey, boolean ascendingUsername )
{
PersistenceManager pm = getPersistenceManager();
@@ -209,6 +209,7 @@ public class JdoUserManager
}
public User addUser( User user )
+ throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
@@ -243,6 +244,7 @@ public class JdoUserManager
}
public void deleteUser( String username )
+ throws UserManagerException
{
try
{
@@ -264,6 +266,7 @@ public class JdoUserManager
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
@@ -287,7 +290,7 @@ public class JdoUserManager
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( StringUtils.isEmpty( username ) )
{
@@ -298,6 +301,7 @@ public class JdoUserManager
}
public boolean userExists( String principal )
+ throws UserManagerException
{
try
{
@@ -311,13 +315,13 @@ public class JdoUserManager
}
public User updateUser( User user )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
public User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
@@ -385,6 +389,7 @@ public class JdoUserManager
}
private Object removeObject( Object o )
+ throws UserManagerException
{
if ( o == null )
{
diff --git a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java b/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java
index bc11f245..38167e3b 100644
--- a/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java
+++ b/redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java
@@ -21,6 +21,7 @@ package org.apache.archiva.redback.users.jdo;
import org.apache.archiva.redback.components.jdo.DefaultConfigurableJdoFactory;
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.jpox.AbstractPersistenceManagerFactory;
import org.jpox.SchemaTool;
@@ -38,17 +39,16 @@ import java.util.Properties;
* JdoUserManagerTest
*
* @author Joakim Erdfelt
- *
*/
public class JdoUserManagerTest
extends AbstractUserManagerTestCase
{
@Inject
- @Named( value = "jdoFactory#users" )
+ @Named(value = "jdoFactory#users")
DefaultConfigurableJdoFactory jdoFactory;
@Inject
- @Named( value = "userManager#jdo" )
+ @Named(value = "userManager#jdo")
JdoUserManager jdoUserManager;
private StoreManagerDebug storeManager;
@@ -106,12 +106,10 @@ public class JdoUserManagerTest
}
protected void assertCleanUserManager()
+ throws UserManagerException
{
// database cleanup
- ( (JdoUserManager) getUserManager()).eraseDatabase();
-
-
-
+ ( (JdoUserManager) getUserManager() ).eraseDatabase();
super.assertCleanUserManager();
}
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 db66e7ba..fc711901 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
@@ -74,6 +74,7 @@ public class LdapUserManager
}
public User addUser( User user )
+ throws UserManagerException
{
try
{
@@ -86,6 +87,7 @@ public class LdapUserManager
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
try
{
@@ -144,7 +146,7 @@ public class LdapUserManager
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( username != null )
{
@@ -177,7 +179,7 @@ public class LdapUserManager
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( username == null )
{
@@ -248,6 +250,7 @@ public class LdapUserManager
}
public List findUsersByEmailKey( String emailKey, boolean orderAscending )
+ throws UserManagerException
{
LdapUserQuery query = new LdapUserQuery();
query.setEmail( emailKey );
@@ -257,6 +260,7 @@ public class LdapUserManager
}
public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ throws UserManagerException
{
LdapUserQuery query = new LdapUserQuery();
query.setFullName( fullNameKey );
@@ -266,6 +270,7 @@ public class LdapUserManager
}
public List findUsersByQuery( UserQuery query )
+ throws UserManagerException
{
if ( query == null )
{
@@ -304,6 +309,7 @@ public class LdapUserManager
* @see org.apache.archiva.redback.users.UserManager#findUsersByUsernameKey(java.lang.String, boolean)
*/
public List findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+ throws UserManagerException
{
LdapUserQuery query = new LdapUserQuery();
query.setUsername( usernameKey );
@@ -365,13 +371,13 @@ public class LdapUserManager
}
public User updateUser( User user )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return updateUser( user, false );
}
public User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( user != null )
{
@@ -406,6 +412,7 @@ public class LdapUserManager
}
public boolean userExists( String principal )
+ throws UserManagerException
{
if ( principal == null )
{
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 c3a7526b..5e7e4c78 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
@@ -24,6 +24,7 @@ import org.apache.archiva.redback.users.UserManager;
import org.apache.archiva.redback.policy.UserSecurityPolicy;
import org.apache.archiva.redback.users.AbstractUserManager;
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.UserNotFoundException;
import org.apache.archiva.redback.users.memory.util.UserSorter;
@@ -163,7 +164,7 @@ public class MemoryUserManager
}
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
User user = findUser( 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 2fa013ac..6da8ac8d 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
@@ -24,6 +24,7 @@ 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.UserManagerException;
import org.apache.archiva.redback.users.UserNotFoundException;
import org.apache.archiva.redback.users.UserQuery;
import org.junit.Test;
@@ -40,9 +41,9 @@ import java.util.List;
*
* @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
{
@@ -93,6 +94,7 @@ public class AbstractUserManagerTestCase
}
protected void assertCleanUserManager()
+ throws UserManagerException
{
getUserManager().eraseDatabase();
@@ -105,6 +107,7 @@ public class AbstractUserManagerTestCase
@Test
public void testFindUserByNullPrincipal()
+ throws UserManagerException
{
try
{
@@ -120,6 +123,7 @@ public class AbstractUserManagerTestCase
@Test
public void testFindUserByEmptyUsername()
+ throws UserManagerException
{
try
{
@@ -157,7 +161,7 @@ public class AbstractUserManagerTestCase
@Test
public void testAddFindUserByPrincipal()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@@ -187,7 +191,7 @@ public class AbstractUserManagerTestCase
@Test
public void testAddFindUserLockedStatus()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@@ -197,7 +201,7 @@ public class AbstractUserManagerTestCase
smcqueen.setLocked( true );
/*
- * Keep a reference to the object that was added. Since it has the
+ * Keep a reference to the object that was added. Since it has the
* actual principal that was managed by jpox/jdo.
*/
User added = userManager.addUser( smcqueen );
@@ -224,7 +228,7 @@ public class AbstractUserManagerTestCase
@Test
public void testAddFindUserByUsername()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@@ -396,6 +400,7 @@ public class AbstractUserManagerTestCase
@Test
public void testFindUsersByQuery()
+ throws UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@@ -572,7 +577,7 @@ public class AbstractUserManagerTestCase
@Test
public void testDeletePermanentUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );