Search in sources :

Example 6 with User

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

the class ArchivaServletAuthenticatorTest method testIsAuthorizedUserHasNoReadAccess.

@Test
public void testIsAuthorizedUserHasNoReadAccess() throws Exception {
    createUser(USER_ALPACA, "Al 'Archiva' Paca");
    UserManager userManager = securitySystem.getUserManager();
    User user = userManager.findUser(USER_ALPACA);
    AuthenticationResult result = new AuthenticationResult(true, USER_ALPACA, null);
    SecuritySession session = new DefaultSecuritySession(result, user);
    try {
        servletAuth.isAuthorized(request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS);
        fail("UnauthorizedException should have been thrown.");
    } catch (UnauthorizedException e) {
        assertEquals("Access denied for repository corporate", e.getMessage());
    }
    restoreGuestInitialValues(USER_ALPACA);
}
Also used : User(org.apache.archiva.redback.users.User) UserManager(org.apache.archiva.redback.users.UserManager) SecuritySession(org.apache.archiva.redback.system.SecuritySession) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) UnauthorizedException(org.apache.archiva.redback.authorization.UnauthorizedException) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) AuthenticationResult(org.apache.archiva.redback.authentication.AuthenticationResult) Test(org.junit.Test)

Example 7 with User

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

the class ArchivaServletAuthenticator method isAuthorized.

@Override
public boolean isAuthorized(String principal, String repoId, String permission) throws UnauthorizedException {
    try {
        User user = securitySystem.getUserManager().findUser(principal);
        if (user == null) {
            throw new UnauthorizedException("The security system had an internal error - please check your system logs");
        }
        if (user.isLocked()) {
            throw new UnauthorizedException("User account is locked.");
        }
        AuthenticationResult authn = new AuthenticationResult(true, principal, null);
        SecuritySession securitySession = new DefaultSecuritySession(authn, user);
        return securitySystem.isAuthorized(securitySession, permission, repoId);
    } catch (UserNotFoundException e) {
        throw new UnauthorizedException(e.getMessage(), e);
    } catch (AuthorizationException e) {
        throw new UnauthorizedException(e.getMessage(), e);
    } catch (UserManagerException e) {
        throw new UnauthorizedException(e.getMessage(), e);
    }
}
Also used : UserNotFoundException(org.apache.archiva.redback.users.UserNotFoundException) User(org.apache.archiva.redback.users.User) AuthorizationException(org.apache.archiva.redback.authorization.AuthorizationException) UserManagerException(org.apache.archiva.redback.users.UserManagerException) SecuritySession(org.apache.archiva.redback.system.SecuritySession) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) UnauthorizedException(org.apache.archiva.redback.authorization.UnauthorizedException) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) AuthenticationResult(org.apache.archiva.redback.authentication.AuthenticationResult)

Example 8 with User

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

the class AbstractSecurityTest method createUser.

protected User createUser(String principal, String fullname) throws UserManagerException {
    UserManager userManager = securitySystem.getUserManager();
    User user = userManager.createUser(principal, fullname, principal + "@testable.archiva.apache.org");
    securitySystem.getPolicy().setEnabled(false);
    userManager.addUser(user);
    securitySystem.getPolicy().setEnabled(true);
    return user;
}
Also used : User(org.apache.archiva.redback.users.User) UserManager(org.apache.archiva.redback.users.UserManager)

Example 9 with User

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

the class ArchivaConfigurableUsersManager method createUser.

@Override
public User createUser(String username, String fullName, String emailAddress) throws UserManagerException {
    Exception lastException = null;
    boolean allFailed = true;
    User user = null;
    for (UserManager userManager : userManagerPerId.values()) {
        try {
            if (!userManager.isReadOnly()) {
                user = userManager.createUser(username, fullName, emailAddress);
                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 10 with User

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

the class ArchivaConfigurableUsersManager method deleteUser.

@Override
public void deleteUser(String username) throws UserNotFoundException, UserManagerException {
    Exception lastException = null;
    boolean allFailed = true;
    User user = null;
    for (UserManager userManager : userManagerPerId.values()) {
        try {
            if (!userManager.isReadOnly()) {
                userManager.deleteUser(username);
                allFailed = false;
            }
        } catch (Exception e) {
            lastException = e;
        }
    }
    if (lastException != null && allFailed) {
        throw new UserManagerException(lastException.getMessage(), lastException);
    }
}
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)

Aggregations

User (org.apache.archiva.redback.users.User)19 UserManager (org.apache.archiva.redback.users.UserManager)11 AuthenticationResult (org.apache.archiva.redback.authentication.AuthenticationResult)10 DefaultSecuritySession (org.apache.archiva.redback.system.DefaultSecuritySession)9 UserNotFoundException (org.apache.archiva.redback.users.UserNotFoundException)9 SecuritySession (org.apache.archiva.redback.system.SecuritySession)8 UserManagerException (org.apache.archiva.redback.users.UserManagerException)8 RepositoryAdminException (org.apache.archiva.admin.model.RepositoryAdminException)6 Test (org.junit.Test)5 AbstractUserManager (org.apache.archiva.redback.users.AbstractUserManager)4 UnauthorizedException (org.apache.archiva.redback.authorization.UnauthorizedException)3 Path (java.nio.file.Path)2 ArrayList (java.util.ArrayList)2 AuthorizationException (org.apache.archiva.redback.authorization.AuthorizationException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Date (java.util.Date)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 AuditInformation (org.apache.archiva.admin.model.AuditInformation)1