use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class TestSecurityPrincipal method test051GetUserBarbossa.
@Test
public void test051GetUserBarbossa() throws Exception {
final String TEST_NAME = "test051GetUserBarbossa";
TestUtil.displayTestTile(this, TEST_NAME);
resetAuthentication();
// WHEN
MidPointPrincipal principal = userProfileService.getPrincipal(USER_BARBOSSA_USERNAME);
// THEN
display("Principal barbossa", principal);
assertNotNull("No principal for username " + USER_BARBOSSA_USERNAME, principal);
assertEquals("wrong username", USER_BARBOSSA_USERNAME, principal.getUsername());
assertEquals("wrong oid", USER_BARBOSSA_OID, principal.getOid());
assertTrue("Unexpected authorizations", principal.getAuthorities().isEmpty());
display("User in principal barbossa", 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 test052GetUserGuybrush.
@Test
public void test052GetUserGuybrush() throws Exception {
final String TEST_NAME = "test052GetUserGuybrush";
TestUtil.displayTestTile(this, TEST_NAME);
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 test100JackRolePirate.
@Test
public void test100JackRolePirate() throws Exception {
final String TEST_NAME = "test100JackRolePirate";
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_JACK_OID, ROLE_PIRATE_OID, task, result);
resetAuthentication();
// WHEN
MidPointPrincipal principal = userProfileService.getPrincipal(USER_JACK_USERNAME);
// THEN
assertJack(principal);
assertEquals("Wrong number of authorizations", 1, principal.getAuthorities().size());
assertHasAuthotizationAllow(principal.getAuthorities().iterator().next(), AUTZ_LOOT_URL);
assertAuthorized(principal, AUTZ_LOOT_URL, AuthorizationPhaseType.EXECUTION);
assertNotAuthorized(principal, AUTZ_LOOT_URL, AuthorizationPhaseType.REQUEST);
assertNotAuthorized(principal, AUTZ_LOOT_URL, null);
assertNotAuthorized(principal, AUTZ_COMMAND_URL);
assertAdminGuiConfigurations(principal, 1, 2, 3, 2, 2);
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method assertLoggedInUser.
protected void assertLoggedInUser(String username) {
SecurityContext securityContext = SecurityContextHolder.getContext();
Authentication authentication = securityContext.getAuthentication();
if (authentication == null) {
if (username == null) {
return;
} else {
AssertJUnit.fail("Expected logged in user '" + username + "' but there was no authentication in the spring security context");
}
}
Object principal = authentication.getPrincipal();
if (principal == null) {
if (username == null) {
return;
} else {
AssertJUnit.fail("Expected logged in user '" + username + "' but there was no principal in the spring security context");
}
}
if (principal instanceof MidPointPrincipal) {
MidPointPrincipal midPointPrincipal = (MidPointPrincipal) principal;
UserType user = midPointPrincipal.getUser();
if (user == null) {
if (username == null) {
return;
} else {
AssertJUnit.fail("Expected logged in user '" + username + "' but there was no user in the spring security context");
}
}
assertEquals("Wrong logged-in user", username, user.getName().getOrig());
} else {
AssertJUnit.fail("Expected logged in user '" + username + "' but there was unknown principal in the spring security context: " + principal);
}
}
use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.
the class AbstractModelIntegrationTest method loginSuperUser.
protected void loginSuperUser(PrismObject<UserType> user) throws SchemaException {
MidPointPrincipal principal = userProfileService.getPrincipal(user);
loginSuperUser(principal);
}
Aggregations