Search in sources :

Example 31 with MidPointPrincipal

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

the class TestValidityRecomputeTask method test132BarbossaDisableAssignmentJudge.

@Test
public void test132BarbossaDisableAssignmentJudge() throws Exception {
    final String TEST_NAME = "test132BarbossaDisableAssignmentJudge";
    TestUtil.displayTestTile(this, TEST_NAME);
    // GIVEN
    Task task = createTask(TestValidityRecomputeTask.class.getName() + "." + TEST_NAME);
    OperationResult result = task.getResult();
    AssignmentType assignment = getUserAssignment(USER_BARBOSSA_OID, ROLE_JUDGE_OID);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    modifyAssignmentAdministrativeStatus(USER_BARBOSSA_OID, assignment.getId(), ActivationStatusType.DISABLED, task, result);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(null, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, true);
    // WHEN
    TestUtil.displayWhen(TEST_NAME);
    waitForTaskNextRunAssertSuccess(TASK_VALIDITY_SCANNER_OID, true);
    // THEN
    TestUtil.displayThen(TEST_NAME);
    assertDummyAccount(null, USER_BARBOSSA_USERNAME, USER_BARBOSSA_FULL_NAME, true);
    assertNoDummyAccountAttribute(null, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_TITLE_NAME);
    assertDummyAccountAttribute(null, USER_BARBOSSA_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, RESOURCE_DUMMY_DRINK, ROLE_SAILOR_DRINK);
    PrismObject<UserType> user = getUser(USER_BARBOSSA_OID);
    display("User after", user);
    assertLinks(user, 1);
    MidPointPrincipal principal = userProfileService.getPrincipal(user);
    assertNotAuthorized(principal, AUTZ_PUNISH_URL);
}
Also used : TestTriggerTask(com.evolveum.midpoint.model.intest.TestTriggerTask) Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) Test(org.testng.annotations.Test) AbstractInitializedModelIntegrationTest(com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)

Example 32 with MidPointPrincipal

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

the class AbstractModelIntegrationTest method login.

protected void login(PrismObject<UserType> user) throws SchemaException {
    MidPointPrincipal principal = userProfileService.getPrincipal(user);
    login(principal);
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 33 with MidPointPrincipal

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

the class PageResetPasswordConfirmation method init.

private void init(final PageParameters pageParameters) {
    PageParameters params = pageParameters;
    if (params == null) {
        params = getPageParameters();
    }
    OperationResult result = new OperationResult(OPERATION_FINISH_REGISTRATION);
    if (params == null) {
        LOGGER.error("Confirmation link is not valid. No credentials provided in it");
        String msg = createStringResource("PageSelfRegistration.invalid.registration.link").getString();
        getSession().error(createStringResource(msg));
        result.recordFatalError(msg);
        initLayout(result);
        return;
    }
    StringValue userNameValue = params.get(SchemaConstants.USER_ID);
    Validate.notEmpty(userNameValue.toString());
    StringValue tokenValue = params.get(SchemaConstants.TOKEN);
    Validate.notEmpty(tokenValue.toString());
    UsernamePasswordAuthenticationToken token = authenticateUser(userNameValue.toString(), tokenValue.toString(), result);
    if (token == null) {
        initLayout(result);
        return;
    } else {
        //			SecurityContextHolder.getContext().setAuthentication(token);
        MidPointPrincipal principal = (MidPointPrincipal) token.getPrincipal();
        Collection<Authorization> authz = principal.getAuthorities();
        if (authz != null) {
            Iterator<Authorization> authzIterator = authz.iterator();
            while (authzIterator.hasNext()) {
                Authorization authzI = authzIterator.next();
                Iterator<String> actionIterator = authzI.getAction().iterator();
                while (actionIterator.hasNext()) {
                    String action = actionIterator.next();
                    if (action.contains(AuthorizationConstants.NS_AUTHORIZATION_UI)) {
                        actionIterator.remove();
                    }
                }
            }
        }
        AuthorizationType authorizationType = new AuthorizationType();
        authorizationType.getAction().add(AuthorizationConstants.AUTZ_UI_SELF_CREDENTIALS_URL);
        Authorization selfServiceCredentialsAuthz = new Authorization(authorizationType);
        authz.add(selfServiceCredentialsAuthz);
        SecurityContextHolder.getContext().setAuthentication(token);
        setResponsePage(PageResetPassword.class);
    }
    initLayout(result);
}
Also used : Authorization(com.evolveum.midpoint.security.api.Authorization) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) StringValue(org.apache.wicket.util.string.StringValue) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 34 with MidPointPrincipal

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

the class PageBase method loadAdminGuiConfiguration.

public AdminGuiConfigurationType loadAdminGuiConfiguration() {
    MidPointPrincipal user = SecurityUtils.getPrincipalUser();
    AdminGuiConfigurationType adminGuiConfig = null;
    if (user == null) {
        return adminGuiConfig;
    } else {
        OperationResult result = new OperationResult(OPERATION_GET_SYSTEM_CONFIG);
        Task task = createSimpleTask(OPERATION_GET_SYSTEM_CONFIG);
        try {
            adminGuiConfig = getModelInteractionService().getAdminGuiConfiguration(task, result);
            LOGGER.trace("Admin GUI config: {}", adminGuiConfig);
            result.recordSuccess();
        } catch (Exception ex) {
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load system configuration", ex);
            result.recordFatalError("Couldn't load system configuration.", ex);
        }
        return adminGuiConfig;
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 35 with MidPointPrincipal

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

the class WebModelServiceUtils method getTimezone.

public static TimeZone getTimezone(UserType user) {
    MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
    if (principal != null && user == null) {
        user = principal.getUser();
    }
    String timeZone;
    if (user != null && StringUtils.isNotEmpty(user.getTimezone())) {
        timeZone = user.getTimezone();
    } else {
        timeZone = principal != null && principal.getAdminGuiConfiguration() != null ? principal.getAdminGuiConfiguration().getDefaultTimezone() : "";
    }
    try {
        if (timeZone != null) {
            return TimeZone.getTimeZone(timeZone);
        }
    } catch (Exception ex) {
        LOGGER.debug("Error occurred while getting user time zone, " + ex.getMessage());
    }
    return null;
}
Also used : PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) 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