Search in sources :

Example 1 with ProgressReporter

use of com.evolveum.midpoint.web.component.progress.ProgressReporter in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChanges.

/**
 * Executes changes on behalf of the parent page. By default, changes are executed asynchronously (in
 * a separate thread). However, when set in the midpoint configuration, changes are executed synchronously.
 *
 * @param deltas  Deltas to be executed.
 * @param options Model execution options.
 * @param task    Task in context of which the changes have to be executed.
 * @param result  Operation result.
 */
public Collection<ObjectDeltaOperation<? extends ObjectType>> executeChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result, AjaxRequestTarget target) {
    ProgressPanel progressPanel = progressAwarePage.startAndGetProgressPanel(target, result);
    ProgressReporter reporter = progressPanel.getReporterModel().getProcessData();
    if (reporter.isAsynchronousExecution()) {
        reporter.setAsyncOperationResult(null);
        progressPanel.setTask(task);
        executeChangesAsync(progressPanel, deltas, previewOnly, options, task, result);
    } else {
        executeChangesSync(reporter, deltas, previewOnly, options, task, result);
    }
    if (!reporter.isAsynchronousExecution()) {
        progressAwarePage.finishProcessing(target, reporter.isAsynchronousExecution(), result);
    }
    return reporter.getObjectDeltaOperation();
}
Also used : ProgressPanel(com.evolveum.midpoint.gui.impl.page.admin.component.ProgressPanel) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter)

Example 2 with ProgressReporter

use of com.evolveum.midpoint.web.component.progress.ProgressReporter in project midpoint by Evolveum.

the class ProgressAwareChangesExecutorImpl method executeChangesAsync.

private void executeChangesAsync(ProgressPanel progressPanel, Collection<ObjectDelta<? extends ObjectType>> deltas, boolean previewOnly, ModelExecuteOptions options, Task task, OperationResult result) {
    MidPointApplication application = MidPointApplication.get();
    final ModelInteractionService modelInteraction = application.getModelInteractionService();
    final ModelService model = application.getModel();
    final SecurityContextManager secManager = application.getSecurityContextManager();
    final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
    final HttpConnectionInformation connInfo = SecurityUtil.getCurrentConnectionInformation();
    AsyncWebProcessModel<ProgressReporter> reporterModel = progressPanel.getReporterModel();
    Callable<Void> execution = new SecurityContextAwareCallable<>(secManager, auth, connInfo) {

        @Override
        public Void callWithContextPrepared() {
            ProgressReporter reporter = reporterModel.getProcessData();
            try {
                LOGGER.debug("Execution start");
                reporter.recordExecutionStart();
                if (previewOnly) {
                    ModelContext previewResult = modelInteraction.previewChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setPreviewResult(previewResult);
                } else if (deltas != null && deltas.size() > 0) {
                    Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = model.executeChanges(deltas, options, task, Collections.singleton(reporter), result);
                    reporter.setObjectDeltaOperation(executedDeltas);
                }
            } catch (CommonException | 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);
                }
            } finally {
                LOGGER.debug("Execution finish {}", result);
            }
            reporter.recordExecutionStop();
            // signals that the operation has finished
            reporter.setAsyncOperationResult(result);
            return null;
        }
    };
    // to disable showing not-final results (why does it work? and why is the result shown otherwise?)
    result.setInProgress();
    AsyncWebProcessManager manager = application.getAsyncWebProcessManager();
    manager.submit(reporterModel.getId(), execution);
}
Also used : ModelInteractionService(com.evolveum.midpoint.model.api.ModelInteractionService) SecurityContextAwareCallable(com.evolveum.midpoint.web.component.SecurityContextAwareCallable) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter) ModelService(com.evolveum.midpoint.model.api.ModelService) ModelContext(com.evolveum.midpoint.model.api.context.ModelContext) MidPointApplication(com.evolveum.midpoint.web.security.MidPointApplication) HttpConnectionInformation(com.evolveum.midpoint.security.api.HttpConnectionInformation) Authentication(org.springframework.security.core.Authentication) Collection(java.util.Collection) AsyncWebProcessManager(com.evolveum.midpoint.web.application.AsyncWebProcessManager) CommonException(com.evolveum.midpoint.util.exception.CommonException) SecurityContextManager(com.evolveum.midpoint.security.api.SecurityContextManager)

Example 3 with ProgressReporter

use of com.evolveum.midpoint.web.component.progress.ProgressReporter in project midpoint by Evolveum.

the class PageAbstractSelfCredentials method onSavePerformed.

protected void onSavePerformed(AjaxRequestTarget target) {
    Component actualTab = getActualTabPanel();
    if (actualTab instanceof ChangePasswordPanel) {
        ProtectedStringType oldPassword = null;
        if (isCheckOldPassword()) {
            LOGGER.debug("Check old password");
            MyPasswordsDto modelObject = getPasswordDto();
            if (modelObject.getOldPassword() == null || modelObject.getOldPassword().trim().equals("")) {
                warn(getString("PageSelfCredentials.specifyOldPasswordMessage"));
                target.add(getFeedbackPanel());
                return;
            } else {
                OperationResult checkPasswordResult = new OperationResult(OPERATION_CHECK_PASSWORD);
                Task checkPasswordTask = createSimpleTask(OPERATION_CHECK_PASSWORD);
                try {
                    oldPassword = new ProtectedStringType();
                    oldPassword.setClearValue(modelObject.getOldPassword());
                    boolean isCorrectPassword = getModelInteractionService().checkPassword(modelObject.getFocusOid(), oldPassword, checkPasswordTask, checkPasswordResult);
                    if (!isCorrectPassword) {
                        error(getString("PageSelfCredentials.incorrectOldPassword"));
                        target.add(getFeedbackPanel());
                        return;
                    }
                } catch (Exception ex) {
                    LoggingUtils.logUnexpectedException(LOGGER, "Couldn't check password", ex);
                    checkPasswordResult.recordFatalError(getString("PageAbstractSelfCredentials.message.onSavePerformed.fatalError", ex.getMessage()), ex);
                    target.add(getFeedbackPanel());
                    return;
                } finally {
                    checkPasswordResult.computeStatus();
                }
            }
        }
        if (getPasswordDto().getPassword() == null) {
            warn(getString("PageSelfCredentials.emptyPasswordFiled"));
            target.add(getFeedbackPanel());
            return;
        }
        List<PasswordAccountDto> selectedAccounts = getSelectedAccountsList();
        if (selectedAccounts.isEmpty()) {
            warn(getString("PageSelfCredentials.noAccountSelected"));
            target.add(getFeedbackPanel());
            return;
        }
        OperationResult result = new OperationResult(OPERATION_SAVE_PASSWORD);
        ProgressReporter reporter = new ProgressReporter(MidPointApplication.get());
        reporter.getProgress().clear();
        reporter.setWriteOpResultForProgressActivity(true);
        reporter.recordExecutionStart();
        boolean showFeedback = true;
        try {
            MyPasswordsDto dto = getPasswordDto();
            ProtectedStringType password = dto.getPassword();
            if (!password.isEncrypted()) {
                WebComponentUtil.encryptProtectedString(password, true, getMidpointApplication());
            }
            final ItemPath valuePath = ItemPath.create(SchemaConstantsGenerated.C_CREDENTIALS, CredentialsType.F_PASSWORD, PasswordType.F_VALUE);
            SchemaRegistry registry = getPrismContext().getSchemaRegistry();
            Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
            for (PasswordAccountDto accDto : selectedAccounts) {
                PrismObjectDefinition objDef = accDto.isMidpoint() ? registry.findObjectDefinitionByCompileTimeClass(UserType.class) : registry.findObjectDefinitionByCompileTimeClass(ShadowType.class);
                PropertyDelta<ProtectedStringType> delta = getPrismContext().deltaFactory().property().createModificationReplaceProperty(valuePath, objDef, password);
                if (oldPassword != null) {
                    delta.addEstimatedOldValue(getPrismContext().itemFactory().createPropertyValue(oldPassword));
                }
                Class<? extends ObjectType> type = accDto.isMidpoint() ? UserType.class : ShadowType.class;
                deltas.add(getPrismContext().deltaFactory().object().createModifyDelta(accDto.getOid(), delta, type));
            }
            getModelService().executeChanges(deltas, null, createSimpleTask(OPERATION_SAVE_PASSWORD, SchemaConstants.CHANNEL_SELF_SERVICE_URI), Collections.singleton(reporter), result);
            result.computeStatus();
        } catch (Exception ex) {
            setNullEncryptedPasswordData();
            LoggingUtils.logUnexpectedException(LOGGER, "Couldn't save password changes", ex);
            result.recordFatalError(getString("PageAbstractSelfCredentials.save.password.failed", ex.getMessage()), ex);
        } finally {
            reporter.recordExecutionStop();
            getPasswordDto().setProgress(reporter.getProgress());
            if (getActualTabPanel() != null) {
                ((ChangePasswordPanel) getActualTabPanel()).updateResultColumnOfTable(target);
            }
            result.computeStatusIfUnknown();
            if (shouldLoadAccounts()) {
                showFeedback = false;
                if (result.isError()) {
                    error(createStringResource("PageAbstractSelfCredentials.message.resultInTable.error").getString());
                } else {
                    success(createStringResource("PageAbstractSelfCredentials.message.resultInTable").getString());
                }
            }
            if (!result.isError()) {
                this.savedPassword = true;
                target.add(getSaveButton());
            }
        }
        finishChangePassword(result, target, showFeedback);
    } else if (actualTab instanceof SecurityQuestionsPanel) {
        ((SecurityQuestionsPanel) actualTab).onSavePerformed(target);
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) SecurityQuestionsPanel(com.evolveum.midpoint.web.page.self.component.SecurityQuestionsPanel) ChangePasswordPanel(com.evolveum.midpoint.web.page.self.component.ChangePasswordPanel) PrismObjectDefinition(com.evolveum.midpoint.prism.PrismObjectDefinition) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ProgressReporter(com.evolveum.midpoint.web.component.progress.ProgressReporter) PasswordAccountDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto) MyPasswordsDto(com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto) Component(org.apache.wicket.Component) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) SchemaRegistry(com.evolveum.midpoint.prism.schema.SchemaRegistry) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Aggregations

ProgressReporter (com.evolveum.midpoint.web.component.progress.ProgressReporter)3 ProgressPanel (com.evolveum.midpoint.gui.impl.page.admin.component.ProgressPanel)1 ModelInteractionService (com.evolveum.midpoint.model.api.ModelInteractionService)1 ModelService (com.evolveum.midpoint.model.api.ModelService)1 ModelContext (com.evolveum.midpoint.model.api.context.ModelContext)1 PrismObjectDefinition (com.evolveum.midpoint.prism.PrismObjectDefinition)1 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)1 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)1 SchemaRegistry (com.evolveum.midpoint.prism.schema.SchemaRegistry)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 HttpConnectionInformation (com.evolveum.midpoint.security.api.HttpConnectionInformation)1 SecurityContextManager (com.evolveum.midpoint.security.api.SecurityContextManager)1 Task (com.evolveum.midpoint.task.api.Task)1 CommonException (com.evolveum.midpoint.util.exception.CommonException)1 AsyncWebProcessManager (com.evolveum.midpoint.web.application.AsyncWebProcessManager)1 SecurityContextAwareCallable (com.evolveum.midpoint.web.component.SecurityContextAwareCallable)1 MyPasswordsDto (com.evolveum.midpoint.web.page.admin.home.dto.MyPasswordsDto)1 PasswordAccountDto (com.evolveum.midpoint.web.page.admin.home.dto.PasswordAccountDto)1 ChangePasswordPanel (com.evolveum.midpoint.web.page.self.component.ChangePasswordPanel)1 SecurityQuestionsPanel (com.evolveum.midpoint.web.page.self.component.SecurityQuestionsPanel)1