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();
}
}
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;
}
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;
}
}
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;
}
}
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
}
}
Aggregations