use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class MidPointAuthenticationProvider method authenticate.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String enteredUsername = (String) authentication.getPrincipal();
LOGGER.trace("Authenticating username '{}'", enteredUsername);
ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
Authentication token;
if (authentication instanceof UsernamePasswordAuthenticationToken) {
String enteredPassword = (String) authentication.getCredentials();
token = passwordAuthenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(enteredUsername, enteredPassword));
} else if (authentication instanceof PreAuthenticatedAuthenticationToken) {
token = passwordAuthenticationEvaluator.authenticateUserPreAuthenticated(connEnv, enteredUsername);
} else {
LOGGER.error("Unsupported authentication {}", authentication);
throw new AuthenticationServiceException("web.security.provider.unavailable");
}
MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
LOGGER.debug("User '{}' authenticated ({}), authorities: {}", authentication.getPrincipal(), authentication.getClass().getSimpleName(), principal.getAuthorities());
return token;
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class AuditedLogoutHandler method auditEvent.
private void auditEvent(HttpServletRequest request, Authentication authentication) {
MidPointPrincipal principal = SecurityUtils.getPrincipalUser(authentication);
PrismObject<UserType> user = principal != null ? principal.getUser().asPrismObject() : null;
Task task = taskManager.createTaskInstance();
task.setOwner(user);
task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
AuditEventRecord record = new AuditEventRecord(AuditEventType.TERMINATE_SESSION, AuditEventStage.REQUEST);
record.setInitiator(user);
record.setParameter(WebComponentUtil.getName(user));
record.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
record.setTimestamp(System.currentTimeMillis());
record.setOutcome(OperationResultStatus.SUCCESS);
// probably not needed, as audit service would take care of it; but it doesn't hurt so let's keep it here
record.setHostIdentifier(request.getLocalName());
record.setRemoteHostAddress(request.getLocalAddr());
record.setNodeIdentifier(taskManager.getNodeId());
record.setSessionIdentifier(request.getRequestedSessionId());
auditService.audit(record, task);
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class TestSecurityPrincipal method test111GuybrushRoleCaptain.
@Test
public void test111GuybrushRoleCaptain() throws Exception {
final String TEST_NAME = "test111GuybrushRoleCaptain";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
login(USER_ADMINISTRATOR_USERNAME);
Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
assignRole(USER_GUYBRUSH_OID, ROLE_CAPTAIN_OID, task, result);
resetAuthentication();
// WHEN
MidPointPrincipal principal = userProfileService.getPrincipal(USER_GUYBRUSH_USERNAME);
// THEN
display("Principal guybrush", principal);
assertEquals("Wrong number of authorizations", 3, principal.getAuthorities().size());
assertNotAuthorized(principal, AUTZ_LOOT_URL);
assertAuthorized(principal, AUTZ_COMMAND_URL);
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class TestSecurityPrincipal method test062GuybrushConditionalRoleUnassign.
@Test
public void test062GuybrushConditionalRoleUnassign() throws Exception {
final String TEST_NAME = "test062GuybrushConditionalRoleUnassign";
TestUtil.displayTestTile(this, TEST_NAME);
login(USER_ADMINISTRATOR_USERNAME);
unassignRole(USER_GUYBRUSH_OID, ROLE_CONDITIONAL_OID);
resetAuthentication();
// WHEN
MidPointPrincipal principal = userProfileService.getPrincipal(USER_GUYBRUSH_USERNAME);
// THEN
display("Principal guybrush", principal);
assertEquals("wrong username", USER_GUYBRUSH_USERNAME, principal.getUsername());
assertEquals("wrong oid", USER_GUYBRUSH_OID, principal.getOid());
assertTrue("Unexpected authorizations", principal.getAuthorities().isEmpty());
display("User in principal guybrush", principal.getUser().asPrismObject());
principal.getUser().asPrismObject().checkConsistence(true, true);
assertNotAuthorized(principal, AUTZ_LOOT_URL);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class TestSecurityPrincipal method test050GetUserJack.
@Test
public void test050GetUserJack() throws Exception {
final String TEST_NAME = "test050GetUserJack";
TestUtil.displayTestTile(this, TEST_NAME);
resetAuthentication();
// WHEN
MidPointPrincipal principal = userProfileService.getPrincipal(USER_JACK_USERNAME);
// THEN
assertNoAuthentication();
assertJack(principal);
assertTrue("Unexpected authorizations", principal.getAuthorities().isEmpty());
assertNoAuthentication();
assertNotAuthorized(principal, AUTZ_LOOT_URL);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);
assertNoAuthentication();
}
Aggregations