Search in sources :

Example 16 with User

use of org.apache.archiva.redback.users.User 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)

Example 17 with User

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

the class AbstractSecurityTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    Path srcConfig = Paths.get("src/test/resources/repository-archiva.xml");
    Path destConfig = Paths.get("target/test-conf/archiva.xml");
    Files.createDirectories(destConfig.getParent());
    Files.deleteIfExists(destConfig);
    FileUtils.copyFile(srcConfig.toFile(), destConfig.toFile());
    // Some basic asserts.
    assertNotNull(securitySystem);
    assertNotNull(rbacManager);
    assertNotNull(roleManager);
    assertNotNull(userRepos);
    assertNotNull(archivaConfiguration);
    // Setup Admin User.
    User adminUser = createUser(USER_ADMIN, "Admin User");
    roleManager.assignRole(ArchivaRoleConstants.TEMPLATE_SYSTEM_ADMIN, adminUser.getUsername());
    // Setup Guest User.
    User guestUser = createUser(USER_GUEST, "Guest User");
    roleManager.assignRole(ArchivaRoleConstants.TEMPLATE_GUEST, guestUser.getUsername());
    repositoryRegistry.setArchivaConfiguration(archivaConfiguration);
    repositoryRegistry.reload();
}
Also used : Path(java.nio.file.Path) User(org.apache.archiva.redback.users.User) Before(org.junit.Before)

Example 18 with User

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

the class ArchivaServletAuthenticatorTest method testIsAuthorizedUserHasWriteAccess.

@Test
public void testIsAuthorizedUserHasWriteAccess() throws Exception {
    createUser(USER_ALPACA, "Al 'Archiva' Paca");
    assignRepositoryManagerRole(USER_ALPACA, "corporate");
    UserManager userManager = securitySystem.getUserManager();
    User user = userManager.findUser(USER_ALPACA);
    AuthenticationResult result = new AuthenticationResult(true, USER_ALPACA, null);
    SecuritySession session = new DefaultSecuritySession(result, user);
    boolean isAuthorized = servletAuth.isAuthorized(request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
    assertTrue(isAuthorized);
    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) DefaultSecuritySession(org.apache.archiva.redback.system.DefaultSecuritySession) AuthenticationResult(org.apache.archiva.redback.authentication.AuthenticationResult) Test(org.junit.Test)

Example 19 with User

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

the class AbstractRestService method getAuditInformation.

protected AuditInformation getAuditInformation() {
    RedbackRequestInformation redbackRequestInformation = RedbackAuthenticationThreadLocal.get();
    User user = redbackRequestInformation == null ? null : redbackRequestInformation.getUser();
    String remoteAddr = redbackRequestInformation == null ? null : redbackRequestInformation.getRemoteAddr();
    return new AuditInformation(user, remoteAddr);
}
Also used : AuditInformation(org.apache.archiva.admin.model.AuditInformation) User(org.apache.archiva.redback.users.User) RedbackRequestInformation(org.apache.archiva.redback.rest.services.RedbackRequestInformation)

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