Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/Evolveum/midpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Mar 5, 2019
2 parents 7e6a04d + 94a5624 commit bbdae7c
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 52 deletions.
Expand Up @@ -34,6 +34,7 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.processor.ResourceAttributeDefinition;
import com.evolveum.midpoint.schema.util.ResourceTypeUtil;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.component.search.Search;
Expand Down Expand Up @@ -97,7 +98,7 @@ private <T extends ObjectType> List<SearchItemDefinition> createAttributeDefinit

ItemPath attributePath = ShadowType.F_ATTRIBUTES;

for (ItemDefinition def : (List<ItemDefinition>) ocDef.getDefinitions()) {
for (ResourceAttributeDefinition def : ocDef.getAttributeDefinitions()) {
if (!(def instanceof PrismPropertyDefinition) && !(def instanceof PrismReferenceDefinition)) {
continue;
}
Expand Down
Expand Up @@ -345,6 +345,10 @@ protected void cleanUpSecurity() {
securityContext.setAuthentication(null);
}

protected void initDummyResource(String name, DummyResourceContoller controller) {
dummyResourceCollection.initDummyResource(name, controller);
}

protected DummyResourceContoller initDummyResource(String name, File resourceFile, String resourceOid,
FailableProcessor<DummyResourceContoller> controllerInitLambda,
Task task, OperationResult result) throws Exception {
Expand Down Expand Up @@ -3676,7 +3680,7 @@ protected <O extends ObjectType> String addObject(PrismObject<O> object, ModelEx
ObjectDelta<O> addDelta = object.createAddDelta();
assertFalse("Immutable object provided?",addDelta.getObjectToAdd().isImmutable());
Collection<ObjectDeltaOperation<? extends ObjectType>> executedDeltas = executeChanges(addDelta, options, task, result);
object.setOid(ObjectDeltaOperation.findFocusDeltaOidInCollection(executedDeltas));
object.setOid(ObjectDeltaOperation.findAddDeltaOid(executedDeltas, object));
return object.getOid();
}

Expand Down
Expand Up @@ -75,6 +75,13 @@ public DummyResourceContoller initDummyResource(String name, File resourceFile,
map.put(name, controller);
return controller;
}

public void initDummyResource(String name, DummyResourceContoller controller) {
if (map.containsKey(name)) {
throw new IllegalArgumentException("Dummy resource "+name+" already initialized");
}
map.put(name, controller);
}

public DummyResourceContoller get(String name) {
DummyResourceContoller contoller = map.get(name);
Expand Down
Expand Up @@ -16,6 +16,7 @@
package com.evolveum.midpoint.provisioning.impl;

import java.util.Collection;
import java.util.List;

import javax.xml.namespace.QName;

Expand Down Expand Up @@ -96,12 +97,14 @@ public void checkAdd(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Op
result.recordSuccess();
}

public void checkModify(ResourceType resource, PrismObject<ShadowType> shadow,
Collection<? extends ItemDelta> modifications, RefinedObjectClassDefinition objectClassDefinition,
OperationResult parentResult) throws SecurityViolationException, SchemaException {
public void checkModify(ProvisioningContext ctx, PrismObject<ShadowType> shadow,
Collection<? extends ItemDelta> modifications,
OperationResult parentResult) throws SecurityViolationException, SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {

RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();

OperationResult result = parentResult.createMinorSubresult(OPERATION_NAME);
for (ItemDelta modification: modifications) {
for (ItemDelta<?,?> modification: modifications) {
if (!(modification instanceof PropertyDelta<?>)) {
continue;
}
Expand All @@ -111,6 +114,7 @@ public void checkModify(ResourceType resource, PrismObject<ShadowType> shadow,
continue;
}
QName attrName = attrDelta.getElementName();
LOGGER.trace("Checking attribue {} definition present in {}", attrName, objectClassDefinition);
RefinedAttributeDefinition attrDef = objectClassDefinition.findAttributeDefinition(attrName);
if (attrDef == null) {
throw new SchemaException("Cannot find definition of attribute "+attrName+" in "+objectClassDefinition);
Expand Down
Expand Up @@ -923,7 +923,7 @@ public String modifyShadow(PrismObject<ShadowType> repoShadow,

Collection<QName> additionalAuxiliaryObjectClassQNames = new ArrayList<>();
for (ItemDelta modification : modifications) {
if (ShadowType.F_AUXILIARY_OBJECT_CLASS.equals(modification.getPath())) {
if (ShadowType.F_AUXILIARY_OBJECT_CLASS.equivalent(modification.getPath())) {
PropertyDelta<QName> auxDelta = (PropertyDelta<QName>) modification;
for (PrismPropertyValue<QName> pval : auxDelta.getValues(QName.class)) {
additionalAuxiliaryObjectClassQNames.add(pval.getValue());
Expand Down Expand Up @@ -959,8 +959,7 @@ private String modifyShadowAttempt(ProvisioningContext ctx,

shadowCaretaker.applyAttributesDefinition(ctx, repoShadow);

accessChecker.checkModify(ctx.getResource(), repoShadow, modifications,
ctx.getObjectClassDefinition(), parentResult);
accessChecker.checkModify(ctx, repoShadow, modifications, parentResult);

XMLGregorianCalendar now = clock.currentTimeXMLGregorianCalendar();

Expand Down
Expand Up @@ -180,7 +180,7 @@ public void test010importActiveUserRUR() throws Exception {

@Test
public void test011importInactiveUserChappie() throws Exception {
final String TEST_NAME = "test020ResourceOpenDjGet";
final String TEST_NAME = "test011importInactiveUserChappie";
TestUtil.displayTestTitle(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestTrafo.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Expand Down
Expand Up @@ -397,7 +397,7 @@ public void test100changePasswordForceChange() throws Exception {
passwd = new ProtectedStringType();
passwd.setClearValue("somenewValue");
userDelta = createModifyUserReplaceDelta(USER_JACK_OID, SchemaConstants.PATH_PASSWORD_VALUE, passwd);
userDelta.addModificationReplaceProperty(SchemaConstants.PATH_PASSWORD, PasswordType.F_FORCE_CHANGE, Boolean.TRUE);
userDelta.addModificationReplaceProperty(SchemaConstants.PATH_PASSWORD_FORCE_CHANGE, Boolean.TRUE);

executeChanges(userDelta, null, task, result);

Expand Down
Expand Up @@ -296,9 +296,9 @@ public void test102AssignRoleStats() throws Exception{

// THEN
result.computeStatus();
if (!result.isSuccess() && !result.isPartialError()) {
if (!result.isInProgress()) {
display(result);
AssertJUnit.fail("Expected success or partial error, but got "+result.getStatus());
AssertJUnit.fail("Expected in progress result, but got "+result.getStatus());
}
PrismObject<UserType> userJack = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
AssertJUnit.assertNotNull("User jack not found", userJack);
Expand Down
Expand Up @@ -168,6 +168,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
resourceDummyAd = importAndGetObjectFromFileIgnoreWarnings(ResourceType.class, RESOURCE_DUMMY_AD_FILE, RESOURCE_DUMMY_AD_OID, initTask, initResult);
resourceDummyAdType = resourceDummyAd.asObjectable();
dummyResourceCtlAd.setResource(resourceDummyAd);
initDummyResource(RESOURCE_DUMMY_AD_ID, dummyResourceCtlAd);

dummyResourceCtlMail = DummyResourceContoller.create(RESOURCE_DUMMY_MAIL_ID, resourceDummyMail);
dummyResourceCtlMail.populateWithDefaultSchema();
Expand All @@ -186,6 +187,7 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti
resourceDummyMail = importAndGetObjectFromFile(ResourceType.class, RESOURCE_DUMMY_MAIL_FILE, RESOURCE_DUMMY_MAIL_OID, initTask, initResult);
resourceDummyMailType = resourceDummyMail.asObjectable();
dummyResourceCtlMail.setResource(resourceDummyMail);
initDummyResource(RESOURCE_DUMMY_MAIL_ID, dummyResourceCtlMail);

}

Expand Down
Expand Up @@ -15,21 +15,18 @@
*/
package com.evolveum.midpoint.testing.story;

import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertEquals;
import static org.testng.AssertJUnit.assertFalse;
import static org.testng.AssertJUnit.assertNotNull;
import static org.testng.AssertJUnit.assertNull;
import static org.testng.AssertJUnit.assertTrue;

import java.io.File;
import java.util.List;

import javax.xml.datatype.XMLGregorianCalendar;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import org.jetbrains.annotations.Nullable;
import org.opends.server.types.DirectoryException;
import org.opends.server.types.Entry;
Expand All @@ -41,6 +38,7 @@
import org.testng.annotations.AfterClass;
import org.testng.annotations.Test;

import com.evolveum.midpoint.common.Utils;
import com.evolveum.midpoint.common.refinery.RefinedObjectClassDefinition;
import com.evolveum.midpoint.common.refinery.RefinedResourceSchema;
import com.evolveum.midpoint.model.impl.sync.ReconciliationTaskHandler;
Expand All @@ -49,6 +47,9 @@
import com.evolveum.midpoint.prism.PrismObject;
import com.evolveum.midpoint.prism.PrismProperty;
import com.evolveum.midpoint.prism.delta.ChangeType;
import com.evolveum.midpoint.prism.delta.ItemDelta;
import com.evolveum.midpoint.prism.path.ItemName;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.polystring.PolyString;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.prism.util.PrismAsserts;
Expand All @@ -67,8 +68,21 @@
import com.evolveum.midpoint.test.util.MidPointTestConstants;
import com.evolveum.midpoint.test.util.TestUtil;
import com.evolveum.midpoint.util.DOMUtil;
import com.evolveum.midpoint.util.MiscUtil;
import com.evolveum.midpoint.util.exception.ExpressionEvaluationException;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationStatusType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ActivationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationPhaseType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.RoleType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.SequenceType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowAssociationType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowKindType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType;
import com.evolveum.midpoint.xml.ns._public.common.common_3.UserType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

/**
Expand Down Expand Up @@ -2121,7 +2135,7 @@ protected void assertModifyTimestamp(PrismObject<ShadowType> shadow, long startT
}

protected Long getTimestampAttribute(PrismObject<ShadowType> shadow) throws Exception {
Long attributeValue = ShadowUtil.getAttributeValue(shadow, OPENDJ_MODIFY_TIMESTAMP_ATTRIBUTE_QNAME);
return attributeValue;
XMLGregorianCalendar attributeValue = ShadowUtil.getAttributeValue(shadow, OPENDJ_MODIFY_TIMESTAMP_ATTRIBUTE_QNAME);
return MiscUtil.asLong(attributeValue);
}
}
Expand Up @@ -48,42 +48,37 @@

currentTimestamp = focus?.asPrismObject()?.findExtensionItem("hrStatusChangeTimestamp")
if (currentTimestamp == null) {
// No timestamp at all, e.g. the case of adding new object
return basic.currentDateTime()
// No timestamp at all, e.g. the case of adding new object
return basic.currentDateTime()
}

// Let's check whether the hrStatus is really changed
hrStatusDelta = midpoint.focusContext?.delta?.findPropertyDelta(ItemPath.create("extension","hrStatus"))

if (hrStatusDelta == null) {
// No hrStatus delta. Therefore this is phantom invocation of this mapping. hrStatus is not really
changing.
return currentTimestamp
// No hrStatus delta. Therefore this is phantom invocation of this mapping. hrStatus is not really changing.
return currentTimestamp
} else {
// Let's check whether we are not changing hrStatusChangeTimestamp already. We do not want create
different value in such case.
// Creating different value will mean that there will be too many triggers. And we may run into risk of
creating new
// triggers indefinitely if we are not careful here.
timestampSecondaryDelta =
midpoint.focusContext?.secondaryDelta?.findPropertyDelta(ItemPath.create("extension","hrStatusChangeTimestamp"))
if (timestampSecondaryDelta == null) {
// This is the "core" case: we really are changing hrStatus, and we do not have new timestamp
// Let's check whether we are not changing hrStatusChangeTimestamp already. We do not want create different value in such case.
// Creating different value will mean that there will be too many triggers. And we may run into risk of creating new
// triggers indefinitely if we are not careful here.
timestampSecondaryDelta = midpoint.focusContext?.secondaryDelta?.findPropertyDelta(ItemPath.create("extension","hrStatusChangeTimestamp"))
if (timestampSecondaryDelta == null) {
// This is the "core" case: we really are changing hrStatus, and we do not have new timestamp

// Pretend that output for old value is null.
// Otherwise the script can produce the same value for old and new inputs if those two exections were done
// during the same millisecond. That midPoint will interpret that as "unchanged" and it will not update the timestamp.
if (!midpoint.isEvaluateNew()) {
return null;
}

return basic.currentDateTime()

// Pretend that output for old value is null.
// Otherwise the script can produce the same value for old and new inputs if those two exections were done
// during the same millisecond. That midPoint will interpret that as "unchanged" and it will not update
the timestamp.
if (!midpoint.isEvaluateNew()) {
return null;
}
return basic.currentDateTime()

} else {
// We have already changed the timestamp. Therefore just return the value that we have created a moment
ago.
return currentTimestamp
}
} else {
// We have already changed the timestamp. Therefore just return the value that we have created a moment ago.
return currentTimestamp
}
}
</code>
</script>
Expand Down
7 changes: 3 additions & 4 deletions testing/story/src/test/resources/trafo/resource-dummy-ad.xml
Expand Up @@ -172,16 +172,16 @@ else {
<attribute>
<ref>ri:groups</ref>
<displayName>Groups</displayName>

<limitations>
<access>
<read>true</read>
<add>true</add>
<modify>true</modify>
</access>
</limitations>
<tolerant>true</tolerant>
<matchingRule>mr:stringIgnoreCase</matchingRule>
<tolerant>true</tolerant>

<outbound>
<strength>strong</strength><!-- See above -->
<source>
Expand Down Expand Up @@ -220,16 +220,15 @@ return null;
<attribute>
<ref>icfs:name</ref>
<displayName>Distinguished Name</displayName>

<limitations>
<access>
<read>true</read>
<add>true</add>
<modify>true</modify>
</access>
</limitations>

<matchingRule>mr:stringIgnoreCase</matchingRule>

<outbound>
<!--<strength>weak</strength>-->
<source>
Expand Down

0 comments on commit bbdae7c

Please sign in to comment.