]> source.dussan.org Git - archiva.git/commitdiff
UserManagerException is now a checked Exception
authorOlivier Lamy <olamy@apache.org>
Mon, 10 Dec 2012 16:34:46 +0000 (16:34 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 10 Dec 2012 16:34:46 +0000 (16:34 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1419568 13f79535-47bb-0310-9956-ffa450edef68

33 files changed:
redback-authentication/redback-authentication-providers/redback-authentication-users/src/main/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticator.java
redback-authentication/redback-authentication-providers/redback-authentication-users/src/test/java/org/apache/archiva/redback/authentication/users/UserManagerAuthenticatorTest.java
redback-data-management/src/main/java/org/apache/archiva/redback/management/DataManagementTool.java
redback-data-management/src/main/java/org/apache/archiva/redback/management/JdoDataManagementTool.java
redback-data-management/src/test/java/org/apache/archiva/redback/management/DataManagementTest.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/AdminAutoCreateCheck.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/GuestUserEnvironmentCheck.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/checks/security/LockedAdminEnvironmentCheck.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/HttpAuthenticator.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/filter/authentication/digest/HttpDigestAuthentication.java
redback-integrations/redback-common-integrations/src/main/java/org/apache/archiva/redback/integration/model/UserCredentials.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultLoginService.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultPasswordService.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultRoleManagementService.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/DefaultUserService.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/interceptors/AuthenticationInterceptor.java
redback-integrations/redback-rest/redback-rest-services/src/main/java/org/apache/archiva/redback/rest/services/utils/PasswordValidator.java
redback-keys/redback-authentication-keys/src/main/java/org/apache/archiva/redback/authentication/keystore/KeyStoreAuthenticator.java
redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/RbacAuthorizer.java
redback-rbac/redback-authorization-rbac/src/main/java/org/apache/archiva/redback/authorization/rbac/evaluator/DefaultPermissionEvaluator.java
redback-system/src/main/java/org/apache/archiva/redback/system/DefaultSecuritySystem.java
redback-system/src/main/java/org/apache/archiva/redback/system/SecuritySystem.java
redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/AbstractUserManager.java
redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManager.java
redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserManagerException.java
redback-users/redback-users-api/src/main/java/org/apache/archiva/redback/users/UserNotFoundException.java
redback-users/redback-users-providers/redback-users-cached/src/main/java/org/apache/archiva/redback/users/cached/CachedUserManager.java
redback-users/redback-users-providers/redback-users-configurable/src/main/java/org/apache/archiva/redback/users/configurable/ConfigurableUserManager.java
redback-users/redback-users-providers/redback-users-jdo/src/main/java/org/apache/archiva/redback/users/jdo/JdoUserManager.java
redback-users/redback-users-providers/redback-users-jdo/src/test/java/org/apache/archiva/redback/users/jdo/JdoUserManagerTest.java
redback-users/redback-users-providers/redback-users-ldap/src/main/java/org/apache/archiva/redback/users/ldap/LdapUserManager.java
redback-users/redback-users-providers/redback-users-memory/src/main/java/org/apache/archiva/redback/users/memory/MemoryUserManager.java
redback-users/redback-users-tests/src/main/java/org/apache/archiva/redback/users/provider/test/AbstractUserManagerTestCase.java

index 5614fa30df594237ef99fe070be59f17ba1c39fb..eb982ddab3317a73c99af12a243e047351679366 100644 (file)
@@ -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 <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  */
-@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 );
     }
index ea80a89401743b3a003fedbfbf35936d5c57f85d..70d289e9a4246e56736b823fd2f77ad5673315d6 100644 (file)
@@ -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 <a href='mailto:rahul.thakur.xdev@gmail.com'>Rahul Thakur</a>
  */
-@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 );
index 8949cf5341d9388e860faa29ba3957dd82238229..343120c725369b11d3f70804baeace5349310902 100644 (file)
@@ -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;
index 22c5fbda2008b866f6586415a03825a750f08c79..2f8ca63fb6676a04b16682a130889d702de140e3 100644 (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.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();
 
index 01342ea807e9f8e5dc25a14df6d1d7cf976d1f34..cf29e6c6bc2fbf376ae50d2057722bee7a85f02d 100644 (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.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<User> 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();
 
index fb0c625d28d4ea49bc8b2267494c12dc7320439d..ebd4b6ab0e1f16276f6dd39a2290073be3e3854c 100644 (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.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<String> violations )
@@ -91,13 +92,15 @@ public class AdminAutoCreateCheck
             {
                 useForceAdminCreationFile();
             }
-
-
         }
         catch ( UserNotFoundException e )
         {
             useForceAdminCreationFile();
         }
+        catch ( UserManagerException e )
+        {
+            useForceAdminCreationFile();
+        }
     }
 
     private void useForceAdminCreationFile()
index 21c3626dcb152c9f79ed46a303d7c1b8635f88d9..17d891ab811502b81f0ce39914a069e4b06b9d1b 100644 (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.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 <jesse@codehaus.org>
- *
  */
-@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 );
             }
 
index 3e9b881c173f3b646077072152a2a9632670fe4d..27b148a9839f346ad508fc27e2d4e3097429b383 100644 (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.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 <jesse@codehaus.org>
- *
  */
 @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 )
index c2c4b85637bf480a9f20769b32fe2ce11e100cf3..ed8ef6144bbed9cd97c1b1e61f53e105729e688b 100644 (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.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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
  */
 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;
-        }
-    }
 }
index 2ca4255ef7df30714d96412df1f21039dd66d17b..0cd7a64e4d3fd749bed6d8916bcb6bd510790f57 100644 (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.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 <a href="http://www.faqs.org/rfcs/rfc2617.html">RFC 2617 HTTP Authentication</a>.
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
  */
 @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 );
index e743c439e9a569c7531e5a501962349576dcc193..2cde9002fe66006417843b87369b7e7b72c40673 100644 (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.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 );
 
index 03940bd5f843b6d290bd4588b4c77841113316bf..0c1626edb731d6888299264a879ac6b61e642c1a 100644 (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.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<ErrorMessage> errorMessages =
+                Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+            throw new RedbackServiceException( errorMessages );
+        }
+
     }
 
     public Boolean isLogged()
index 79cd4af7ae82ad2d9e2b094ddf122ec547c5dc35..e112de9a1c96e6eadb1aff0904f0c511e59feb9e 100644 (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.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<ErrorMessage> 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<ErrorMessage> errorMessages =
+                Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+            throw new RedbackServiceException( errorMessages );
+        }
 
     }
 }
index 28496becaae1f592b3b256f92d8bc70a86d42a47..643d21989f8a31af10824d7375c4b9ec8252c488 100644 (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.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<org.apache.archiva.redback.rest.api.model.User>();
             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<String> appRoleNames = new ArrayList<String>( 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<org.apache.archiva.redback.rbac.Role> roles )
+                                                           Collection<org.apache.archiva.redback.rbac.Role> roles )
     {
         for ( org.apache.archiva.redback.rbac.Role role : roles )
         {
@@ -705,8 +737,8 @@ public class DefaultRoleManagementService
     }
 
     private Collection<org.apache.archiva.redback.rbac.Role> filterApplicationRoles( ModelApplication application,
-                                                                                      List<org.apache.archiva.redback.rbac.Role> allRoles,
-                                                                                      List<ModelTemplate> applicationTemplates )
+                                                                                     List<org.apache.archiva.redback.rbac.Role> allRoles,
+                                                                                     List<ModelTemplate> applicationTemplates )
     {
         Set<org.apache.archiva.redback.rbac.Role> applicationRoles =
             new HashSet<org.apache.archiva.redback.rbac.Role>();
index 90fa8f45b68b9c32304c082abaf4233e3d374137..35d1078e409d90fa25f6e9102b578428219d2ef6 100644 (file)
@@ -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() )
+        try
         {
-            u.setPasswordChangeRequired( false );
-            try
-            {
-                u = userManager.updateUser( u );
-                log.debug( "user {} created", u.getUsername() );
-            }
-            catch ( UserNotFoundException e )
+
+            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() )
             {
-                throw new RedbackServiceException( e.getMessage() );
+                u.setPasswordChangeRequired( false );
+                try
+                {
+                    u = userManager.updateUser( u );
+                    log.debug( "user {} created", u.getUsername() );
+                }
+                catch ( UserNotFoundException e )
+                {
+                    throw new RedbackServiceException( e.getMessage() );
+                }
             }
-        }
-        try
-        {
+
             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<User> getUsers()
         throws RedbackServiceException
     {
-        List<org.apache.archiva.redback.users.User> users = userManager.getUsers();
-        List<User> simpleUsers = new ArrayList<User>( users.size() );
+        try
+        {
+            List<org.apache.archiva.redback.users.User> users = userManager.getUsers();
+            List<User> simpleUsers = new ArrayList<User>( users.size() );
+
+            for ( org.apache.archiva.redback.users.User user : users )
+            {
+                simpleUsers.add( getSimpleUser( user ) );
+            }
 
-        for ( org.apache.archiva.redback.users.User user : users )
+            return simpleUsers;
+        }
+        catch ( UserManagerException e )
         {
-            simpleUsers.add( getSimpleUser( user ) );
+            throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
         }
-
-        return simpleUsers;
     }
 
     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.
+        org.apache.archiva.redback.users.User u = null;
 
-        if ( userManager.userExists( user.getUsername() ) )
+        try
         {
-            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 );
+            // 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 );
 
-        try
-        {
             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<Permission> getCurrentUserPermissions()
@@ -845,17 +915,23 @@ public class DefaultUserService
         throws RedbackServiceException
     {
         validateCredentialsLoose( user );
+        try
+        {
+            org.apache.archiva.redback.users.User tmpuser =
+                userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
 
-        org.apache.archiva.redback.users.User tmpuser =
-            userManager.createUser( user.getUsername(), user.getFullName(), user.getEmail() );
-
-        user.setPassword( user.getPassword() );
+            user.setPassword( user.getPassword() );
 
-        securitySystem.getPolicy().validatePassword( tmpuser );
+            securitySystem.getPolicy().validatePassword( tmpuser );
 
-        if ( ( org.codehaus.plexus.util.StringUtils.isEmpty( user.getPassword() ) ) )
+            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( "password.required", null ) );
+            throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
         }
     }
 
index 575789554be4edf297f0accb1c7793c1ee764da6..5ab5a5452e3bcfc6330653e64e4f8e2edcea29a5 100644 (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.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();
+        }
     }
 }
index 454d0508242d33b4739501e37193d9642490f38f..b0510c9ddb7ce9e838300c893524eb9ba9d6c1eb 100644 (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.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<ErrorMessage> errorMessages =
+                Arrays.asList( new ErrorMessage().message( "UserManagerException: " + e.getMessage() ) );
+            throw new RedbackServiceException( errorMessages );
+        }
 
     }
 }
index 66cb55838152097893c953bb4d2275745abc315d..f3d549f31f9c1c9058b9bd07d14d7963ce1141f6 100644 (file)
@@ -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 <jesse@codehaus.org>
  */
-@Service ("authenticator#keystore")
+@Service("authenticator#keystore")
 public class KeyStoreAuthenticator
     implements Authenticator
 {
     private Logger log = LoggerFactory.getLogger( getClass() );
 
-    @Resource (name = "keyManager#cached")
+    @Resource(name = "keyManager#cached")
     private KeyManager keystore;
 
-    @Resource (name = "userManager#configurable")
+    @Resource(name = "userManager#configurable")
     private UserManager userManager;
 
     public String getId()
@@ -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 )
index d14a2d4e971ff6cb4899255b28887ae932263c7d..eefca1a8da5de397178a83380ba52b115008e696 100644 (file)
@@ -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 <jmcconnell@apache.org>
  */
-@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<String, List<Permission>> permissionMap =
-                    manager.getAssignedPermissionMap( guest.getUsername() );
+                Map<String, List<Permission>> 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()
index 6e69491808d0faacf979830993b630fe53d7adb6..0db1f4f8bad0fb859fc27729a1b44b6f255fd881 100644 (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.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 <jesse@codehaus.org>
- *
  */
 @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", e );
+                }
+                catch ( UserManagerException e )
                 {
-                    throw new PermissionEvaluationException( "unable to locate user to retrieve username", ne );
+                    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() ) )
index 29112a78225e729f0c8327aae9939939ef957b18..58171a8f4ef95d1d69ceba64ec9b9f23cc52612d 100644 (file)
@@ -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 <jesse@codehaus.org>
- *
  */
-@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();
     }
index 8b199faf77ccb341fd2b4f7c03ea18cf561fe2f3..66f775e776081ac684f570655e4d9c23a35493c0 100644 (file)
@@ -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 <jesse@codehaus.org>
- *
  */
 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();
 }
index fcb903dfd698089555d7f734019a79ee7af33ada..e98dae97f866e47bae33ef87f55399b71de118bf 100644 (file)
@@ -31,13 +31,12 @@ import javax.annotation.PostConstruct;
  * AbstractUserManager
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
  */
 public abstract class AbstractUserManager
     implements UserManager
 {
     protected Logger log = LoggerFactory.getLogger( getClass() );
-    
+
     private List<UserManagerListener> listeners = new ArrayList<UserManagerListener>();
 
     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
         {
index e610f047b2d6c6341f45628bff4d8c47011f206e..d9a1a0c4d3d6668d9945187d5b7014994132c978 100644 (file)
@@ -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<User> getUsers();
+    List<User> getUsers()
+        throws UserManagerException;
 
-    List<User> getUsers( boolean orderAscending );
+    List<User> 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<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
@@ -148,7 +160,8 @@ public interface UserManager
      * @param query the query.
      * @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
@@ -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();
 }
index 84f95fd49848744c374d550808d3d6c62244726d..aa0b0dc4af9ec1a25085635c4ea1882314462ea6 100644 (file)
@@ -26,7 +26,7 @@ package org.apache.archiva.redback.users;
  *
  */
 public class UserManagerException
-    extends RuntimeException
+    extends Exception
 {
 
     public UserManagerException()
index ab8006adacf58e0a1961ac7d0c5960114b1f6258..ba319dbacabfa2b733007cf16b88aae42e3f862e 100644 (file)
@@ -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 )
     {
index 7cebc1f8277d4f3b494780cc695db0c27e187cd9..82cfcb8a1ef69be2363633f1cdec41d2343e71f9 100644 (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.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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
  */
 @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<User> findUsersByQuery( UserQuery query )
+        throws UserManagerException
     {
         log.debug( "NOT CACHED - .findUsersByQuery(UserQuery)" );
         return this.userImpl.findUsersByQuery( query );
     }
 
     public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+        throws UserManagerException
     {
         log.debug( "NOT CACHED - .findUsersByEmailKey(String, boolean)" );
         return this.userImpl.findUsersByEmailKey( emailKey, orderAscending );
     }
 
     public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+        throws UserManagerException
     {
         log.debug( "NOT CACHED - .findUsersByFullNameKey(String, boolean)" );
         return this.userImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
     }
 
     public List<User> 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<User> getUsers()
+        throws UserManagerException
     {
         log.debug( "NOT CACHED - .getUsers()" );
         return this.userImpl.getUsers();
     }
 
     public List<User> 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 ) )
         {
index 848aba37741046b010f4d78719e5fe4156945cd7..e6f42429ee33cd84af45d177cdf8b32f3fb0e8e0 100644 (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.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<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+        throws UserManagerException
     {
         return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
     }
 
     public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+        throws UserManagerException
     {
         return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
     }
 
     public List<User> findUsersByQuery( UserQuery query )
+        throws UserManagerException
     {
         return userManagerImpl.findUsersByQuery( query );
     }
 
     public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+        throws UserManagerException
     {
         return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
     }
@@ -135,11 +143,13 @@ public class ConfigurableUserManager
     }
 
     public List<User> getUsers()
+        throws UserManagerException
     {
         return userManagerImpl.getUsers();
     }
 
     public List<User> 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 );
     }
index 8a68c0836e87e920cc99931dede51bf16b609b15..75a3088e8ad9a84a3ae405ea6df7cedebb6986d4 100644 (file)
@@ -50,12 +50,12 @@ import java.util.List;
  *
  * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  */
-@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<User> 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<User> findUsersByQuery( UserQuery userQuery )
     {
         JdoUserQuery uq = (JdoUserQuery) userQuery;
@@ -169,7 +169,7 @@ public class JdoUserManager
         }
     }
 
-    @SuppressWarnings ("unchecked")
+    @SuppressWarnings("unchecked")
     private List<User> 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 )
         {
index bc11f245e6e7273b5e4a1e0be7b4817aa3a0f43c..38167e3bd5eb579c1268711c62d34348d64ae019 100644 (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.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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
  */
 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();
     }
 
index db66e7baf8bfdf67a2c9b28e70a093255c5210d1..fc711901ff9123b906f3eea130a2181ab5cfea7e 100644 (file)
@@ -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<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+        throws UserManagerException
     {
         LdapUserQuery query = new LdapUserQuery();
         query.setEmail( emailKey );
@@ -257,6 +260,7 @@ public class LdapUserManager
     }
 
     public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+        throws UserManagerException
     {
         LdapUserQuery query = new LdapUserQuery();
         query.setFullName( fullNameKey );
@@ -266,6 +270,7 @@ public class LdapUserManager
     }
 
     public List<User> 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<User> 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 )
         {
index c3a7526b77a9f1ebc66da672f2d9278cb42f17cd..5e7e4c7888377e4a9e6069725943e6cd0b3e3ca3 100644 (file)
@@ -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 );
 
index 2fa013acef38b5f35779071cb42511878cac7c0d..6da8ac8d19fd49ac4f29357e4be300d88a94dd91 100644 (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.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 <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
  */
-@RunWith ( SpringJUnit4ClassRunner.class )
-@ContextConfiguration ( locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" } )
-@DirtiesContext ( classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" })
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
 public class AbstractUserManagerTestCase
     extends TestCase
 {
@@ -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 );