Search in sources :

Example 6 with UserManagerException

use of org.apache.archiva.redback.users.UserManagerException in project archiva by apache.

the class ArchivaConfigurableUsersManager method createGuestUser.

@Override
public User createGuestUser() throws UserManagerException {
    Exception lastException = null;
    boolean allFailed = true;
    User user = null;
    for (UserManager userManager : userManagerPerId.values()) {
        try {
            if (!userManager.isReadOnly()) {
                user = userManager.createGuestUser();
                allFailed = false;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new UserManagerException(lastException.getMessage(), lastException);
    }
    return user;
}
Also used : User(org.apache.archiva.redback.users.User) UserManagerException(org.apache.archiva.redback.users.UserManagerException) AbstractUserManager(org.apache.archiva.redback.users.AbstractUserManager) UserManager(org.apache.archiva.redback.users.UserManager) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException)

Example 7 with UserManagerException

use of org.apache.archiva.redback.users.UserManagerException in project archiva by apache.

the class ArchivaLockedAdminEnvironmentCheck method validateEnvironment.

/**
 * This environment check will unlock system administrator accounts that are locked on the restart of the
 * application when the environment checks are processed.
 *
 * @param violations
 */
@Override
public void validateEnvironment(List<String> violations) {
    if (!checked) {
        for (UserManager userManager : userManagers) {
            if (userManager.isReadOnly()) {
                continue;
            }
            List<String> roles = new ArrayList<>();
            roles.add(RedbackRoleConstants.SYSTEM_ADMINISTRATOR_ROLE);
            List<UserAssignment> systemAdminstrators;
            try {
                systemAdminstrators = rbacManager.getUserAssignmentsForRoles(roles);
                for (UserAssignment userAssignment : systemAdminstrators) {
                    try {
                        User admin = userManager.findUser(userAssignment.getPrincipal());
                        if (admin.isLocked()) {
                            log.info("Unlocking system administrator: {}", admin.getUsername());
                            admin.setLocked(false);
                            userManager.updateUser(admin);
                        }
                    } catch (UserNotFoundException ne) {
                        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) {
                log.warn("Exception when checking for locked admin user: {}", e.getMessage(), e);
            }
            checked = true;
        }
    }
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) UserAssignment(org.apache.archiva.redback.rbac.UserAssignment) User(org.apache.archiva.redback.users.User) RbacManagerException(org.apache.archiva.redback.rbac.RbacManagerException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) UserManager(org.apache.archiva.redback.users.UserManager) ArrayList(java.util.ArrayList)

Example 8 with UserManagerException

use of org.apache.archiva.redback.users.UserManagerException in project archiva by apache.

the class ArchivaConfigurableUsersManager method findUser.

@Override
public User findUser(String username, boolean useCache) throws UserNotFoundException, UserManagerException {
    User user = null;
    if (useUsersCache() && useCache) {
        user = usersCache.get(username);
        if (user != null) {
            return user;
        }
    }
    Exception lastException = null;
    for (UserManager userManager : userManagerPerId.values()) {
        try {
            user = userManager.findUser(username);
            if (user != null) {
                if (useUsersCache()) {
                    usersCache.put(username, user);
                }
                return user;
            }
        } catch (UserNotFoundException e) {
            lastException = e;
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (user == null) {
        if (lastException != null) {
            if (lastException instanceof UserNotFoundException) {
                throw (UserNotFoundException) lastException;
            }
            throw new UserManagerException(lastException.getMessage(), lastException);
        }
    }
    return user;
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) User(org.apache.archiva.redback.users.User) UserManagerException(org.apache.archiva.redback.users.UserManagerException) AbstractUserManager(org.apache.archiva.redback.users.AbstractUserManager) UserManager(org.apache.archiva.redback.users.UserManager) RepositoryAdminException(org.apache.archiva.admin.model.RepositoryAdminException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException)

Example 9 with UserManagerException

use of org.apache.archiva.redback.users.UserManagerException in project archiva by apache.

the class DefaultUserRepositories method createSession.

private SecuritySession createSession(String principal) throws ArchivaSecurityException, AccessDeniedException {
    User user;
    try {
        user = securitySystem.getUserManager().findUser(principal);
        if (user == null) {
            throw new ArchivaSecurityException("The security system had an internal error - please check your system logs");
        }
    } catch (UserNotFoundException e) {
        throw new PrincipalNotFoundException("Unable to find principal " + principal + "", e);
    } catch (UserManagerException e) {
        throw new ArchivaSecurityException(e.getMessage(), e);
    }
    if (user.isLocked()) {
        throw new AccessDeniedException("User " + principal + "(" + user.getFullName() + ") is locked.");
    }
    AuthenticationResult authn = new AuthenticationResult(true, principal, null);
    authn.setUser(user);
    return new DefaultSecuritySession(authn, user);
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) User(org.apache.archiva.redback.users.User) UserManagerException(org.apache.archiva.redback.users.UserManagerException) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) AuthenticationResult(org.apache.archiva.redback.authentication.AuthenticationResult)

Aggregations

UserManagerException (org.apache.archiva.redback.users.UserManagerException)9 UserNotFoundException (org.apache.archiva.redback.users.UserNotFoundException)9 User (org.apache.archiva.redback.users.User)8 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 UserManager (org.apache.archiva.redback.users.UserManager)6 AbstractUserManager (org.apache.archiva.redback.users.AbstractUserManager)5 AuthenticationResult (org.apache.archiva.redback.authentication.AuthenticationResult)3 DefaultSecuritySession (org.apache.archiva.redback.system.DefaultSecuritySession)3 AuthorizationException (org.apache.archiva.redback.authorization.AuthorizationException)2 SecuritySession (org.apache.archiva.redback.system.SecuritySession)2 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ManagedRepository (org.apache.archiva.admin.model.beans.ManagedRepository)1 MetadataRepositoryException (org.apache.archiva.metadata.repository.MetadataRepositoryException)1 ArtifactReference (org.apache.archiva.model.ArtifactReference)1 UnauthorizedException (org.apache.archiva.redback.authorization.UnauthorizedException)1 RbacManagerException (org.apache.archiva.redback.rbac.RbacManagerException)1 UserAssignment (org.apache.archiva.redback.rbac.UserAssignment)1