use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class BasicExpressionFunctions method stringify.
/**
* Converts whatever it gets to a string. But it does it in a sensitive way.
* E.g. it tries to detect collections and returns the first element (if there is only one).
* Never returns null. Returns empty string instead.
*/
public String stringify(Object whatever) {
if (whatever == null) {
return "";
}
if (whatever instanceof String) {
return (String) whatever;
}
if (whatever instanceof PolyString) {
return ((PolyString) whatever).getOrig();
}
if (whatever instanceof PolyStringType) {
return ((PolyStringType) whatever).getOrig();
}
if (whatever instanceof Collection) {
Collection collection = (Collection) whatever;
if (collection.isEmpty()) {
return "";
}
if (collection.size() > 1) {
throw new IllegalArgumentException("Cannot stringify collection because it has " + collection.size() + " values");
}
whatever = collection.iterator().next();
}
Class<? extends Object> whateverClass = whatever.getClass();
if (whateverClass.isArray()) {
Object[] array = (Object[]) whatever;
if (array.length == 0) {
return "";
}
if (array.length > 1) {
throw new IllegalArgumentException("Cannot stringify array because it has " + array.length + " values");
}
whatever = array[0];
}
if (whatever == null) {
return "";
}
if (whatever instanceof String) {
return (String) whatever;
}
if (whatever instanceof PolyString) {
return ((PolyString) whatever).getOrig();
}
if (whatever instanceof PolyStringType) {
return ((PolyStringType) whatever).getOrig();
}
if (whatever instanceof Element) {
Element element = (Element) whatever;
Element origElement = DOMUtil.getChildElement(element, PolyString.F_ORIG);
if (origElement != null) {
// This is most likely a PolyStringType
return origElement.getTextContent();
} else {
return element.getTextContent();
}
}
if (whatever instanceof Node) {
return ((Node) whatever).getTextContent();
}
return whatever.toString();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestCorrelationConfiramtionEvaluator method test006CorrelationFindCaseInsensitive.
@Test
public void test006CorrelationFindCaseInsensitive() throws Exception {
String TEST_NAME = "test006CorrelationFindCaseInsensitive";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TEST_NAME);
OperationResult result = task.getResult();
// importObjectFromFile(USER_JACK_FILENAME);
PrismObject<UserType> userType = repositoryService.getObject(UserType.class, USER_JACK_OID, null, result);
//assert jack
assertNotNull(userType);
ShadowType shadow = parseObjectType(ACCOUNT_SHADOW_JACK_DUMMY_FILE, ShadowType.class);
ConditionalSearchFilterType query = PrismTestUtil.parseAtomicValue(new File(CORRELATION_CASE_INSENSITIVE), ConditionalSearchFilterType.COMPLEX_TYPE);
List<ConditionalSearchFilterType> queries = new ArrayList<>();
queries.add(query);
//
ResourceType resourceType = parseObjectType(RESOURCE_DUMMY_FILE, ResourceType.class);
// resourceType.getSynchronization().getObjectSynchronization().get(0).getCorrelation().add(query);
userType.asObjectable().setName(new PolyStringType("JACK"));
Collection<? extends ItemDelta> modifications = PropertyDelta.createModificationReplacePropertyCollection(UserType.F_NAME, userType.getDefinition(), new PolyString("JACK", "jack"));
repositoryService.modifyObject(UserType.class, USER_JACK_OID, modifications, result);
List<PrismObject<UserType>> matchedUsers = evaluator.findFocusesByCorrelationRule(UserType.class, shadow, queries, resourceType, getSystemConfiguration(), task, result);
System.out.println("matched users " + matchedUsers);
assertNotNull("Correlation evaluator returned null collection of matched users.", matchedUsers);
assertEquals("Found more than one user.", 1, matchedUsers.size());
PrismObject<UserType> jack = matchedUsers.get(0);
assertUser(jack, "c0c010c0-d34d-b33f-f00d-111111111111", "JACK", "Jack Sparrow", "Jack", "Sparrow");
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestTrafo method test300Smith111Rename.
/**
* Attempt to rename two employees that are boh "John Smith". This is the first user. Everything shouyld do as normal.
* Note: this is a different case than jack-angelica. Jack and Angelica are "externists". Smithes are employees (type "T")
*/
@Test
public void test300Smith111Rename() throws Exception {
final String TEST_NAME = "test300Smith111Rename";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestTrafo.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
// WHEN
TestUtil.displayWhen(TEST_NAME);
// addObject(USER_SMITH111_FILE);
// TestUtil.displayThen(TEST_NAME);
// result.computeStatus();
// TestUtil.assertSuccess(result);
PrismObject<UserType> userSmith = getUser(USER_SMITH111_OID);
display("User smith111 before change execution", userSmith);
assertUser(userSmith, USER_SMITH111_OID, USER_SMITH111_USERNAME, "John Smith", "John", "Smith");
assertLinks(userSmith, 2);
String accountAdOid = getLinkRefOid(userSmith, RESOURCE_DUMMY_AD_OID);
String accountMailOid = getLinkRefOid(userSmith, RESOURCE_DUMMY_MAIL_OID);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
Collection<? extends ItemDelta> fullNameModification = PropertyDelta.createModificationReplacePropertyCollection(UserType.F_FAMILY_NAME, userSmith.getDefinition(), new PolyString("Smither", "smither"));
ObjectDelta.createModifyDelta(userSmith.getOid(), fullNameModification, UserType.class, prismContext);
modifyUserReplace(userSmith.getOid(), UserType.F_FAMILY_NAME, task, result, new PolyString("Smither", "smither"));
// AD ACCOUNT
// Check shadow
PrismObject<ShadowType> accountAdShadow = repositoryService.getObject(ShadowType.class, accountAdOid, null, result);
display("AD shadow", accountAdShadow);
assertAccountShadowRepo(accountAdShadow, accountAdOid, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, resourceDummyAdType, caseIgnoreMatchingRule);
// Check account
PrismObject<ShadowType> accountAdModel = modelService.getObject(ShadowType.class, accountAdOid, null, task, result);
display("AD shadow", accountAdModel);
assertAccountShadowModel(accountAdModel, accountAdOid, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, resourceDummyAdType, caseIgnoreMatchingRule);
assertAdministrativeStatusEnabled(accountAdModel);
smith111AdIcfUid = getIcfUid(accountAdModel);
// Check account in dummy resource
assertDummyAccountById(RESOURCE_DUMMY_AD_ID, smith111AdIcfUid);
assertDummyAccount(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME);
assertDummyAccountActivation(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, ACCOUNT_SMITH111_AD_SAM_NAME);
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_USER_PRINCIPAL_NAME_NAME, ACCOUNT_SMITH111_AD_SAM_NAME + "@" + TRAFO_MAIL_DOMAIN);
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_GIVEN_NAME_NAME, "John");
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SN_NAME, "Smither");
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_MAIL_NAME, "John.Smither@" + TRAFO_MAIL_DOMAIN);
assertDummyAccountNoAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_TELEPHONE_NUMBER_NAME);
assertDummyAccountAttribute(RESOURCE_DUMMY_AD_ID, ACCOUNT_SMITH111_AD_DN_AFTER_RENAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_USER_SHARED_FOLDER_OTHER_NAME, "\\\\medusa\\User\\Smither_smith111");
// MAIL ACCOUNT
// Check shadow
PrismObject<ShadowType> accountMailShadow = repositoryService.getObject(ShadowType.class, accountMailOid, null, result);
assertAccountShadowRepo(accountMailShadow, accountMailOid, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, resourceDummyMailType, caseIgnoreMatchingRule);
// Check account
PrismObject<ShadowType> accountMailModel = modelService.getObject(ShadowType.class, accountMailOid, null, task, result);
display("Mail shadow", accountMailModel);
assertAccountShadowModel(accountMailModel, accountMailOid, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, resourceDummyMailType, caseIgnoreMatchingRule);
assertAdministrativeStatusEnabled(accountMailModel);
smith111MailIcfUid = getIcfUid(accountMailModel);
// Check account in dummy resource
assertDummyAccountById(RESOURCE_DUMMY_MAIL_ID, smith111MailIcfUid);
assertDummyAccount(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME);
assertDummyAccountActivation(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_INTERNET_ADDRESS_NAME, "John.Smither@" + TRAFO_MAIL_DOMAIN);
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_FIRST_NAME_NAME, "John");
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_LAST_NAME_NAME, "Smither");
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_ID_FILE_NAME, "c:\\install\\test-id-folder\\jsmith.id");
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_SHORT_NAME_NAME, "PS111", "jsmither");
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_MAIL_FILE_NAME_NAME, "mail\\js111");
assertDummyAccountAttribute(RESOURCE_DUMMY_MAIL_ID, ACCOUNT_SMITH111_MAIL_USERNAME_AFTER_RENAME, DUMMY_ACCOUNT_ATTRIBUTE_MAIL_MAIL_DOMAIN_NAME, "TRAFO");
PrismObject<UserType> userSmithAfter = getUser(USER_SMITH111_OID);
display("User smith111 after change execution", userSmithAfter);
// Set by inbound mappings
PrismAsserts.assertPropertyValue(userSmithAfter, UserType.F_EMAIL_ADDRESS, "John.Smither@" + TRAFO_MAIL_DOMAIN);
// [pmed] This is nondeterministic: extension/homedir is filled-in from both AD and Mail resources. (With different values.)
// So it's hard to say which value will be there in the end.
// PrismAsserts.assertPropertyValue(userSmithAfter,
// new ItemPath(UserType.F_EXTENSION, TRAFO_EXTENSION_HOMEDIR_QNAME), "\\\\medusa\\User\\Smither_smith111");
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(5);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
dummyAuditService.assertExecutionDeltas(0, 2);
// primary
dummyAuditService.assertHasDelta(0, ChangeType.MODIFY, UserType.class);
// dummyAuditService.asserHasDelta(0,ChangeType.MODIFY, UserType.class); // link
// AD account (outbound)
dummyAuditService.assertHasDelta(0, ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionDeltas(1, 2);
// link, inbound (2 deltas)
dummyAuditService.assertHasDelta(1, ChangeType.MODIFY, UserType.class);
// Mail account (outboud)
dummyAuditService.assertHasDelta(1, ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionDeltas(2, 2);
// inbound
dummyAuditService.assertHasDelta(2, ChangeType.MODIFY, UserType.class);
// AD account (mail change compued from outboud)
dummyAuditService.assertHasDelta(2, ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertExecutionDeltas(3, 1);
// inbound - SHOULD THIS BE HERE?? FIXME
dummyAuditService.assertHasDelta(3, ChangeType.MODIFY, UserType.class);
dummyAuditService.assertExecutionSuccess();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestUnix method test257RenameUserAndAccountsCheckGroupmembership.
@Test
public void test257RenameUserAndAccountsCheckGroupmembership() throws Exception {
final String TEST_NAME = "test257RenameUserAndAccountsCheckGroupmembership";
TestUtil.displayTestTile(this, TEST_NAME);
Task task = taskManager.createTaskInstance(TestUnix.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBefore = findUserByUsername(USER_RANGER_USERNAME);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserReplace(userBefore.getOid(), UserType.F_NAME, task, result, new PolyString("usranger", "usranger"));
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess(result);
PrismObject<UserType> userAfter = findUserByUsername(USER_RANGER_USERNAME_RENAMED);
assertNotNull("User not renamed", userAfter);
display("User after rename", userAfter);
assertUserPosix(userAfter, USER_RANGER_USERNAME_RENAMED, USER_RANGER_FIST_NAME, USER_RANGER_LAST_NAME, USER_RANGER_UID_NUMBER);
String accountOid = getSingleLinkOid(userAfter);
PrismObject<ShadowType> shadow = getShadowModel(accountOid);
display("Shadow (model)", shadow);
assertPosixAccount(shadow, USER_RANGER_UID_NUMBER);
// account should still be in the rangers group, but renamed from
// ranger to usranger
PrismObject<ShadowType> shadowGroup = getShadowModel(groupRangersOid);
display("Shadow rangers group (model)", shadowGroup);
Entry groupRangers = openDJController.fetchEntry(groupRangersDn);
assertUnixGroup(shadowGroup, ROLE_RANGERS_GID);
openDJController.assertAttribute(groupRangers, "memberUid", USER_RANGER_USERNAME_RENAMED);
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestIteration method test280RenameBobNoShadow.
/**
* Same as test240 (conflict with no shadow), but including rename operation.
*/
@Test
public void test280RenameBobNoShadow() throws Exception {
final String TEST_NAME = "test280RenameBobNoShadow";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userBob = createUser(USER_BOB_NAME, "Bob Andrews", true);
addObject(userBob);
String userBobOid = userBob.getOid();
// Make sure there is a conflicting account and NO shadow for it
DummyAccount account = new DummyAccount("bobby");
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_FULLNAME_NAME, "Bobby Pinky");
dummyResourcePink.addAccount(account);
// preconditions
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, USER_BOB_NAME);
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby", "Bobby Pinky", true);
// prepare change
ObjectDelta<UserType> objectDelta = createAccountAssignmentUserDelta(userBobOid, RESOURCE_DUMMY_PINK_OID, "default", true);
// will conflict with Bobby Pinky
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_NAME, new PolyString("bobby")));
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_FULL_NAME, new PolyString("Bobby Andrews")));
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<>();
deltas.add(objectDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
PrismObject<UserType> userBobAfter = getUser(userBobOid);
display("User after change execution", userBobAfter);
assertUser(userBobAfter, userBobOid, "bobby", "Bobby Andrews", null, null, null);
String accountOid = getSingleLinkOid(userBobAfter);
// Check shadow & account
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
display("Account shadow from repo", accountShadow);
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
display("Account shadow from model", accountModel);
assertAccountShadowRepo(accountShadow, accountOid, "bobby1", resourceDummyPinkType);
assertAccountShadowModel(accountModel, accountOid, "bobby1", resourceDummyPinkType);
// THEN
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby", "Bobby Pinky", true);
assertDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bobby1", "Bobby Andrews", true);
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, "bob");
}
Aggregations