From ad33df69c84292bda51ce98d011405c25a912307 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 22 Feb 2013 16:05:08 +0000 Subject: [PATCH] really chain user managers git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1449091 13f79535-47bb-0310-9956-ffa450edef68 --- .../ArchivaConfigurableUsersManager.java | 96 ++++++++++++------- 1 file changed, 64 insertions(+), 32 deletions(-) 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 bead5a99b..3af683190 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 @@ -121,32 +121,31 @@ public class ArchivaConfigurableUsersManager } } - protected UserManager findFirstWritable() - { - for ( UserManager userManager : userManagerPerId.values() ) - { - if ( !userManager.isReadOnly() ) - { - return userManager; - } - } - return null; - } - @Override public User createUser( String username, String fullName, String emailAddress ) throws UserManagerException { - UserManager userManager = findFirstWritable(); - if ( userManager.isReadOnly() ) + Exception lastException = null; + boolean allFailed = true; + User user = null; + for ( UserManager userManager : userManagerPerId.values() ) { - log.warn( "cannot find writable user manager implementation, skip user creation" ); - return null; + try + { + if ( !userManager.isReadOnly() ) + { + user = userManager.createUser( username, fullName, emailAddress ); + allFailed = false; + } + } + catch ( Exception e ) + { + lastException = e; + } } - User user = userManager.createUser( username, fullName, emailAddress ); - if ( useUsersCache() ) + if ( lastException != null && allFailed ) { - usersCache.put( user.getUsername(), user ); + throw new UserManagerException( lastException.getMessage(), lastException ); } return user; } @@ -162,16 +161,27 @@ public class ArchivaConfigurableUsersManager public void deleteUser( String username ) throws UserNotFoundException, UserManagerException { - UserManager userManager = findFirstWritable(); - if ( userManager.isReadOnly() ) + Exception lastException = null; + boolean allFailed = true; + User user = null; + for ( UserManager userManager : userManagerPerId.values() ) { - log.warn( "cannot find writable user manager implementation, skip delete user" ); - return; + try + { + if ( !userManager.isReadOnly() ) + { + userManager.deleteUser( username ); + allFailed = false; + } + } + catch ( Exception e ) + { + lastException = e; + } } - userManager.deleteUser( username ); - if ( useUsersCache() ) + if ( lastException != null && allFailed ) { - usersCache.remove( username ); + throw new UserManagerException( lastException.getMessage(), lastException ); } } @@ -354,7 +364,13 @@ public class ArchivaConfigurableUsersManager @Override public boolean isReadOnly() { - return findFirstWritable() != null; + boolean readOnly = false; + + for ( UserManager userManager : userManagerPerId.values() ) + { + readOnly = readOnly || userManager.isReadOnly(); + } + return readOnly; } @Override @@ -444,13 +460,29 @@ public class ArchivaConfigurableUsersManager public User createGuestUser() throws UserManagerException { - UserManager userManager = findFirstWritable(); - if ( userManager == null ) + Exception lastException = null; + boolean allFailed = true; + User user = null; + for ( UserManager userManager : userManagerPerId.values() ) { - log.warn( "cannot find writable user manager implementation, skip guest user creation" ); - return null; + try + { + if ( !userManager.isReadOnly() ) + { + user = userManager.createGuestUser(); + allFailed = false; + } + } + catch ( Exception e ) + { + lastException = e; + } } - return userManager.createGuestUser(); + if ( lastException != null && allFailed ) + { + throw new UserManagerException( lastException.getMessage(), lastException ); + } + return user; } @Override