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;
*
* @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
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 );
}
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;
*
* @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
{
@Test
public void testAuthenticateLockedPassword()
- throws AuthenticationException, MustChangePasswordException, UserNotFoundException
+ throws AuthenticationException, MustChangePasswordException, UserNotFoundException, UserManagerException
{
userSecurityPolicy.setEnabled( true );
@Test
public void testAuthenticateExpiredPassword()
- throws AuthenticationException, AccountLockedException, UserNotFoundException
+ throws AuthenticationException, AccountLockedException, UserNotFoundException, UserManagerException
{
userSecurityPolicy.setEnabled( true );
userSecurityPolicy.setPasswordExpirationDays( 15 );
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;
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;
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;
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;
}
public void backupUserDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException
+ throws IOException, XMLStreamException, UserManagerException
{
UserDatabase database = new UserDatabase();
database.setUsers( manager.getUsers() );
@SuppressWarnings("unchecked")
public void restoreUsersDatabase( UserManager manager, File backupDirectory )
- throws IOException, XMLStreamException
+ throws IOException, XMLStreamException, UserManagerException
{
UsersManagementStaxReader reader = new UsersManagementStaxReader();
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;
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
{
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
}
private void createUserDatabase( UserManager manager )
+ throws UserManagerException
{
User user = manager.createUser( "smcqueen", "Steve McQueen", "the cooler king" );
user.setPassword( "abc123" );
FileWriter fw = new FileWriter( backupFile );
- IOUtils.copy( is, fw);
+ IOUtils.copy( is, fw );
is.close();
}
private void assertEmpty( UserManager manager )
+ throws UserManagerException
{
List<User> users = manager.getUsers();
assertEquals( 0, users.size() );
FileWriter fw = new FileWriter( backupFile );
- IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), fw);
+ IOUtils.copy( getClass().getResourceAsStream( "/expected-keys.xml" ), fw );
fw.close();
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;
* @author Olivier Lamy
* @since 2.0
*/
-@Service( "environmentCheck#adminAutoCreateCheck" )
+@Service("environmentCheck#adminAutoCreateCheck")
public class AdminAutoCreateCheck
implements EnvironmentCheck
{
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
private RoleManager roleManager;
@Inject
- @Named( value = "rBACManager#cached" )
+ @Named(value = "rBACManager#cached")
private RBACManager rbacManager;
public void validateEnvironment( List<String> violations )
{
useForceAdminCreationFile();
}
-
-
}
catch ( UserNotFoundException e )
{
useForceAdminCreationFile();
}
+ catch ( UserManagerException e )
+ {
+ useForceAdminCreationFile();
+ }
}
private void useForceAdminCreationFile()
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;
* RequiredRolesEnvironmentCheck:
*
* @author: Jesse McConnell <jesse@codehaus.org>
- *
*/
-@Service( "environmentCheck#guest-user-check" )
+@Service("environmentCheck#guest-user-check")
public class GuestUserEnvironmentCheck
implements EnvironmentCheck
{
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 );
}
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;
* and unlocks them on startup.
*
* @author: Jesse McConnell <jesse@codehaus.org>
- *
*/
@Service( "environmentCheck#locked-admin-check" )
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 )
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;
* HttpAuthenticator
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
*/
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 );
+ }
}
/**
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;
- }
- }
}
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;
* 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;
/**
/**
* NOTE: Must be alphanumeric.
- *
- *
*/
- private String digestKey ="OrycteropusAfer";
+ private String digestKey = "OrycteropusAfer";
private String realm;
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 );
+ }
}
/**
* @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 )
}
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 );
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;
private String timestampLastPasswordChange;
public User createUser( UserManager um )
+ throws UserManagerException
{
User user = um.createUser( username, fullName, email );
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;
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;
{
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()
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;
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
{
@Inject
public DefaultPasswordService( SecuritySystem securitySystem,
- @Named( "httpAuthenticator#basic" ) HttpAuthenticator httpAuthenticator,
+ @Named("httpAuthenticator#basic") HttpAuthenticator httpAuthenticator,
PasswordValidator passwordValidator )
{
this.securitySystem = securitySystem;
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;
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();
}
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 ) )
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 );
+ }
}
}
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;
* @author Olivier Lamy
* @since 1.3
*/
-@Service( "roleManagementService#rest" )
+@Service("roleManagementService#rest")
public class DefaultRoleManagementService
implements RoleManagementService
{
@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;
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 )
{
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;
{
throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public Boolean updateRoleDescription( String roleName, String description )
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 ) )
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 ) )
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;
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 )
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
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 );
}
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 )
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
{
//----------------------------------------------------------------
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 )
{
}
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>();
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;
//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() ) )
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 )
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;
}
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
finally
{
removeFromCache( username );
{
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 )
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() );
{
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public int removeFromCache( String userName )
log.error( e.getMessage(), e );
throw new RedbackServiceException( e.getMessage() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
finally
{
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;
}
{
// ignore
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
return Boolean.FALSE;
}
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;
}
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 )
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 )
{
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 );
}
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
{
throw new RedbackServiceException( e.getMessage(), Response.Status.FORBIDDEN.getStatusCode() );
}
+ catch ( UserManagerException e )
+ {
+ throw new RedbackServiceException( new ErrorMessage( e.getMessage() ) );
+ }
}
public Collection<Permission> getCurrentUserPermissions()
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() ) );
}
}
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;
* @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() );
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();
+ }
}
}
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;
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
{
private SecuritySystem securitySystem;
/**
- *
* @param password
* @param principal
* @return encoded password
}
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 );
+ }
}
}
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;
*
* @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()
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 )
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;
*
* @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
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() ) )
{
{
return new AuthorizationResult( false, null, rme );
}
+ catch ( UserManagerException e )
+ {
+ return new AuthorizationResult( false, null, e );
+ }
}
public RBACManager getManager()
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;
* 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 )
{
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 );
}
}
}
{
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() ) )
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;
* DefaultSecuritySystem:
*
* @author: Jesse McConnell <jesse@codehaus.org>
- *
*/
-@Service( "securitySystem" )
+@Service("securitySystem")
public class DefaultSecuritySystem
implements SecuritySystem
{
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
* @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 );
// 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 )
{
}
public boolean isAuthenticated( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException
+ throws AuthenticationException, UserNotFoundException, AccountLockedException, MustChangePasswordException,
+ UserManagerException
{
return authenticate( source ).getAuthenticationResult().isAuthenticated();
}
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;
* SecuritySystem:
*
* @author: Jesse McConnell <jesse@codehaus.org>
- *
*/
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
/**
* return AuthorizationResult without changing authorization
+ *
* @param session
* @param permission
* @param resource
// ----------------------------------------------------------------------------
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();
}
* 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 )
}
public User getGuestUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
return findUser( GUEST_USERNAME );
}
public User createGuestUser()
+ throws UserManagerException
{
try
{
*/
public interface UserManager
{
-
+
static final String GUEST_USERNAME = "guest";
/**
* @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
* 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.
* @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.
* @throws UserNotFoundException if the user was not found.
*/
User findUser( String username )
- throws UserNotFoundException;
+ throws UserNotFoundException, UserManagerException;
/**
* Get the guest user.
* @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
* @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
* @param principal
* @return true, if user exists
*/
- boolean userExists( String principal );
+ boolean userExists( String principal )
+ throws UserManagerException;
/**
* Delete a user using the username.
* @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
*
* @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();
}
*
*/
public class UserManagerException
- extends RuntimeException
+ extends Exception
{
public UserManagerException()
* @author Jason van Zyl
*/
public class UserNotFoundException
- extends Exception
+ extends UserManagerException
{
public UserNotFoundException( String string )
{
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;
* CachedUserManager
*
* @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
- *
*/
@Service( "userManager#cached" )
public class CachedUserManager
}
public User createGuestUser()
+ throws UserManagerException
{
return userImpl.createGuestUser();
}
public User addUser( User user )
+ throws UserManagerException
{
if ( user != null )
{
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
if ( user != null )
{
}
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 );
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( GUEST_USERNAME.equals( username ) )
{
}
public User getGuestUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
Object el = usersCache.get( GUEST_USERNAME );
if ( el != null )
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 );
}
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 );
}
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 )
{
}
public boolean userExists( String userName )
+ throws UserManagerException
{
if ( usersCache.hasKey( userName ) )
{
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;
}
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 );
}
}
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
userManagerImpl.deleteUser( username );
}
}
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 );
}
}
public List<User> getUsers()
+ throws UserManagerException
{
return userManagerImpl.getUsers();
}
public List<User> getUsers( boolean orderAscending )
+ throws UserManagerException
{
return userManagerImpl.getUsers( orderAscending );
}
}
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 );
}
*
* @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
return getAllObjectsDetached( ordering );
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
private List<User> getAllObjectsDetached( String ordering )
{
return RedbackJdoUtils.getAllObjectsDetached( getPersistenceManager(), JdoUser.class, ordering, (String) null );
return findUsers( "email", emailKey, orderAscending );
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
public List<User> findUsersByQuery( UserQuery userQuery )
{
JdoUserQuery uq = (JdoUserQuery) userQuery;
}
}
- @SuppressWarnings ("unchecked")
+ @SuppressWarnings("unchecked")
private List<User> findUsers( String searchField, String searchKey, boolean ascendingUsername )
{
PersistenceManager pm = getPersistenceManager();
}
public User addUser( User user )
+ throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
}
public void deleteUser( String username )
+ throws UserManagerException
{
try
{
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
if ( !( user instanceof JdoUser ) )
{
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( StringUtils.isEmpty( username ) )
{
}
public boolean userExists( String principal )
+ throws UserManagerException
{
try
{
}
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 ) )
{
}
private Object removeObject( Object o )
+ throws UserManagerException
{
if ( o == null )
{
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;
* 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;
}
protected void assertCleanUserManager()
+ throws UserManagerException
{
// database cleanup
- ( (JdoUserManager) getUserManager()).eraseDatabase();
-
-
-
+ ( (JdoUserManager) getUserManager() ).eraseDatabase();
super.assertCleanUserManager();
}
}
public User addUser( User user )
+ throws UserManagerException
{
try
{
}
public void addUserUnchecked( User user )
+ throws UserManagerException
{
try
{
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( username != null )
{
}
public User findUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
if ( username == null )
{
}
public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+ throws UserManagerException
{
LdapUserQuery query = new LdapUserQuery();
query.setEmail( emailKey );
}
public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ throws UserManagerException
{
LdapUserQuery query = new LdapUserQuery();
query.setFullName( fullNameKey );
}
public List<User> findUsersByQuery( UserQuery query )
+ throws UserManagerException
{
if ( query == null )
{
* @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 );
}
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 )
{
}
public boolean userExists( String principal )
+ throws UserManagerException
{
if ( principal == null )
{
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;
}
public void deleteUser( String username )
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
User user = findUser( username );
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;
*
* @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
{
}
protected void assertCleanUserManager()
+ throws UserManagerException
{
getUserManager().eraseDatabase();
@Test
public void testFindUserByNullPrincipal()
+ throws UserManagerException
{
try
{
@Test
public void testFindUserByEmptyUsername()
+ throws UserManagerException
{
try
{
@Test
public void testAddFindUserByPrincipal()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@Test
public void testAddFindUserLockedStatus()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
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 );
@Test
public void testAddFindUserByUsername()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@Test
public void testFindUsersByQuery()
+ throws UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );
@Test
public void testDeletePermanentUser()
- throws UserNotFoundException
+ throws UserNotFoundException, UserManagerException
{
assertCleanUserManager();
securityPolicy.setEnabled( false );