Search in sources :

Example 36 with MidPointPrincipal

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

the class WebModelServiceUtils method getLoggedInUserOid.

public static String getLoggedInUserOid() {
    MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
    Validate.notNull(principal, "No principal");
    if (principal.getOid() == null) {
        throw new IllegalArgumentException("No OID in principal: " + principal);
    }
    return principal.getOid();
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 37 with MidPointPrincipal

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

the class PageBase method setTimeZone.

protected void setTimeZone(PageBase page) {
    PrismObject<UserType> user = loadUserSelf(page);
    String timeZone = null;
    MidPointPrincipal principal = SecurityUtils.getPrincipalUser();
    if (user != null && user.asObjectable().getTimezone() != null) {
        timeZone = user.asObjectable().getTimezone();
    } else {
        timeZone = principal.getAdminGuiConfiguration().getDefaultTimezone();
    }
    if (timeZone != null) {
        WebSession.get().getClientInfo().getProperties().setTimeZone(TimeZone.getTimeZone(timeZone));
    }
}
Also used : MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 38 with MidPointPrincipal

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

the class PageProcessInstances method stopProcessInstancesPerformed.

private void stopProcessInstancesPerformed(AjaxRequestTarget target) {
    MidPointPrincipal user = SecurityUtils.getPrincipalUser();
    List<ProcessInstanceDto> selectedStoppableInstances = new ArrayList<>();
    for (Selectable row : WebComponentUtil.getSelectedData(getTable())) {
        ProcessInstanceDto instance = (ProcessInstanceDto) row;
        if (instance.getEndTimestamp() == null) {
            selectedStoppableInstances.add(instance);
        }
    }
    if (!isSomeItemSelected(selectedStoppableInstances, true, target)) {
        return;
    }
    OperationResult result = new OperationResult(OPERATION_STOP_PROCESS_INSTANCES);
    WorkflowService workflowService = getWorkflowService();
    for (ProcessInstanceDto instance : selectedStoppableInstances) {
        try {
            workflowService.stopProcessInstance(instance.getProcessInstanceId(), WebComponentUtil.getOrigStringFromPoly(user.getName()), result);
        } catch (SchemaException | ObjectNotFoundException | SecurityViolationException | RuntimeException ex) {
            result.createSubresult(OPERATION_STOP_PROCESS_INSTANCE).recordPartialError("Couldn't stop process instance " + instance.getName(), ex);
        }
    }
    if (result.isUnknown()) {
        result.recomputeStatus();
    }
    if (result.isSuccess()) {
        result.recordStatus(OperationResultStatus.SUCCESS, "Selected process instance(s) have been successfully stopped.");
    }
    showResult(result);
    ProcessInstanceDtoProvider provider = (ProcessInstanceDtoProvider) getTable().getDataTable().getDataProvider();
    provider.clearCache();
    //refresh feedback and table
    target.add(getFeedbackPanel());
    target.add(getTable());
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ProcessInstanceDto(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDto) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProcessInstanceDtoProvider(com.evolveum.midpoint.web.page.admin.workflow.dto.ProcessInstanceDtoProvider) Selectable(com.evolveum.midpoint.web.component.util.Selectable) WorkflowService(com.evolveum.midpoint.model.api.WorkflowService) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 39 with MidPointPrincipal

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

the class RunReportPopupPanel method createSimpleTask.

public Task createSimpleTask(String operation, PrismObject<UserType> owner) {
    Task task = getPageBase().getTaskManager().createTaskInstance(operation);
    if (owner == null) {
        MidPointPrincipal user = SecurityUtils.getPrincipalUser();
        if (user == null) {
            return task;
        } else {
            owner = user.getUser().asPrismObject();
        }
    }
    task.setOwner(owner);
    task.setChannel(SchemaConstants.CHANNEL_GUI_USER_URI);
    return task;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 40 with MidPointPrincipal

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

the class ExpressionUtil method addActorVariable.

public static void addActorVariable(ExpressionVariables scriptVariables, SecurityEnforcer securityEnforcer) {
    // There can already be a value, because for mappings, we create the
    // variable before parsing sources.
    // For other scripts we do it just before the execution, to catch all
    // possible places where scripts can be executed.
    UserType oldActor = (UserType) scriptVariables.get(ExpressionConstants.VAR_ACTOR);
    if (oldActor != null) {
        return;
    }
    UserType actor = null;
    try {
        if (securityEnforcer != null) {
            if (!securityEnforcer.isAuthenticated()) {
                // This is most likely evaluation of role
                // condition before
                // the authentication is complete.
                scriptVariables.addVariableDefinition(ExpressionConstants.VAR_ACTOR, null);
                return;
            }
            MidPointPrincipal principal = securityEnforcer.getPrincipal();
            if (principal != null) {
                actor = principal.getUser();
            }
        }
        if (actor == null) {
            LOGGER.debug("Couldn't get principal information - the 'actor' variable is set to null");
        }
    } catch (SecurityViolationException e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't get principal information - the 'actor' variable is set to null", e);
    }
    scriptVariables.addVariableDefinition(ExpressionConstants.VAR_ACTOR, actor);
}
Also used : SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) 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