Search in sources :

Example 41 with MidPointPrincipal

use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.

the class TestEmpty method test020UserProfileServiceMockUsername.

@Test
public void test020UserProfileServiceMockUsername() throws Exception {
    final String TEST_NAME = "test020UserProfileServiceMockUsername";
    TestUtil.displayTestTile(TEST_NAME);
    MidPointPrincipal principal = userProfileService.getPrincipal(USER_JACK_USERNAME);
    assertPrincipalJack(principal);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) AbstractIntegrationTest(com.evolveum.midpoint.test.AbstractIntegrationTest) Test(org.testng.annotations.Test)

Example 42 with MidPointPrincipal

use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.

the class UserProfileServiceMock method createPrincipal.

private MidPointPrincipal createPrincipal(PrismObject<UserType> user, OperationResult result) {
    if (user == null) {
        return null;
    }
    PrismObject<SystemConfigurationType> systemConfiguration = null;
    try {
        systemConfiguration = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, result);
    } catch (ObjectNotFoundException | SchemaException e) {
        LOGGER.warn("No system configuration: {}", e.getMessage(), e);
    }
    MidPointPrincipal principal = new MidPointPrincipal(user.asObjectable());
    initializePrincipalFromAssignments(principal, systemConfiguration);
    return principal;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 43 with MidPointPrincipal

use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.

the class TestSecurityPrincipal method test110GuybrushRoleNicePirate.

@Test
public void test110GuybrushRoleNicePirate() throws Exception {
    final String TEST_NAME = "test110GuybrushRoleNicePirate";
    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_NICE_PIRATE_OID, task, result);
    resetAuthentication();
    // WHEN
    MidPointPrincipal principal = userProfileService.getPrincipal(USER_GUYBRUSH_USERNAME);
    // THEN
    display("Principal guybrush", principal);
    assertEquals("Wrong number of authorizations", 2, principal.getAuthorities().size());
    assertNotAuthorized(principal, AUTZ_LOOT_URL);
    assertNotAuthorized(principal, AUTZ_COMMAND_URL);
}
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 44 with MidPointPrincipal

use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.

the class TestSecurityPrincipal method test010GetUserAdministrator.

@Test
public void test010GetUserAdministrator() throws Exception {
    final String TEST_NAME = "test010GetUserAdministrator";
    TestUtil.displayTestTile(this, TEST_NAME);
    resetAuthentication();
    // WHEN
    MidPointPrincipal principal = userProfileService.getPrincipal(USER_ADMINISTRATOR_USERNAME);
    // THEN
    display("Administrator principal", principal);
    assertEquals("Wrong number of authorizations", 1, principal.getAuthorities().size());
    assertHasAuthotizationAllow(principal.getAuthorities().iterator().next(), AuthorizationConstants.AUTZ_ALL_URL);
    assertAuthorized(principal, AUTZ_LOOT_URL);
    assertAuthorized(principal, AUTZ_COMMAND_URL);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test)

Example 45 with MidPointPrincipal

use of com.evolveum.midpoint.security.api.MidPointPrincipal in project midpoint by Evolveum.

the class TestSecurityPrincipal method test109JackUnassignRolePirate.

@Test
public void test109JackUnassignRolePirate() throws Exception {
    final String TEST_NAME = "test109JackUnassignRolePirate";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    login(USER_ADMINISTRATOR_USERNAME);
    Task task = taskManager.createTaskInstance(TestRbac.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    unassignRole(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", 0, principal.getAuthorities().size());
    assertNotAuthorized(principal, AUTZ_LOOT_URL);
    assertNotAuthorized(principal, AUTZ_COMMAND_URL);
    assertAdminGuiConfigurations(principal, 0, 1, 3, 1, 0);
}
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)

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