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;
}
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;
}
}
}
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;
}
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);
}
Aggregations