Search in sources :

Example 46 with MidPointPrincipal

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);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test)

Example 47 with MidPointPrincipal

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);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test)

Example 48 with MidPointPrincipal

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);
}
Also used : Task(com.evolveum.midpoint.task.api.Task) TestRbac(com.evolveum.midpoint.model.intest.rbac.TestRbac) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test)

Example 49 with MidPointPrincipal

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);
    }
}
Also used : Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext) PrismObject(com.evolveum.midpoint.prism.PrismObject) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 50 with MidPointPrincipal

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);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Aggregations

MidPointPrincipal (com.evolveum.midpoint.security.api.MidPointPrincipal)75 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)35 Task (com.evolveum.midpoint.task.api.Task)35 Test (org.testng.annotations.Test)30 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)18 TestTriggerTask (com.evolveum.midpoint.model.intest.TestTriggerTask)18 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)11 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)10 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)10 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)9 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)8 IdItemPathSegment (com.evolveum.midpoint.prism.path.IdItemPathSegment)6 NameItemPathSegment (com.evolveum.midpoint.prism.path.NameItemPathSegment)6 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)6 Authentication (org.springframework.security.core.Authentication)6 TestRbac (com.evolveum.midpoint.model.intest.rbac.TestRbac)5 SystemException (com.evolveum.midpoint.util.exception.SystemException)5 Authorization (com.evolveum.midpoint.security.api.Authorization)3 ConnectionEnvironment (com.evolveum.midpoint.security.api.ConnectionEnvironment)3 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)3