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