Search in sources :

Example 46 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class PageAccountActivation method propagatePassword.

private void propagatePassword(AjaxRequestTarget target, Form<?> form) {
    List<ShadowType> shadowsToActivate = getShadowsToActivate();
    PasswordTextField passwordPanel = (PasswordTextField) form.get(createComponentPath(ID_PASSWORD));
    String value = passwordPanel.getModelObject();
    ConnectionEnvironment connEnv = ConnectionEnvironment.create(SchemaConstants.CHANNEL_GUI_USER_URI);
    UsernamePasswordAuthenticationToken token;
    try {
        token = authenticationEvaluator.authenticate(connEnv, new PasswordAuthenticationContext(userModel.getObject().getName().getOrig(), value));
    } catch (Exception ex) {
        LOGGER.error("Failed to authenticate user, reason ", ex.getMessage());
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    if (token == null) {
        LOGGER.error("Failed to authenticate user");
        getSession().error(getString("PageAccountActivation.authentication.failed"));
        throw new RestartResponseException(PageAccountActivation.class, getPageParameters());
    }
    ProtectedStringType passwordValue = new ProtectedStringType();
    passwordValue.setClearValue(value);
    Collection<ObjectDelta<ShadowType>> passwordDeltas = new ArrayList<>(shadowsToActivate.size());
    for (ShadowType shadow : shadowsToActivate) {
        ObjectDelta<ShadowType> shadowDelta = ObjectDelta.createModificationReplaceProperty(ShadowType.class, shadow.getOid(), SchemaConstants.PATH_PASSWORD_VALUE, getPrismContext(), passwordValue);
        shadowDelta.addModificationReplaceProperty(ShadowType.F_LIFECYCLE_STATE, SchemaConstants.LIFECYCLE_PROPOSED);
        passwordDeltas.add(shadowDelta);
    }
    OperationResult result = runPrivileged(new Producer<OperationResult>() {

        @Override
        public OperationResult run() {
            OperationResult result = new OperationResult(OPERATION_ACTIVATE_SHADOWS);
            Task task = createAnonymousTask(OPERATION_ACTIVATE_SHADOWS);
            WebModelServiceUtils.save((Collection) passwordDeltas, null, result, task, PageAccountActivation.this);
            return result;
        }
    });
    result.recomputeStatus();
    if (!result.isSuccess()) {
        getSession().error(getString("PageAccountActivation.account.activation.failed"));
        LOGGER.error("Failed to acitvate accounts, reason: {} ", result.getMessage());
        target.add(getFeedbackPanel());
    } else {
        getSession().success(getString("PageAccountActivation.account.activation.successful"));
        target.add(getFeedbackPanel());
        activated = true;
    }
    target.add(PageAccountActivation.this);
}
Also used : PasswordAuthenticationContext(com.evolveum.midpoint.model.api.context.PasswordAuthenticationContext) Task(com.evolveum.midpoint.task.api.Task) ShadowType(com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType) ArrayList(java.util.ArrayList) PasswordTextField(org.apache.wicket.markup.html.form.PasswordTextField) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) ConnectionEnvironment(com.evolveum.midpoint.security.api.ConnectionEnvironment) RestartResponseException(org.apache.wicket.RestartResponseException) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 47 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class TestSchemaDelta method testSubtractAssignmentFromModifyDelta.

@Test
public void testSubtractAssignmentFromModifyDelta() throws Exception {
    final String TEST_NAME = "testSubtractAssignmentFromModifyDelta";
    displayTestTile(TEST_NAME);
    // GIVEN
    PrismObject<UserType> user = PrismTestUtil.parseObject(USER_BILL_FILE);
    user.asObjectable().getAssignment().get(0).setId(9999L);
    AssignmentType assignment9999 = new AssignmentType();
    assignment9999.setId(9999L);
    ObjectDelta<UserType> delta = (ObjectDelta<UserType>) DeltaBuilder.deltaFor(UserType.class, getPrismContext()).item(UserType.F_ASSIGNMENT).delete(assignment9999).asObjectDelta(user.getOid());
    // WHEN
    PrismContainerDefinition<AssignmentType> assignmentDef = PrismTestUtil.getSchemaRegistry().findContainerDefinitionByCompileTimeClass(AssignmentType.class).clone();
    ((PrismContainerDefinitionImpl) assignmentDef).setMaxOccurs(1);
    PrismContainer<AssignmentType> assignmentContainer = assignmentDef.instantiate();
    PrismContainerValue<AssignmentType> assignmentValue = ObjectTypeUtil.createAssignmentTo("00000001-d34d-b33f-f00d-000000000002", ObjectTypes.ROLE, getPrismContext()).asPrismContainerValue();
    assignmentValue.setId(9999L);
    assignmentContainer.add(assignmentValue);
    System.out.println("Delta before operation:\n" + delta.debugDump() + "\n");
    System.out.println("Assignment to subtract:\n" + assignmentValue.debugDump() + "\n");
    boolean removed = delta.subtract(SchemaConstants.PATH_ASSIGNMENT, assignmentValue, true, false);
    // THEN
    System.out.println("Delta after operation:\n" + delta.debugDump() + "\n");
    System.out.println("Removed: " + removed + "\n");
    assertTrue("Not removed", removed);
    assertTrue("Remaining delta is not a MODIFY delta", delta.isModify());
    assertEquals("Wrong # of remaining modifications", 0, delta.getModifications().size());
}
Also used : AssignmentType(com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 48 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method previewChanges.

@Override
public <F extends ObjectType> ModelContext<F> previewChanges(Collection<ObjectDelta<? extends ObjectType>> deltas, ModelExecuteOptions options, Task task, Collection<ProgressListener> listeners, OperationResult parentResult) throws SchemaException, PolicyViolationException, ExpressionEvaluationException, ObjectNotFoundException, ObjectAlreadyExistsException, CommunicationException, ConfigurationException, SecurityViolationException {
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Preview changes input:\n{}", DebugUtil.debugDump(deltas));
    }
    int size = 0;
    if (deltas != null) {
        size = deltas.size();
    }
    Collection<ObjectDelta<? extends ObjectType>> clonedDeltas = new ArrayList<>(size);
    if (deltas != null) {
        for (ObjectDelta delta : deltas) {
            clonedDeltas.add(delta.clone());
        }
    }
    OperationResult result = parentResult.createSubresult(PREVIEW_CHANGES);
    LensContext<F> context;
    try {
        RepositoryCache.enter();
        //used cloned deltas instead of origin deltas, because some of the values should be lost later..
        context = contextFactory.createContext(clonedDeltas, options, task, result);
        //			context.setOptions(options);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.trace("Preview changes context:\n{}", context.debugDump());
        }
        context.setProgressListeners(listeners);
        projector.projectAllWaves(context, "preview", task, result);
        context.distributeResource();
    } catch (ConfigurationException | SecurityViolationException | ObjectNotFoundException | SchemaException | CommunicationException | PolicyViolationException | RuntimeException | ObjectAlreadyExistsException | ExpressionEvaluationException e) {
        ModelUtils.recordFatalError(result, e);
        throw e;
    } finally {
        RepositoryCache.exit();
    }
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Preview changes output:\n{}", context.debugDump());
    }
    result.computeStatus();
    result.cleanupResult();
    return context;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ExpressionEvaluationException(com.evolveum.midpoint.util.exception.ExpressionEvaluationException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) CommunicationException(com.evolveum.midpoint.util.exception.CommunicationException) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) ConfigurationException(com.evolveum.midpoint.util.exception.ConfigurationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) PolicyViolationException(com.evolveum.midpoint.util.exception.PolicyViolationException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)

Example 49 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class ObjectImporter method addObject.

private <T extends ObjectType> String addObject(PrismObject<T> object, boolean overwrite, boolean noCrypt, boolean raw, Task task, OperationResult parentResult) throws ObjectAlreadyExistsException, SchemaException, ObjectNotFoundException, ExpressionEvaluationException, CommunicationException, ConfigurationException, PolicyViolationException, SecurityViolationException {
    ObjectDelta<T> delta = ObjectDelta.createAddDelta(object);
    Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(delta);
    ModelExecuteOptions options = new ModelExecuteOptions();
    options.setRaw(raw);
    if (overwrite) {
        options.setOverwrite(true);
    }
    if (noCrypt) {
        options.setNoCrypt(true);
    }
    modelService.executeChanges(deltas, options, task, parentResult);
    return deltas.iterator().next().getOid();
}
Also used : ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta)

Example 50 with ObjectDelta

use of com.evolveum.midpoint.prism.delta.ObjectDelta in project midpoint by Evolveum.

the class PageDebugView method savePerformed.

public void savePerformed(AjaxRequestTarget target) {
    ObjectViewDto dto = model.getObject();
    if (StringUtils.isEmpty(dto.getXml())) {
        error(getString("pageDebugView.message.cantSaveEmpty"));
        target.add(getFeedbackPanel());
        return;
    }
    Task task = createSimpleTask(OPERATION_SAVE_OBJECT);
    OperationResult result = task.getResult();
    try {
        PrismObject<ObjectType> oldObject = dto.getObject();
        oldObject.revive(getPrismContext());
        Holder<PrismObject<ObjectType>> objectHolder = new Holder<>(null);
        validateObject(result, objectHolder);
        if (result.isAcceptable()) {
            PrismObject<ObjectType> newObject = objectHolder.getValue();
            ObjectDelta<ObjectType> delta = oldObject.diff(newObject, true, true);
            if (delta.getPrismContext() == null) {
                LOGGER.warn("No prism context in delta {} after diff, adding it", delta);
                delta.revive(getPrismContext());
            }
            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Delta to be applied:\n{}", delta.debugDump());
            }
            //quick fix for now (MID-1910), maybe it should be somewhere in model..
            //                if (isReport(oldObject)){
            //                	ReportTypeUtil.applyConfigurationDefinition((PrismObject)newObject, delta, getPrismContext());
            //                }
            Collection<ObjectDelta<? extends ObjectType>> deltas = (Collection) MiscUtil.createCollection(delta);
            ModelExecuteOptions options = new ModelExecuteOptions();
            if (saveAsRaw.getObject()) {
                options.setRaw(true);
            }
            if (reevaluateSearchFilters.getObject()) {
                options.setReevaluateSearchFilters(true);
            }
            if (!encrypt.getObject()) {
                options.setNoCrypt(true);
            }
            getModelService().executeChanges(deltas, options, task, result);
            result.computeStatus();
        }
    } catch (Exception ex) {
        result.recordFatalError("Couldn't save object.", ex);
    }
    if (result.isError()) {
        showResult(result);
        target.add(getFeedbackPanel());
    } else {
        showResult(result);
        redirectBack();
    }
}
Also used : Task(com.evolveum.midpoint.task.api.Task) Holder(com.evolveum.midpoint.util.Holder) ModelExecuteOptions(com.evolveum.midpoint.model.api.ModelExecuteOptions) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RestartResponseException(org.apache.wicket.RestartResponseException) PrismObject(com.evolveum.midpoint.prism.PrismObject) Collection(java.util.Collection) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) ObjectViewDto(com.evolveum.midpoint.web.page.admin.dto.ObjectViewDto)

Aggregations

ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)445 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)363 Task (com.evolveum.midpoint.task.api.Task)326 Test (org.testng.annotations.Test)303 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)242 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)218 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)148 ArrayList (java.util.ArrayList)126 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)103 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)55 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)47 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)42 ReferenceDelta (com.evolveum.midpoint.prism.delta.ReferenceDelta)41 AbstractInitializedModelIntegrationTest (com.evolveum.midpoint.model.intest.AbstractInitializedModelIntegrationTest)38 ShadowDiscriminatorObjectDelta (com.evolveum.midpoint.common.refinery.ShadowDiscriminatorObjectDelta)32 ModelExecuteOptions (com.evolveum.midpoint.model.api.ModelExecuteOptions)31 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)31 Collection (java.util.Collection)31 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)31 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)26