use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestIteration method test282RenamePeterNoShadowSync.
/**
* Same as test280 (conflict with no shadow with rename), but including synchronization.
*/
@Test
public void test282RenamePeterNoShadowSync() throws Exception {
final String TEST_NAME = "test282RenamePeterNoShadowSync";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestIteration.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
PrismObject<UserType> userPeter = createUser("peter", "Peter Crenshaw", true);
addObject(userPeter);
String userPeterOid = userPeter.getOid();
// Make sure there is a conflicting account and NO shadow for it
// will conflict after rename
DummyAccount account = new DummyAccount("Pete Crenshaw");
account.setEnabled(true);
account.addAttributeValues(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete0");
dummyResourceFuchsia.addAccount(account);
// preconditions
assertNoDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Peter Crenshaw");
// conflicting account (pete0)
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", null, true);
// prepare change
ObjectDelta<UserType> objectDelta = createAccountAssignmentUserDelta(userPeterOid, RESOURCE_DUMMY_FUCHSIA_OID, "default", true);
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_NAME, new PolyString("pete")));
objectDelta.addModification(createUserPropertyReplaceModification(UserType.F_FULL_NAME, new PolyString("Pete Crenshaw")));
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> userPeteAfter = getUser(userPeterOid);
display("User after change execution", userPeteAfter);
assertUser(userPeteAfter, userPeterOid, "pete", "Pete Crenshaw", null, null, null);
String accountOid = getSingleLinkOid(userPeteAfter);
// 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, "Pete Crenshaw1", resourceDummyFuchsiaType);
assertAccountShadowModel(accountModel, accountOid, "Pete Crenshaw1", resourceDummyFuchsiaType);
// Now check the other (newly created) user, pete0
PrismObject<UserType> userPete0 = findUserByUsername("pete0");
display("Newly created pete0 user", userPete0);
assertUser(userPete0, null, "pete0", "Pete Crenshaw", null, null, null);
String accountOidP0 = getSingleLinkOid(userPete0);
// Check shadow
PrismObject<ShadowType> accountShadowP0 = repositoryService.getObject(ShadowType.class, accountOidP0, null, result);
display("Account shadow from repo (pete0)", accountShadowP0);
assertAccountShadowRepo(accountShadowP0, accountOidP0, "Pete Crenshaw", resourceDummyFuchsiaType);
// Check account
PrismObject<ShadowType> accountModelP0 = modelService.getObject(ShadowType.class, accountOidP0, null, task, result);
display("Account shadow from model (pete0)", accountModelP0);
assertAccountShadowModel(accountModelP0, accountOidP0, "Pete Crenshaw", resourceDummyFuchsiaType);
// accounts on the resource
// pete0
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", null, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete0");
// pete
assertDummyAccount(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw1", null, true);
assertDummyAccountAttribute(RESOURCE_DUMMY_FUCHSIA_NAME, "Pete Crenshaw1", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_AD_SAM_ACCOUNT_NAME_NAME, "pete");
assertNoDummyAccount(RESOURCE_DUMMY_PINK_NAME, "peter");
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class ShadowManager method extractRepoShadowChanges.
@SuppressWarnings("rawtypes")
private Collection<? extends ItemDelta> extractRepoShadowChanges(ProvisioningContext ctx, PrismObject<ShadowType> shadow, Collection<? extends ItemDelta> objectChange) throws SchemaException, ConfigurationException, ObjectNotFoundException, CommunicationException, ExpressionEvaluationException {
RefinedObjectClassDefinition objectClassDefinition = ctx.getObjectClassDefinition();
CachingStategyType cachingStrategy = ProvisioningUtil.getCachingStrategy(ctx);
Collection<ItemDelta> repoChanges = new ArrayList<ItemDelta>();
for (ItemDelta itemDelta : objectChange) {
if (new ItemPath(ShadowType.F_ATTRIBUTES).equivalent(itemDelta.getParentPath())) {
QName attrName = itemDelta.getElementName();
if (objectClassDefinition.isSecondaryIdentifier(attrName)) {
// Change of secondary identifier means object rename. We also need to change $shadow/name
// TODO: change this to displayName attribute later
String newName = null;
if (itemDelta.getValuesToReplace() != null && !itemDelta.getValuesToReplace().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToReplace().iterator().next()).getValue().toString();
} else if (itemDelta.getValuesToAdd() != null && !itemDelta.getValuesToAdd().isEmpty()) {
newName = ((PrismPropertyValue) itemDelta.getValuesToAdd().iterator().next()).getValue().toString();
}
PropertyDelta<PolyString> nameDelta = PropertyDelta.createReplaceDelta(shadow.getDefinition(), ShadowType.F_NAME, new PolyString(newName));
repoChanges.add(nameDelta);
}
if (!ProvisioningUtil.shouldStoreAtributeInShadow(objectClassDefinition, attrName, cachingStrategy)) {
continue;
}
} else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getParentPath())) {
if (!ProvisioningUtil.shouldStoreActivationItemInShadow(itemDelta.getElementName(), cachingStrategy)) {
continue;
}
} else if (new ItemPath(ShadowType.F_ACTIVATION).equivalent(itemDelta.getPath())) {
// should not occur, but for completeness...
for (PrismContainerValue<ActivationType> valueToAdd : ((ContainerDelta<ActivationType>) itemDelta).getValuesToAdd()) {
ProvisioningUtil.cleanupShadowActivation(valueToAdd.asContainerable());
}
for (PrismContainerValue<ActivationType> valueToReplace : ((ContainerDelta<ActivationType>) itemDelta).getValuesToReplace()) {
ProvisioningUtil.cleanupShadowActivation(valueToReplace.asContainerable());
}
} else if (SchemaConstants.PATH_PASSWORD.equivalent(itemDelta.getParentPath())) {
continue;
}
normalizeDelta(itemDelta, objectClassDefinition);
repoChanges.add(itemDelta);
}
return repoChanges;
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class PropertyRestriction method checkValueType.
private Object checkValueType(Object value, ValueFilter filter) throws QueryException {
Class expectedType = linkDefinition.getTargetDefinition().getJaxbClass();
if (expectedType == null || value == null) {
// nothing to check here
return value;
}
if (expectedType.isPrimitive()) {
expectedType = ClassUtils.primitiveToWrapper(expectedType);
}
//attempt to fix value type for polystring (if it was string in filter we create polystring from it)
if (PolyString.class.equals(expectedType) && (value instanceof String)) {
LOGGER.debug("Trying to query PolyString value but filter contains String '{}'.", filter);
String orig = (String) value;
value = new PolyString(orig, context.getPrismContext().getDefaultPolyStringNormalizer().normalize(orig));
}
//attempt to fix value type for polystring (if it was polystringtype in filter we create polystring from it)
if (PolyString.class.equals(expectedType) && (value instanceof PolyStringType)) {
LOGGER.debug("Trying to query PolyString value but filter contains PolyStringType '{}'.", filter);
PolyStringType type = (PolyStringType) value;
value = new PolyString(type.getOrig(), type.getNorm());
}
if (String.class.equals(expectedType) && (value instanceof QName)) {
//eg. shadow/objectClass
value = RUtil.qnameToString((QName) value);
}
if (value instanceof RawType) {
// MID-3850: but it's quite a workaround. Maybe we should treat RawType's earlier than this.
try {
return ((RawType) value).getParsedRealValue(expectedType);
} catch (SchemaException e) {
throw new QueryException("Couldn't parse value " + value + " as " + expectedType + ": " + e.getMessage(), e);
}
}
if (!expectedType.isAssignableFrom(value.getClass())) {
throw new QueryException("Value should be type of '" + expectedType + "' but it's '" + value.getClass() + "', filter '" + filter + "'.");
}
return value;
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestMultiResource method test227ModifyUserJackDefaultDummyBrokenSchemaViolation.
/**
* Cause schema violation on the account during a provisioning operation. This should fail
* the operation, but other operations should proceed and the account should definitelly NOT
* be unlinked.
* MID-2134
*/
@Test
public void test227ModifyUserJackDefaultDummyBrokenSchemaViolation() throws Exception {
final String TEST_NAME = "test227ModifyUserJackDefaultDummyBrokenSchemaViolation";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestMultiResource.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
getDummyResource().setModifyBreakMode(BreakMode.SCHEMA);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modifyUserReplace(USER_JACK_OID, UserType.F_FULL_NAME, task, result, new PolyString("Cpt. Jack Sparrow", null));
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
display("Result", result);
TestUtil.assertPartialError(result);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
assertLinks(userJack, 2);
display("dummy resource after", getDummyResource());
display("beige dummy resource after", dummyResourceBeige);
assertDummyAccount(null, ACCOUNT_JACK_DUMMY_USERNAME, ACCOUNT_JACK_DUMMY_FULLNAME, true);
assertDummyAccount(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, "Cpt. Jack Sparrow", true);
// No value for ship ... no place to get it from
assertDummyAccountAttribute(RESOURCE_DUMMY_BEIGE_NAME, ACCOUNT_JACK_DUMMY_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_SHIP_NAME);
assertNoDummyAccount(RESOURCE_DUMMY_LAVENDER_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
assertNoDummyAccount(RESOURCE_DUMMY_IVORY_NAME, ACCOUNT_JACK_DUMMY_USERNAME);
getDummyResource().resetBreakMode();
}
use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.
the class TestModelServiceContract method test197ModifyUserJackLocationNull.
@Test
public void test197ModifyUserJackLocationNull() throws Exception {
final String TEST_NAME = "test197ModifyUserJackLocationNull";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
preTestCleanup(AssignmentPolicyEnforcementType.FULL);
try {
// WHEN
modifyUserReplace(USER_JACK_OID, UserType.F_LOCALITY, task, result, (PolyString) null);
AssertJUnit.fail("Unexpected success");
} catch (IllegalStateException e) {
// This is expected
}
// THEN
result.computeStatus();
TestUtil.assertFailure(result);
assertShadowFetchOperationCountIncrement(0);
assertNoProvisioningScripts();
// Check audit
display("Audit", dummyAuditService);
// This should fail even before the request record is created
dummyAuditService.assertRecords(0);
assertScriptCompileIncrement(0);
assertSteadyResources();
}
Aggregations