Search in sources :

Example 11 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class PageRegistrationConfirmation method assignAdditionalRoleIfPresent.

private void assignAdditionalRoleIfPresent(String userOid, NonceType nonceType, PrismObject<UserType> administrator, OperationResult parentResult) throws CommonException {
    if (nonceType.getName() == null) {
        return;
    }
    OperationResult result = parentResult.createSubresult(OPERATION_ASSIGN_ADDITIONAL_ROLE);
    try {
        runAsChecked(() -> {
            Task task = createAnonymousTask(OPERATION_ASSIGN_ADDITIONAL_ROLE);
            ObjectDelta<UserType> assignRoleDelta;
            AssignmentType assignment = new AssignmentType();
            assignment.setTargetRef(ObjectTypeUtil.createObjectRef(nonceType.getName(), ObjectTypes.ABSTRACT_ROLE));
            getPrismContext().adopt(assignment);
            List<ItemDelta> userDeltas = new ArrayList<>();
            userDeltas.add(getPrismContext().deltaFactory().container().createModificationAdd(UserType.F_ASSIGNMENT, UserType.class, assignment));
            assignRoleDelta = getPrismContext().deltaFactory().object().createModifyDelta(userOid, userDeltas, UserType.class);
            assignRoleDelta.setPrismContext(getPrismContext());
            WebModelServiceUtils.save(assignRoleDelta, result, task, PageRegistrationConfirmation.this);
            return null;
        }, administrator);
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError(getString("PageRegistrationConfirmation.message.assignAdditionalRoleIfPresent.fatalError"), e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't assign additional role", e);
        throw e;
    } finally {
        result.computeStatusIfUnknown();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ItemDelta(com.evolveum.midpoint.prism.delta.ItemDelta) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 12 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class AuthUtil method isPostAuthenticationEnabled.

public static boolean isPostAuthenticationEnabled(TaskManager taskManager, ModelInteractionService modelInteractionService) {
    MidPointPrincipal midpointPrincipal = getPrincipalUser();
    if (midpointPrincipal != null) {
        FocusType focus = midpointPrincipal.getFocus();
        Task task = taskManager.createTaskInstance(OPERATION_LOAD_FLOW_POLICY);
        OperationResult parentResult = new OperationResult(OPERATION_LOAD_FLOW_POLICY);
        RegistrationsPolicyType registrationPolicyType;
        try {
            registrationPolicyType = modelInteractionService.getFlowPolicy(focus.asPrismObject(), task, parentResult);
            if (registrationPolicyType == null) {
                return false;
            }
            SelfRegistrationPolicyType postAuthenticationPolicy = registrationPolicyType.getPostAuthentication();
            if (postAuthenticationPolicy == null) {
                return false;
            }
            String requiredLifecycleState = postAuthenticationPolicy.getRequiredLifecycleState();
            if (StringUtils.isNotBlank(requiredLifecycleState) && requiredLifecycleState.equals(focus.getLifecycleState())) {
                return true;
            }
        } catch (CommonException e) {
            LoggingUtils.logException(LOGGER, "Cannot determine post authentication policies", e);
        }
    }
    return false;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) RegistrationsPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.RegistrationsPolicyType) FocusType(com.evolveum.midpoint.xml.ns._public.common.common_3.FocusType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) SelfRegistrationPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.SelfRegistrationPolicyType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal)

Example 13 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class AccessCertificationCampaignCreationTaskHandler method run.

@Override
public TaskRunResult run(@NotNull RunningTask task) {
    LOGGER.trace("Task run starting");
    OperationResult opResult = task.getResult().createSubresult(CLASS_DOT + "run");
    opResult.setSummarizeSuccesses(true);
    TaskRunResult runResult = new TaskRunResult();
    String definitionOid = task.getObjectOid();
    if (definitionOid == null) {
        LOGGER.error("No definition OID specified in the task");
        opResult.recordFatalError("No definition OID specified in the task");
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    opResult.addContext("definitionOid", definitionOid);
    AccessCertificationCampaignType campaign;
    try {
        LOGGER.debug("Creating campaign with definition of {}", definitionOid);
        campaign = certificationManager.createCampaign(definitionOid, task, opResult);
        LOGGER.info("Campaign {} was created.", ObjectTypeUtil.toShortString(campaign));
    } catch (Exception e) {
        LoggingUtils.logException(LOGGER, "Error while executing 'create campaign' task handler", e);
        opResult.recordFatalError("Error while executing 'create campaign' task handler: " + e.getMessage(), e);
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    Operation op = task.recordIterativeOperationStart(campaign.asPrismObject());
    try {
        certificationManager.openNextStage(campaign.getOid(), task, opResult);
        LOGGER.info("Campaign {} was started.", ObjectTypeUtil.toShortString(campaign));
        op.succeeded();
        opResult.computeStatus();
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        runResult.setOperationResultStatus(OperationResultStatus.SUCCESS);
        runResult.setProgress(task.getLegacyProgress() + 1);
        return runResult;
    } catch (CommonException | RuntimeException e) {
        op.failed(e);
        LoggingUtils.logException(LOGGER, "Error while executing 'create campaign' task handler", e);
        opResult.recordFatalError("Error while executing 'create campaign' task handler: " + e.getMessage(), e);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        return runResult;
    }
}
Also used : OperationResult(com.evolveum.midpoint.schema.result.OperationResult) CommonException(com.evolveum.midpoint.util.exception.CommonException) Operation(com.evolveum.midpoint.schema.statistics.Operation) CommonException(com.evolveum.midpoint.util.exception.CommonException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 14 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class AccessCertificationRemediationTaskHandler method run.

@Override
public TaskRunResult run(@NotNull RunningTask task) {
    LOGGER.trace("Task run starting");
    OperationResult opResult = task.getResult().createSubresult(CLASS_DOT + "run");
    opResult.setSummarizeSuccesses(true);
    TaskRunResult runResult = new TaskRunResult();
    String campaignOid = task.getObjectOid();
    if (campaignOid == null) {
        LOGGER.error("No campaign OID specified in the task");
        opResult.recordFatalError("No campaign OID specified in the task");
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
    opResult.addContext("campaignOid", campaignOid);
    try {
        AccessCertificationCampaignType campaign = helper.getCampaign(campaignOid, null, task, opResult);
        if (!CertCampaignTypeUtil.isRemediationAutomatic(campaign)) {
            LOGGER.error("Automatic remediation is not configured.");
            opResult.recordFatalError("Automatic remediation is not configured.");
            runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
            runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
            return runResult;
        }
        CertificationHandler handler = certificationManager.findCertificationHandler(campaign);
        int revokedOk = 0;
        int revokedError = 0;
        List<AccessCertificationCaseType> caseList = queryHelper.getAllCurrentIterationCases(campaignOid, norm(campaign.getIteration()), null, opResult);
        for (AccessCertificationCaseType acase : caseList) {
            if (OutcomeUtils.isRevoke(acase, campaign)) {
                OperationResult caseResult = opResult.createMinorSubresult(opResult.getOperation() + ".revoke");
                final Long caseId = acase.asPrismContainerValue().getId();
                caseResult.addContext("caseId", caseId);
                try {
                    handler.doRevoke(acase, campaign, task, caseResult);
                    caseHelper.markCaseAsRemedied(campaignOid, caseId, task, caseResult);
                    caseResult.computeStatus();
                    revokedOk++;
                    task.incrementLegacyProgressAndStoreStatisticsIfTimePassed(opResult);
                } catch (CommonException | RuntimeException e) {
                    String message = "Couldn't revoke case " + caseId + ": " + e.getMessage();
                    LoggingUtils.logUnexpectedException(LOGGER, message, e);
                    caseResult.recordPartialError(message, e);
                    revokedError++;
                }
                opResult.summarize();
            }
        }
        opResult.createSubresult(CLASS_DOT + "run.statistics").recordStatus(OperationResultStatus.NOT_APPLICABLE, "Successfully revoked items: " + revokedOk + ", tried to revoke but failed: " + revokedError);
        opResult.computeStatus();
        certificationManager.closeCampaign(campaignOid, task, opResult);
        runResult.setOperationResultStatus(OperationResultStatus.SUCCESS);
        runResult.setRunResultStatus(TaskRunResultStatus.FINISHED);
        LOGGER.trace("Task run stopping (campaign {})", ObjectTypeUtil.toShortString(campaign));
        return runResult;
    } catch (Exception e) {
        // TODO better error handling
        LoggingUtils.logException(LOGGER, "Error while executing remediation task handler", e);
        opResult.recordFatalError("Error while executing remediation task handler: " + e.getMessage(), e);
        runResult.setOperationResultStatus(OperationResultStatus.FATAL_ERROR);
        runResult.setRunResultStatus(TaskRunResultStatus.PERMANENT_ERROR);
        return runResult;
    }
}
Also used : AccessCertificationCaseType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCaseType) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) CommonException(com.evolveum.midpoint.util.exception.CommonException) CertificationHandler(com.evolveum.midpoint.certification.impl.handlers.CertificationHandler) CommonException(com.evolveum.midpoint.util.exception.CommonException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Example 15 with CommonException

use of com.evolveum.midpoint.util.exception.CommonException in project midpoint by Evolveum.

the class CompletedTaskCleanupTriggerHandler method handle.

@Override
public <O extends ObjectType> void handle(@NotNull PrismObject<O> object, @NotNull TriggerType trigger, @NotNull RunningTask task, @NotNull OperationResult result) {
    try {
        // todo use repo preconditions to implement this
        if (!(object.asObjectable() instanceof TaskType)) {
            return;
        }
        TaskType completedTask = repositoryService.getObject(TaskType.class, object.getOid(), createReadOnlyCollection(), result).asObjectable();
        LOGGER.trace("Checking completed task to be deleted {}", completedTask);
        if (completedTask.getExecutionState() != TaskExecutionStateType.CLOSED) {
            LOGGER.debug("Task {} is not closed, not deleting it.", completedTask);
            return;
        }
        XMLGregorianCalendar completion = completedTask.getCompletionTimestamp();
        if (completion == null) {
            LOGGER.debug("Task {} has no completion timestamp, not deleting it.", completedTask);
            return;
        }
        if (completedTask.getCleanupAfterCompletion() == null) {
            LOGGER.debug("Task {} has no 'cleanup after completion' set, not deleting it.", completedTask);
            return;
        }
        completion.add(completedTask.getCleanupAfterCompletion());
        if (!XmlTypeConverter.isBeforeNow(completion)) {
            LOGGER.debug("Task {} should be deleted no earlier than {}, not deleting it.", completedTask, completion);
            // set 'cleanupAfterCompletion' after the task was completed. Let's jut ignore this situation.
            return;
        }
        LOGGER.debug("Deleting completed task {}", completedTask);
        taskManager.deleteTask(object.getOid(), result);
    } catch (CommonException | RuntimeException | Error e) {
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't delete completed task {}", e, object);
    // do not retry this trigger execution
    }
}
Also used : XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) TaskType(com.evolveum.midpoint.xml.ns._public.common.common_3.TaskType) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Aggregations

CommonException (com.evolveum.midpoint.util.exception.CommonException)71 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)44 Task (com.evolveum.midpoint.task.api.Task)33 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 SystemException (com.evolveum.midpoint.util.exception.SystemException)14 ArrayList (java.util.ArrayList)12 ModelService (com.evolveum.midpoint.model.api.ModelService)11 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)8 NotNull (org.jetbrains.annotations.NotNull)7 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)6 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)5 ActivityRunException (com.evolveum.midpoint.repo.common.activity.run.ActivityRunException)5 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)5 RestartResponseException (org.apache.wicket.RestartResponseException)5 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)4 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)4 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)4 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)4 MidPointApplication (com.evolveum.midpoint.web.security.MidPointApplication)4 com.evolveum.midpoint.xml.ns._public.common.common_3 (com.evolveum.midpoint.xml.ns._public.common.common_3)4