Search in sources :

Example 1 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class ResourceCredentialsEditor method createPasswordPolicyList.

private List<ObjectReferenceType> createPasswordPolicyList() {
    passPolicyMap.clear();
    OperationResult result = new OperationResult(OPERATION_LOAD_PASSWORD_POLICIES);
    Task task = getPageBase().createSimpleTask(OPERATION_LOAD_PASSWORD_POLICIES);
    List<PrismObject<ValuePolicyType>> policies = null;
    List<ObjectReferenceType> references = new ArrayList<>();
    try {
        policies = getPageBase().getModelService().searchObjects(ValuePolicyType.class, new ObjectQuery(), null, task, result);
        result.recomputeStatus();
    } catch (CommonException | RuntimeException e) {
        result.recordFatalError("Couldn't load password policies.", e);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load password policies", e);
    }
    if (policies != null) {
        ObjectReferenceType ref;
        for (PrismObject<ValuePolicyType> policy : policies) {
            passPolicyMap.put(policy.getOid(), WebComponentUtil.getName(policy));
            ref = new ObjectReferenceType();
            ref.setType(ValuePolicyType.COMPLEX_TYPE);
            ref.setOid(policy.getOid());
            references.add(ref);
        }
    }
    return references;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectQuery(com.evolveum.midpoint.prism.query.ObjectQuery) PrismObject(com.evolveum.midpoint.prism.PrismObject) CommonException(com.evolveum.midpoint.util.exception.CommonException)

Example 2 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageAdminObjectDetails method saveOrPreviewPerformed.

public void saveOrPreviewPerformed(AjaxRequestTarget target, OperationResult result, boolean previewOnly) {
    boolean isAnythingChanged = processDeputyAssignments();
    ObjectWrapper<O> objectWrapper = getObjectWrapper();
    LOGGER.debug("Saving object {}", objectWrapper);
    // todo: improve, delta variable is quickfix for MID-1006
    // redirecting to user list page everytime user is created in repository
    // during user add in gui,
    // and we're not taking care about account/assignment create errors
    // (error message is still displayed)
    delta = null;
    Task task = createSimpleTask(OPERATION_SEND_TO_SUBMIT);
    ModelExecuteOptions options = getExecuteChangesOptions();
    LOGGER.debug("Using execute options {}.", new Object[] { options });
    try {
        reviveModels();
        delta = objectWrapper.getObjectDelta();
        if (objectWrapper.getOldDelta() != null) {
            delta = ObjectDelta.summarize(objectWrapper.getOldDelta(), delta);
        }
        if (LOGGER.isTraceEnabled()) {
            LOGGER.trace("User delta computed from form:\n{}", new Object[] { delta.debugDump(3) });
        }
    } catch (Exception ex) {
        result.recordFatalError(getString("pageUser.message.cantCreateUser"), ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
        showResult(result);
        return;
    }
    switch(objectWrapper.getStatus()) {
        case ADDING:
            try {
                PrismObject<O> objectToAdd = delta.getObjectToAdd();
                WebComponentUtil.encryptCredentials(objectToAdd, true, getMidpointApplication());
                prepareObjectForAdd(objectToAdd);
                getPrismContext().adopt(objectToAdd, getCompileTimeClass());
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before add user:\n{}", new Object[] { delta.debugDump(3) });
                }
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    final Collection<ObjectDelta<? extends ObjectType>> deltas = WebComponentUtil.createDeltaCollection(delta);
                    final Collection<SimpleValidationError> validationErrors = performCustomValidation(objectToAdd, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else {
                    result.recordSuccess();
                }
            } catch (Exception ex) {
                result.recordFatalError(getString("pageFocus.message.cantCreateFocus"), ex);
                LoggingUtils.logUnexpectedException(LOGGER, "Create user failed", ex);
                showResult(result);
            }
            break;
        case MODIFYING:
            try {
                WebComponentUtil.encryptCredentials(delta, true, getMidpointApplication());
                prepareObjectDeltaForModify(delta);
                if (LOGGER.isTraceEnabled()) {
                    LOGGER.trace("Delta before modify user:\n{}", new Object[] { delta.debugDump(3) });
                }
                Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
                if (!delta.isEmpty()) {
                    delta.revive(getPrismContext());
                    deltas.add(delta);
                }
                List<ObjectDelta<? extends ObjectType>> additionalDeltas = getAdditionalModifyDeltas(result);
                if (additionalDeltas != null) {
                    for (ObjectDelta additionalDelta : additionalDeltas) {
                        if (!additionalDelta.isEmpty()) {
                            additionalDelta.revive(getPrismContext());
                            deltas.add(additionalDelta);
                        }
                    }
                }
                if (delta.isEmpty() && ModelExecuteOptions.isReconcile(options)) {
                    ObjectDelta emptyDelta = ObjectDelta.createEmptyModifyDelta(getCompileTimeClass(), objectWrapper.getObject().getOid(), getPrismContext());
                    deltas.add(emptyDelta);
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else if (!deltas.isEmpty()) {
                    Collection<SimpleValidationError> validationErrors = performCustomValidation(null, deltas);
                    if (checkValidationErrors(target, validationErrors)) {
                        return;
                    }
                    progressReporter.executeChanges(deltas, previewOnly, options, task, result, target);
                } else {
                    // from previous attempts (useful only if we would call finishProcessing at the end, but that's not the case now)
                    progressReporter.clearProgressPanel();
                    if (!previewOnly) {
                        if (!isAnythingChanged) {
                            result.recordWarning(getString("PageAdminObjectDetails.noChangesSave"));
                            showResult(result);
                        }
                        redirectBack();
                    } else {
                        warn(getString("PageAdminObjectDetails.noChangesPreview"));
                        target.add(getFeedbackPanel());
                    }
                }
            } catch (Exception ex) {
                if (!executeForceDelete(objectWrapper, task, options, result)) {
                    result.recordFatalError(getString("pageUser.message.cantUpdateUser"), ex);
                    LoggingUtils.logUnexpectedException(LOGGER, getString("pageUser.message.cantUpdateUser"), ex);
                } else {
                    result.recomputeStatus();
                }
                showResult(result);
            }
            break;
        // support for add/delete containers (e.g. delete credentials)
        default:
            error(getString("pageAdminFocus.message.unsupportedState", objectWrapper.getStatus()));
    }
    //		result.recomputeStatus();
    //
    //		if (!result.isInProgress()) {
    //			LOGGER.trace("Result NOT in progress, calling finishProcessing");
    //			finishProcessing(target, result, false);
    //		}
    LOGGER.trace("returning from saveOrPreviewPerformed");
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ArrayList(java.util.ArrayList) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) SimpleValidationError(com.evolveum.midpoint.web.util.validation.SimpleValidationError)

Example 3 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageAdminObjectDetails method loadObjectWrapper.

protected ObjectWrapper<O> loadObjectWrapper(PrismObject<O> objectToEdit) {
    Task task = createSimpleTask(OPERATION_LOAD_OBJECT);
    OperationResult result = task.getResult();
    PrismObject<O> object = null;
    Collection<SelectorOptions<GetOperationOptions>> loadOptions = null;
    try {
        if (!isEditingFocus()) {
            if (objectToEdit == null) {
                LOGGER.trace("Loading object: New object (creating)");
                O focusType = createNewObject();
                getMidpointApplication().getPrismContext().adopt(focusType);
                object = (PrismObject<O>) focusType.asPrismObject();
            } else {
                LOGGER.trace("Loading object: New object (supplied): {}", objectToEdit);
                object = objectToEdit;
            }
        } else {
            loadOptions = SelectorOptions.createCollection(UserType.F_JPEG_PHOTO, GetOperationOptions.createRetrieve(RetrieveOption.INCLUDE));
            String focusOid = getObjectOidParameter();
            object = WebModelServiceUtils.loadObject(getCompileTimeClass(), focusOid, loadOptions, this, task, result);
            LOGGER.trace("Loading object: Existing object (loadled): {} -> {}", focusOid, object);
        }
        result.recordSuccess();
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get object.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load object", ex);
    }
    showResult(result, false);
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Loaded object:\n{}", object.debugDump());
    }
    if (object == null) {
        if (isEditingFocus()) {
            getSession().error(getString("pageAdminFocus.message.cantEditFocus"));
        } else {
            getSession().error(getString("pageAdminFocus.message.cantNewFocus"));
        }
        throw new RestartResponseException(getRestartResponsePage());
    }
    ContainerStatus status = isEditingFocus() ? ContainerStatus.MODIFYING : ContainerStatus.ADDING;
    ObjectWrapper<O> wrapper;
    ObjectWrapperFactory owf = new ObjectWrapperFactory(this);
    try {
        wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, status, task);
    } catch (Exception ex) {
        result.recordFatalError("Couldn't get user.", ex);
        LoggingUtils.logUnexpectedException(LOGGER, "Couldn't load user", ex);
        wrapper = owf.createObjectWrapper("pageAdminFocus.focusDetails", null, object, null, null, status, false);
    }
    wrapper.setLoadOptions(loadOptions);
    showResult(wrapper.getResult(), false);
    loadParentOrgs(wrapper, task, result);
    wrapper.setShowEmpty(!isEditingFocus());
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Loaded focus wrapper:\n{}", wrapper.debugDump());
    }
    return wrapper;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) ContainerStatus(com.evolveum.midpoint.web.component.prism.ContainerStatus) SelectorOptions(com.evolveum.midpoint.schema.SelectorOptions) RestartResponseException(org.apache.wicket.RestartResponseException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ObjectWrapperFactory(com.evolveum.midpoint.web.component.prism.ObjectWrapperFactory) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) AuthorizationException(com.evolveum.midpoint.util.exception.AuthorizationException) RestartResponseException(org.apache.wicket.RestartResponseException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) SystemException(com.evolveum.midpoint.util.exception.SystemException)

Example 4 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageAdminFocus method loadSubwrappers.

private <S extends ObjectType> List<FocusSubwrapperDto<S>> loadSubwrappers(Class<S> type, QName propertyToLoad, boolean noFetch) {
    List<FocusSubwrapperDto<S>> list = new ArrayList<>();
    ObjectWrapper<F> focusWrapper = getObjectModel().getObject();
    PrismObject<F> focus = focusWrapper.getObject();
    PrismReference prismReference = focus.findReference(new ItemPath(propertyToLoad));
    if (prismReference == null) {
        return new ArrayList<>();
    }
    List<PrismReferenceValue> references = prismReference.getValues();
    Task task = createSimpleTask(OPERATION_LOAD_SHADOW);
    for (PrismReferenceValue reference : references) {
        FocusSubwrapperDto<S> subWrapper = loadSubWrapperDto(type, reference.getOid(), noFetch, task);
        if (subWrapper != null) {
            list.add(subWrapper);
        }
    }
    return list;
}
Also used : Task(com.evolveum.midpoint.task.api.Task) FocusSubwrapperDto(com.evolveum.midpoint.web.page.admin.users.dto.FocusSubwrapperDto) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 5 with Task

use of com.evolveum.midpoint.task.api.Task in project midpoint by Evolveum.

the class PageSecurityQuestions method loadPageModel.

private PasswordQuestionsDto loadPageModel() {
    LOGGER.debug("Loading user.");
    final String userOid = getPageParameters().get(SESSION_ATTRIBUTE_POID).toString();
    PrismObject<UserType> user = runPrivileged(new Producer<PrismObject<UserType>>() {

        @Override
        public PrismObject<UserType> run() {
            Task task = createAnonymousTask(OPERATION_LOAD_USER);
            OperationResult subResult = task.getResult();
            try {
                Collection<SelectorOptions<GetOperationOptions>> options = SelectorOptions.createCollection(GetOperationOptions.createNoFetch());
                return getModelService().getObject(UserType.class, userOid, options, task, subResult);
            } catch (ObjectNotFoundException | SchemaException | SecurityViolationException | CommunicationException | ConfigurationException | ExpressionEvaluationException e) {
                LOGGER.error("Error getting user {}: {}", userOid, e.getMessage(), e);
                // we do not want to provide any information to the attacker.
                return null;
            }
        }
    });
    principalModel.setObject(user);
    PasswordQuestionsDto dto = new PasswordQuestionsDto();
    dto.setSecurityAnswers(createUsersSecurityQuestionsList(user));
    return dto;
}
Also used : PrismObject(com.evolveum.midpoint.prism.PrismObject) Task(com.evolveum.midpoint.task.api.Task) GetOperationOptions(com.evolveum.midpoint.schema.GetOperationOptions) Collection(java.util.Collection) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) PasswordQuestionsDto(com.evolveum.midpoint.web.page.admin.home.dto.PasswordQuestionsDto)

Aggregations

Task (com.evolveum.midpoint.task.api.Task)4943 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)4698 Test (org.testng.annotations.Test)3991 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)599 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)542 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)464 PrismObject (com.evolveum.midpoint.prism.PrismObject)327 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)323 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)290 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)282 ArrayList (java.util.ArrayList)249 QName (javax.xml.namespace.QName)208 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)199 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)193 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)175 DummyAccount (com.evolveum.icf.dummy.resource.DummyAccount)159 AbstractConfiguredModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractConfiguredModelIntegrationTest)140 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)123 SelectorOptions (com.evolveum.midpoint.schema.SelectorOptions)108 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)108