fix some NPE if not writable userManager

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1421195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2012-12-13 10:25:23 +00:00
parent ad540803af
commit f36695553d
1 changed files with 15 additions and 8 deletions

View File

@ -111,9 +111,10 @@ public class ArchivaConfigurableUsersManager
throws UserManagerException throws UserManagerException
{ {
UserManager userManager = findFirstWritable(); UserManager userManager = findFirstWritable();
if ( userManager == null ) if ( userManager.isReadOnly() )
{ {
throw new RuntimeException( "impossible to find a writable userManager" ); log.warn( "cannot find writable user manager implementation, skip user creation" );
return null;
} }
return userManager.createUser( username, fullName, emailAddress ); return userManager.createUser( username, fullName, emailAddress );
} }
@ -121,7 +122,7 @@ public class ArchivaConfigurableUsersManager
@Override @Override
public UserQuery createUserQuery() public UserQuery createUserQuery()
{ {
return super.createUserQuery(); //To change body of overridden methods use File | Settings | File Templates. return super.createUserQuery();
} }
@ -130,9 +131,10 @@ public class ArchivaConfigurableUsersManager
throws UserNotFoundException, UserManagerException throws UserNotFoundException, UserManagerException
{ {
UserManager userManager = findFirstWritable(); UserManager userManager = findFirstWritable();
if ( userManager == null ) if ( userManager.isReadOnly() )
{ {
throw new RuntimeException( "impossible to find a writable userManager" ); log.warn( "cannot find writable user manager implementation, skip delete user" );
return;
} }
userManager.deleteUser( username ); userManager.deleteUser( username );
} }
@ -325,8 +327,7 @@ public class ArchivaConfigurableUsersManager
@Override @Override
public boolean isReadOnly() public boolean isReadOnly()
{ {
//olamy: must be it depends :-) return findFirstWritable() != null;
return true;
} }
@Override @Override
@ -402,7 +403,13 @@ public class ArchivaConfigurableUsersManager
public User createGuestUser() public User createGuestUser()
throws UserManagerException throws UserManagerException
{ {
return findFirstWritable().createGuestUser(); UserManager userManager = findFirstWritable();
if ( userManager.isReadOnly() )
{
log.warn( "cannot find writable user manager implementation, skip guest user creation" );
return null;
}
return userManager.createGuestUser();
} }
@Override @Override