use of org.apache.archiva.redback.users.UserManager in project archiva by apache.
the class DefaultRedbackRuntimeConfigurationService method getUserManagerImplementationInformations.
@Override
public List<UserManagerImplementationInformation> getUserManagerImplementationInformations() throws ArchivaRestServiceException {
Map<String, UserManager> beans = applicationContext.getBeansOfType(UserManager.class);
if (beans.isEmpty()) {
return Collections.emptyList();
}
List<UserManagerImplementationInformation> informations = new ArrayList<>(beans.size());
for (Map.Entry<String, UserManager> entry : beans.entrySet()) {
UserManager userManager = applicationContext.getBean(entry.getKey(), UserManager.class);
if (userManager.isFinalImplementation()) {
UserManagerImplementationInformation information = new UserManagerImplementationInformation();
information.setBeanId(StringUtils.substringAfter(entry.getKey(), "#"));
information.setDescriptionKey(userManager.getDescriptionKey());
information.setReadOnly(userManager.isReadOnly());
informations.add(information);
}
}
return informations;
}
use of org.apache.archiva.redback.users.UserManager in project archiva by apache.
the class ArchivaServletAuthenticatorTest method testIsAuthorizedUserHasNoWriteAccess.
@Test
public void testIsAuthorizedUserHasNoWriteAccess() throws Exception {
createUser(USER_ALPACA, "Al 'Archiva' Paca");
assignRepositoryObserverRole(USER_ALPACA, "corporate");
// httpServletRequestControl.expectAndReturn( request.getRemoteAddr(), "192.168.111.111" );
EasyMock.expect(request.getRemoteAddr()).andReturn("192.168.111.111");
UserManager userManager = securitySystem.getUserManager();
User user = userManager.findUser(USER_ALPACA);
AuthenticationResult result = new AuthenticationResult(true, USER_ALPACA, null);
SecuritySession session = new DefaultSecuritySession(result, user);
httpServletRequestControl.replay();
try {
servletAuth.isAuthorized(request, session, "corporate", ArchivaRoleConstants.OPERATION_REPOSITORY_UPLOAD);
fail("UnauthorizedException should have been thrown.");
} catch (UnauthorizedException e) {
assertEquals("Access denied for repository corporate", e.getMessage());
}
httpServletRequestControl.verify();
restoreGuestInitialValues(USER_ALPACA);
}
use of org.apache.archiva.redback.users.UserManager in project archiva by apache.
the class ArchivaServletAuthenticatorTest method testIsAuthorizedUserHasReadAccess.
@Test
public void testIsAuthorizedUserHasReadAccess() throws Exception {
createUser(USER_ALPACA, "Al 'Archiva' Paca");
assignRepositoryObserverRole(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_ACCESS);
assertTrue(isAuthorized);
restoreGuestInitialValues(USER_ALPACA);
}
use of org.apache.archiva.redback.users.UserManager 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);
}
use of org.apache.archiva.redback.users.UserManager 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;
}
Aggregations