From 48deda62b152020268c7fcbf9b870b3c06f43fbd Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 10 Dec 2012 16:37:30 +0000 Subject: [PATCH] [MRM-1721] Chaining user manager implementations. take care of last changes in redback to be able to track exception when using userManagerImpl. git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1419573 13f79535-47bb-0310-9956-ffa450edef68 --- .../services/DefaultRepositoriesService.java | 13 +++++--- .../security/ArchivaServletAuthenticator.java | 5 +++ .../security/DefaultUserRepositories.java | 7 +++- .../ArchivaConfigurableUsersManager.java | 32 +++++++++++++++---- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java index 77c510109..c9d05c99e 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/main/java/org/apache/archiva/rest/services/DefaultRepositoriesService.java @@ -49,6 +49,7 @@ import org.apache.archiva.redback.system.DefaultSecuritySession; import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.system.SecuritySystem; 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.repository.ContentNotFoundException; import org.apache.archiva.repository.ManagedRepositoryContent; @@ -104,7 +105,7 @@ import java.util.TimeZone; * @author Olivier Lamy * @since 1.4-M1 */ -@Service ( "repositoriesService#rest" ) +@Service( "repositoriesService#rest" ) public class DefaultRepositoriesService extends AbstractRestService implements RepositoriesService @@ -112,7 +113,7 @@ public class DefaultRepositoriesService private Logger log = LoggerFactory.getLogger( getClass() ); @Inject - @Named ( value = "taskExecutor#indexing" ) + @Named( value = "taskExecutor#indexing" ) private ArchivaIndexingTaskExecutor archivaIndexingTaskExecutor; @Inject @@ -131,14 +132,14 @@ public class DefaultRepositoriesService private RepositoryContentFactory repositoryFactory; @Inject - @Named ( value = "archivaTaskScheduler#repository" ) + @Named( value = "archivaTaskScheduler#repository" ) private ArchivaTaskScheduler scheduler; @Inject private DownloadRemoteIndexScheduler downloadRemoteIndexScheduler; @Inject - @Named ( value = "repositorySessionFactory" ) + @Named( value = "repositorySessionFactory" ) protected RepositorySessionFactory repositorySessionFactory; @Inject @@ -298,6 +299,10 @@ public class DefaultRepositoriesService { throw new ArchivaRestServiceException( "user " + userName + " not found", e ); } + catch ( UserManagerException e ) + { + throw new ArchivaRestServiceException( "ArchivaRestServiceException:" + e.getMessage(), e ); + } // check karma on source : read AuthenticationResult authn = new AuthenticationResult( true, userName, null ); diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java index 74e4567bc..0cbc02fd2 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/ArchivaServletAuthenticator.java @@ -30,6 +30,7 @@ import org.apache.archiva.redback.system.DefaultSecuritySession; import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.system.SecuritySystem; import org.apache.archiva.redback.users.User; +import org.apache.archiva.redback.users.UserManagerException; import org.apache.archiva.redback.users.UserNotFoundException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -113,9 +114,13 @@ public class ArchivaServletAuthenticator throw new UnauthorizedException( e.getMessage(), e ); } catch ( AuthorizationException e ) + { + throw new UnauthorizedException( e.getMessage(), e ); + } catch ( UserManagerException e ) { throw new UnauthorizedException( e.getMessage(), e ); } + } diff --git a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java index 91ba7a3e0..58aad4b96 100644 --- a/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java +++ b/archiva-modules/archiva-web/archiva-security/src/main/java/org/apache/archiva/security/DefaultUserRepositories.java @@ -30,6 +30,7 @@ import org.apache.archiva.redback.system.DefaultSecuritySession; import org.apache.archiva.redback.system.SecuritySession; import org.apache.archiva.redback.system.SecuritySystem; 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.security.common.ArchivaRoleConstants; import org.slf4j.Logger; @@ -43,7 +44,7 @@ import java.util.List; /** * DefaultUserRepositories */ -@Service ( "userRepositories" ) +@Service( "userRepositories" ) public class DefaultUserRepositories implements UserRepositories { @@ -151,6 +152,10 @@ public class DefaultUserRepositories { throw new PrincipalNotFoundException( "Unable to find principal " + principal + "", e ); } + catch ( UserManagerException e ) + { + throw new ArchivaSecurityException( e.getMessage(), e ); + } if ( user.isLocked() ) { diff --git a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java index c572ced11..78a443aa9 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/main/java/org/apache/archiva/web/security/ArchivaConfigurableUsersManager.java @@ -22,6 +22,7 @@ import org.apache.archiva.admin.model.RepositoryAdminException; import org.apache.archiva.admin.model.runtime.ArchivaRuntimeConfigurationAdmin; 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.UserManagerListener; import org.apache.archiva.redback.users.UserNotFoundException; import org.apache.archiva.redback.users.UserQuery; @@ -81,12 +82,14 @@ public class ArchivaConfigurableUsersManager @Override public User addUser( User user ) + throws UserManagerException { return userManagerPerId.get( user.getUserManagerId() ).addUser( user ); } @Override public void addUserUnchecked( User user ) + throws UserManagerException { userManagerPerId.get( user.getUserManagerId() ).addUserUnchecked( user ); } @@ -105,6 +108,7 @@ public class ArchivaConfigurableUsersManager @Override public User createUser( String username, String fullName, String emailAddress ) + throws UserManagerException { UserManager userManager = findFirstWritable(); if ( userManager == null ) @@ -123,7 +127,7 @@ public class ArchivaConfigurableUsersManager @Override public void deleteUser( String username ) - throws UserNotFoundException + throws UserNotFoundException, UserManagerException { UserManager userManager = findFirstWritable(); if ( userManager == null ) @@ -144,10 +148,10 @@ public class ArchivaConfigurableUsersManager @Override public User findUser( String username ) - throws UserNotFoundException + throws UserManagerException { User user = null; - UserNotFoundException lastException = null; + UserManagerException lastException = null; for ( UserManager userManager : userManagerPerId.values() ) { try @@ -162,11 +166,18 @@ public class ArchivaConfigurableUsersManager { lastException = e; } + catch ( UserManagerException e ) + { + lastException = e; + } } if ( user == null ) { - throw lastException; + if ( lastException != null ) + { + throw lastException; + } } return user; @@ -175,7 +186,7 @@ public class ArchivaConfigurableUsersManager @Override public User getGuestUser() - throws UserNotFoundException + throws UserNotFoundException, UserManagerException { User user = null; UserNotFoundException lastException = null; @@ -205,6 +216,7 @@ public class ArchivaConfigurableUsersManager @Override public List findUsersByEmailKey( String emailKey, boolean orderAscending ) + throws UserManagerException { List users = new ArrayList(); @@ -221,6 +233,7 @@ public class ArchivaConfigurableUsersManager @Override public List findUsersByFullNameKey( String fullNameKey, boolean orderAscending ) + throws UserManagerException { List users = new ArrayList(); @@ -237,6 +250,7 @@ public class ArchivaConfigurableUsersManager @Override public List findUsersByQuery( UserQuery query ) + throws UserManagerException { List users = new ArrayList(); @@ -253,6 +267,7 @@ public class ArchivaConfigurableUsersManager @Override public List findUsersByUsernameKey( String usernameKey, boolean orderAscending ) + throws UserManagerException { List users = new ArrayList(); @@ -275,6 +290,7 @@ public class ArchivaConfigurableUsersManager @Override public List getUsers() + throws UserManagerException { List users = new ArrayList(); @@ -291,6 +307,7 @@ public class ArchivaConfigurableUsersManager @Override public List getUsers( boolean orderAscending ) + throws UserManagerException { List users = new ArrayList(); @@ -314,14 +331,14 @@ public class ArchivaConfigurableUsersManager @Override public User updateUser( User user ) - throws UserNotFoundException + throws UserNotFoundException, UserManagerException { return userManagerPerId.get( user.getUserManagerId() ).updateUser( user ); } @Override public User updateUser( User user, boolean passwordChangeRequired ) - throws UserNotFoundException + throws UserNotFoundException, UserManagerException { return userManagerPerId.get( user.getUserManagerId() ).updateUser( user, passwordChangeRequired ); } @@ -382,6 +399,7 @@ public class ArchivaConfigurableUsersManager @Override public User createGuestUser() + throws UserManagerException { return findFirstWritable().createGuestUser(); }