Search in sources :

Example 1 with SecurityEnforcer

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

the class ProgressReporter method executeChangesAsync.

private void executeChangesAsync(final Collection<ObjectDelta<? extends ObjectType>> deltas, final boolean previewOnly, final ModelExecuteOptions options, final Task task, final OperationResult result, AjaxRequestTarget target, final ModelService modelService, final ModelInteractionService modelInteractionService) {
    final SecurityEnforcer enforcer = parentPage.getSecurityEnforcer();
    final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    asyncOperationResult = null;
    clearProgressPanel();
    startRefreshingProgressPanel(target);
    showProgressPanel();
    progressPanel.setTask(task);
    progressListener = new DefaultGuiProgressListener(parentPage, progressPanel.getModelObject());
    final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    Runnable execution = () -> {
        try {
            enforcer.storeConnectionInformation(connInfo);
            enforcer.setupPreAuthenticatedSecurityContext(authentication);
            progressPanel.recordExecutionStart();
            if (previewOnly) {
                previewResult = modelInteractionService.previewChanges(deltas, options, task, Collections.singleton(progressListener), result);
            } else {
                modelService.executeChanges(deltas, options, task, Collections.singleton(progressListener), result);
            }
        } catch (CommunicationException | ObjectAlreadyExistsException | ExpressionEvaluationException | PolicyViolationException | SchemaException | SecurityViolationException | ConfigurationException | ObjectNotFoundException | RuntimeException e) {
            LoggingUtils.logUnexpectedException(LOGGER, "Error executing changes", e);
            if (!result.isFatalError()) {
                // just to be sure the exception is recorded into the result
                result.recordFatalError(e.getMessage(), e);
            }
        }
        progressPanel.recordExecutionStop();
        // signals that the operation has finished
        asyncOperationResult = result;
    };
    if (abortEnabled) {
        showAbortButton(target);
    }
    showBackButton(target);
    // to disable showing not-final results (why does it work? and why is the result shown otherwise?)
    result.recordInProgress();
    asyncExecutionThread = new Thread(execution);
    asyncExecutionThread.start();
}
Also used : HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) Authentication(org.springframework.security.core.Authentication) DefaultGuiProgressListener(com.evolveum.midpoint.web.page.admin.users.DefaultGuiProgressListener) SecurityEnforcer(com.evolveum.midpoint.security.api.SecurityEnforcer)

Aggregations

HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)1 SecurityEnforcer (com.evolveum.midpoint.security.api.SecurityEnforcer)1 DefaultGuiProgressListener (com.evolveum.midpoint.web.page.admin.users.DefaultGuiProgressListener)1 Authentication (org.springframework.security.core.Authentication)1