diff --git a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/LensUtil.java b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/LensUtil.java index 0c15d2f70c5..46b760352bb 100644 --- a/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/LensUtil.java +++ b/model/model-impl/src/main/java/com/evolveum/midpoint/model/impl/lens/LensUtil.java @@ -1149,6 +1149,16 @@ private static void checkObjectPolicy(LensFocusContext } else { PropertyDelta nameDelta = focusDelta.findPropertyDelta(itemPath); if (nameDelta != null) { + if (nameDelta.isReplace()) { + Collection> valuesToReplace = nameDelta.getValuesToReplace(); + if (valuesToReplace.size() == 1) { + String stringValue = valuesToReplace.iterator().next().getValue().toString(); + if (focusContext.getOid().equals(stringValue)) { + // This is OK. It is most likely a correction made by a recompute. + continue; + } + } + } throw new PolicyViolationException("Cannot change "+itemPath+" in oid bound mode"); } } diff --git a/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java b/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java index 1f96acc6b7b..af453e0e891 100644 --- a/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java +++ b/model/model-test/src/main/java/com/evolveum/midpoint/model/test/AbstractModelIntegrationTest.java @@ -1484,27 +1484,36 @@ protected void setDefaultObjectTemplate(QName objectType, String userTemplateOid PrismObject systemConfig = repositoryService.getObject(SystemConfigurationType.class, SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, parentResult); - PrismContainerValue deleteValue = null; + PrismContainerValue oldValue = null; for (ObjectPolicyConfigurationType focusPolicyType: systemConfig.asObjectable().getDefaultObjectPolicyConfiguration()) { if (objectType.equals(focusPolicyType.getType())) { - deleteValue = focusPolicyType.asPrismContainerValue(); + oldValue = focusPolicyType.asPrismContainerValue(); } } Collection modifications = new ArrayList(); - if (deleteValue != null) { + if (oldValue != null) { ContainerDelta deleteDelta = ContainerDelta.createModificationDelete(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, - SystemConfigurationType.class, prismContext, deleteValue); + SystemConfigurationType.class, prismContext, oldValue.clone()); ((Collection)modifications).add(deleteDelta); } - ObjectPolicyConfigurationType newFocusPolicyType = new ObjectPolicyConfigurationType(); - newFocusPolicyType.setType(objectType); + ObjectPolicyConfigurationType newFocusPolicyType; + ContainerDelta addDelta; + if (oldValue == null) { + newFocusPolicyType = new ObjectPolicyConfigurationType(); + newFocusPolicyType.setType(objectType); + addDelta = ContainerDelta.createModificationAdd(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, + SystemConfigurationType.class, prismContext, newFocusPolicyType); + } else { + PrismContainerValue newValue = oldValue.clone(); + addDelta = ContainerDelta.createModificationAdd(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, + SystemConfigurationType.class, prismContext, newValue); + newFocusPolicyType = newValue.asContainerable(); + } ObjectReferenceType templateRef = new ObjectReferenceType(); templateRef.setOid(userTemplateOid); newFocusPolicyType.setObjectTemplateRef(templateRef); - ContainerDelta addDelta = ContainerDelta.createModificationAdd(SystemConfigurationType.F_DEFAULT_OBJECT_POLICY_CONFIGURATION, - SystemConfigurationType.class, prismContext, newFocusPolicyType); ((Collection)modifications).add(addDelta); repositoryService.modifyObject(SystemConfigurationType.class, diff --git a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestVillage.java b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestVillage.java index 98df89347ba..5c57e9e8372 100644 --- a/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestVillage.java +++ b/testing/story/src/test/java/com/evolveum/midpoint/testing/story/TestVillage.java @@ -133,6 +133,8 @@ public class TestVillage extends AbstractStoryTest { public static final File TEST_DIR = new File(MidPointTestConstants.TEST_RESOURCES_DIR, "village"); + public static final File SYSTEM_CONFIGURATION_FILE = new File(TEST_DIR, "system-configuration.xml"); + public static final File OBJECT_TEMPLATE_USER_FILE = new File(TEST_DIR, "object-template-user.xml"); public static final String OBJECT_TEMPLATE_USER_OID = "10000000-0000-0000-0000-000000000222"; @@ -183,10 +185,12 @@ public class TestVillage extends AbstractStoryTest { protected static final File TASK_LIVE_SYNC_DUMMY_SOURCE_FILE = new File(TEST_DIR, "task-dumy-source-livesync.xml"); protected static final String TASK_LIVE_SYNC_DUMMY_SOURCE_OID = "10000000-0000-0000-5555-555500000001"; - private static final String USER_MIKE_FILENAME = COMMON_DIR_NAME + "/user-mike.xml"; - private static final File USER_MIKE_FILE = new File(USER_MIKE_FILENAME); + private static final File USER_MIKE_FILE = new File(COMMON_DIR, "user-mike.xml"); private static final String USER_MIKE_OID = "c0c010c0-d34d-b33f-f00d-222333111111"; - + + private static final File USER_MURRAY_FILE = new File(TEST_DIR, "user-murray.xml"); + private static final String USER_MURRAY_OID = "c0c010c0-d34d-b33f-f00d-1111111111aa"; + private static final String ACCOUNT_HERMAN_USERNAME = "ht"; private static final String ACCOUNT_HERMAN_FIST_NAME = "Herman"; private static final String ACCOUNT_HERMAN_LAST_NAME = "Toothrot"; @@ -311,6 +315,11 @@ public void initSystem(Task initTask, OperationResult initResult) throws Excepti } + @Override + protected File getSystemConfigurationFile() { + return SYSTEM_CONFIGURATION_FILE; + } + @Test public void test000Sanity() throws Exception { final String TEST_NAME = "test000Sanity"; @@ -706,6 +715,32 @@ public void test300AddProjectJollyRoger() throws Exception { //TODO: assertions } + /** + * User is added to repo directly, so he does not have OID in employee number. + * Recompute should fix that. This is a migration scenario. + */ + @Test + public void test350AddRepoUserNoEmployeeNumberRecompute() throws Exception { + final String TEST_NAME = "test350AddRepoUserNoEmployeeNumberRecompute"; + TestUtil.displayTestTile(this, TEST_NAME); + Task task = taskManager.createTaskInstance(TestTrafo.class.getName() + "." + TEST_NAME); + OperationResult result = task.getResult(); + + PrismObject user = PrismTestUtil.parseObject(USER_MURRAY_FILE); + repositoryService.addObject(user, null, result); + + // WHEN + TestUtil.displayWhen(TEST_NAME); + recomputeUser(USER_MURRAY_OID, task, result); + + // THEN + TestUtil.displayThen(TEST_NAME); + result.computeStatus(); + TestUtil.assertSuccess(result); + + user = getUser(USER_MURRAY_OID); + assertEmployeeNumber(user); + } private void assertLocGov(PrismObject user, String expLoc, String expOrg) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException { UserType userType = user.asObjectable(); @@ -741,6 +776,7 @@ private void assertUserNoRole(PrismObject user, String firstName, Stri display("User", user); assertUser(user, user.getOid(), username, firstName+" "+lastName, firstName, lastName); + assertEmployeeNumber(user); assertLinks(user, 1); assertAccount(user, RESOURCE_DUMMY_SOURCE_OID); assertAssignments(user, RoleType.class, 0); @@ -758,6 +794,7 @@ private void assertUserLdap(PrismObject user, String firstName, String display("User", user); assertUser(user, user.getOid(), username, firstName+" "+lastName, firstName, lastName); + assertEmployeeNumber(user); assertLinks(user, 2); assertAccount(user, RESOURCE_DUMMY_SOURCE_OID); @@ -771,6 +808,11 @@ private void assertUserLdap(PrismObject user, String firstName, String IntegrationTestTools.assertIcfsNameAttribute(shadow, "uid="+username+",ou=people,dc=example,dc=com"); } + private void assertEmployeeNumber(PrismObject user) { + String employeeNumber = user.asObjectable().getEmployeeNumber(); + assertEquals("Wrong employeeNumber in "+user, user.getOid(), employeeNumber); + } + private String getUsername(String firstName, String lastName, String orgName) throws SchemaException, ObjectNotFoundException, SecurityViolationException, CommunicationException, ConfigurationException { String username = firstName+"."+lastName; if (orgName != null) { diff --git a/testing/story/src/test/resources/village/system-configuration.xml b/testing/story/src/test/resources/village/system-configuration.xml new file mode 100644 index 00000000000..80c497f57a4 --- /dev/null +++ b/testing/story/src/test/resources/village/system-configuration.xml @@ -0,0 +1,153 @@ + + + + + SystemConfiguration + + File Appender + INFO + + TRACE + com.evolveum.midpoint.common.LoggingConfigurationManager + + + TRACE + com.evolveum.midpoint.notifications + + + %date [%thread] %-5level \(%logger{46}\): %message%n + target/test.log + true + + + + UserType + + employeeNumber + true + + + + + + + + + + + + + + + + + + + + + recipient@evolveum.com + + dummy:accountPasswordNotifier + + + + + + recipient@evolveum.com + + dummy:userPasswordNotifier + + + + success + + + recipient@evolveum.com + + dummy:simpleAccountNotifier-SUCCESS + + + + failure + + + recipient@evolveum.com + + dummy:simpleAccountNotifier-FAILURE + + + + add + success + + + recipient@evolveum.com + + dummy:simpleAccountNotifier-ADD-SUCCESS + + + + delete + success + + + recipient@evolveum.com + + dummy:simpleAccountNotifier-DELETE-SUCCESS + + + + + + recipient@evolveum.com + + dummy:simpleUserNotifier + + + + + add + + + + + recipient@evolveum.com + + dummy:simpleUserNotifier-ADD + + + + + + delete + + + + + recipient@evolveum.com + + dummy:simpleUserNotifier-DELETE + + + + + target/mail-notifications.log + + + diff --git a/testing/story/src/test/resources/village/user-murray.xml b/testing/story/src/test/resources/village/user-murray.xml new file mode 100644 index 00000000000..66013731898 --- /dev/null +++ b/testing/story/src/test/resources/village/user-murray.xml @@ -0,0 +1,32 @@ + + + + murray + Murray + Murray + The Skull + + + enabled + +