use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ConsistencyTest method test511AssignAccountMorgan.
/**
* assign account to the user morgan. Account with the same 'uid' (not dn, nut other secondary identifier already exists)
* account should be linked to the user.
* @throws Exception
*/
@Test
public void test511AssignAccountMorgan() throws Exception {
final String TEST_NAME = "test511AssignAccountMorgan";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
openDJController.assumeRunning();
Task task = taskManager.createTaskInstance(ConsistencyTest.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
dummyAuditService.clear();
//prepare new OU in opendj
Entry entry = openDJController.addEntryFromLdifFile(LDIF_CREATE_USERS_OU_FILENAME);
PrismObject<UserType> user = repositoryService.getObject(UserType.class, USER_MORGAN_OID, null, result);
display("User Morgan: ", user);
PrismReference linkRef = user.findReference(UserType.F_LINK_REF);
ExpressionType expression = new ExpressionType();
ObjectFactory of = new ObjectFactory();
RawType raw = new RawType(new PrimitiveXNode("uid=morgan,ou=users,dc=example,dc=com"), prismContext);
JAXBElement val = of.createValue(raw);
expression.getExpressionEvaluator().add(val);
MappingType mapping = new MappingType();
mapping.setExpression(expression);
ResourceAttributeDefinitionType attrDefType = new ResourceAttributeDefinitionType();
attrDefType.setRef(new ItemPathType(new ItemPath(getOpenDjSecondaryIdentifierQName())));
attrDefType.setOutbound(mapping);
ConstructionType construction = new ConstructionType();
construction.getAttribute().add(attrDefType);
construction.setResourceRef(ObjectTypeUtil.createObjectRef(resourceTypeOpenDjrepo));
AssignmentType assignment = new AssignmentType();
assignment.setConstruction(construction);
ObjectDelta<UserType> userDelta = ObjectDelta.createModificationAddContainer(UserType.class, USER_MORGAN_OID, UserType.F_ASSIGNMENT, prismContext, assignment.asPrismContainerValue());
Collection<ObjectDelta<? extends ObjectType>> deltas = MiscSchemaUtil.createCollection(userDelta);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
// assertEquals("Expected handled error but got: " + result.getStatus(), OperationResultStatus.HANDLED_ERROR, result.getStatus());
PrismObject<UserType> userMorgan = modelService.getObject(UserType.class, USER_MORGAN_OID, null, task, result);
display("User morgan after", userMorgan);
UserType userMorganType = userMorgan.asObjectable();
assertEquals("Unexpected number of accountRefs", 1, userMorganType.getLinkRef().size());
String accountOid = userMorganType.getLinkRef().iterator().next().getOid();
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountOid, null, result);
assertShadowRepo(accountShadow, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountOid, null, task, result);
assertShadowModel(accountModel, accountOid, "uid=morgan,ou=people,dc=example,dc=com", resourceTypeOpenDjrepo, RESOURCE_OPENDJ_ACCOUNT_OBJECTCLASS);
ResourceAttribute attributes = ShadowUtil.getAttribute(accountModel, new QName(resourceTypeOpenDjrepo.getNamespace(), "uid"));
assertEquals("morgan", attributes.getAnyRealValue());
// TODO: check OpenDJ Account
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class CorrelationConfirmationEvaluator method satisfyCondition.
private boolean satisfyCondition(ShadowType currentShadow, ConditionalSearchFilterType conditionalFilter, ResourceType resourceType, SystemConfigurationType configurationType, String shortDesc, Task task, OperationResult parentResult) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
if (conditionalFilter.getCondition() == null) {
return true;
}
ExpressionType condition = conditionalFilter.getCondition();
ExpressionVariables variables = Utils.getDefaultExpressionVariables(null, currentShadow, resourceType, configurationType);
ItemDefinition outputDefinition = new PrismPropertyDefinitionImpl(ExpressionConstants.OUTPUT_ELEMENT_NAME, DOMUtil.XSD_BOOLEAN, prismContext);
PrismPropertyValue<Boolean> satisfy = (PrismPropertyValue) ExpressionUtil.evaluateExpression(variables, outputDefinition, condition, expressionFactory, shortDesc, task, parentResult);
if (satisfy.getValue() == null) {
return false;
}
return satisfy.getValue();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class TestModelServiceContract method test191ModifyUserJackModifyAssignment.
/**
* We try to modify an assignment of the account and see whether changes will be recorded in the account itself.
*
*/
@Test
public void test191ModifyUserJackModifyAssignment() throws Exception {
final String TEST_NAME = "test191ModifyUserJackModifyAssignment";
TestUtil.displayTestTile(this, TEST_NAME);
// GIVEN
Task task = taskManager.createTaskInstance(TestModelServiceContract.class.getName() + "." + TEST_NAME);
OperationResult result = task.getResult();
Collection<ObjectDelta<? extends ObjectType>> deltas = new ArrayList<ObjectDelta<? extends ObjectType>>();
//PrismPropertyDefinition definition = getAssignmentDefinition().findPropertyDefinition(new QName(SchemaConstantsGenerated.NS_COMMON, "accountConstruction"));
PrismObject<ResourceType> dummyResource = repositoryService.getObject(ResourceType.class, RESOURCE_DUMMY_OID, null, result);
RefinedResourceSchema refinedSchema = RefinedResourceSchemaImpl.getRefinedSchema(dummyResource, prismContext);
// This explicitly parses the schema, therefore ...
assertResourceSchemaParseCountIncrement(1);
RefinedObjectClassDefinition accountDefinition = refinedSchema.getRefinedDefinition(ShadowKindType.ACCOUNT, (String) null);
PrismPropertyDefinition gossipDefinition = accountDefinition.findPropertyDefinition(new QName("http://midpoint.evolveum.com/xml/ns/public/resource/instance/10000000-0000-0000-0000-000000000004", DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME));
assertNotNull("gossip attribute definition not found", gossipDefinition);
ConstructionType accountConstruction = createAccountConstruction(RESOURCE_DUMMY_OID, null);
ResourceAttributeDefinitionType radt = new ResourceAttributeDefinitionType();
radt.setRef(new ItemPathType(new ItemPath(gossipDefinition.getName())));
MappingType outbound = new MappingType();
radt.setOutbound(outbound);
ExpressionType expression = new ExpressionType();
outbound.setExpression(expression);
MappingType value = new MappingType();
PrismProperty<String> property = gossipDefinition.instantiate();
property.add(new PrismPropertyValue<String>("q"));
List evaluators = expression.getExpressionEvaluator();
Collection<JAXBElement<RawType>> collection = StaticExpressionUtil.serializeValueElements(property, null);
ObjectFactory of = new ObjectFactory();
for (JAXBElement<RawType> obj : collection) {
evaluators.add(of.createValue(obj.getValue()));
}
value.setExpression(expression);
radt.setOutbound(value);
accountConstruction.getAttribute().add(radt);
PrismObject<UserType> jackBefore = getUserFromRepo(USER_JACK_OID);
assertEquals("Wrong # of assignments", 1, jackBefore.asObjectable().getAssignment().size());
Long assignmentId = jackBefore.asObjectable().getAssignment().get(0).getId();
ObjectDelta<UserType> accountAssignmentUserDelta = createReplaceAccountConstructionUserDelta(USER_JACK_OID, assignmentId, accountConstruction);
deltas.add(accountAssignmentUserDelta);
preTestCleanup(AssignmentPolicyEnforcementType.POSITIVE);
PrismObject<UserType> userJackOld = getUser(USER_JACK_OID);
display("User before change execution", userJackOld);
display("Deltas to execute execution", deltas);
// WHEN
TestUtil.displayWhen(TEST_NAME);
modelService.executeChanges(deltas, null, task, result);
// THEN
TestUtil.displayThen(TEST_NAME);
result.computeStatus();
TestUtil.assertSuccess("executeChanges result", result);
// First fetch: initial account read
// Second fetch: fetchback after modification to correctly process inbound
assertShadowFetchOperationCountIncrement(2);
PrismObject<UserType> userJack = getUser(USER_JACK_OID);
display("User after change execution", userJack);
assertUserJack(userJack, "Jack Sparrow");
accountJackOid = getSingleLinkOid(userJack);
// Check shadow
PrismObject<ShadowType> accountShadow = repositoryService.getObject(ShadowType.class, accountJackOid, null, result);
assertDummyAccountShadowRepo(accountShadow, accountJackOid, USER_JACK_USERNAME);
// Check account
PrismObject<ShadowType> accountModel = modelService.getObject(ShadowType.class, accountJackOid, null, task, result);
assertDummyAccountShadowModel(accountModel, accountJackOid, USER_JACK_USERNAME, "Cpt. Jack Sparrow");
// Check account in dummy resource
assertDefaultDummyAccount(USER_JACK_USERNAME, "Cpt. Jack Sparrow", true);
DummyAccount dummyAccount = getDummyAccount(null, USER_JACK_USERNAME);
display(dummyAccount.debugDump());
assertDummyAccountAttribute(null, USER_JACK_USERNAME, DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_GOSSIP_NAME, "q");
//assertEquals("Missing or incorrect attribute value", "soda", dummyAccount.getAttributeValue(DummyResourceContoller.DUMMY_ACCOUNT_ATTRIBUTE_DRINK_NAME, String.class));
assertDummyScriptsModify(userJack, true);
// Check audit
display("Audit", dummyAuditService);
dummyAuditService.assertRecords(2);
dummyAuditService.assertSimpleRecordSanity();
dummyAuditService.assertAnyRequestDeltas();
Collection<ObjectDeltaOperation<? extends ObjectType>> auditExecutionDeltas = dummyAuditService.getExecutionDeltas();
assertEquals("Wrong number of execution deltas", 2, auditExecutionDeltas.size());
dummyAuditService.assertHasDelta(ChangeType.MODIFY, UserType.class);
dummyAuditService.assertHasDelta(ChangeType.MODIFY, ShadowType.class);
dummyAuditService.assertTarget(USER_JACK_OID);
dummyAuditService.assertExecutionSuccess();
assertScriptCompileIncrement(0);
assertSteadyResources();
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class AccCertExpressionHelper method evaluateRefExpression.
private List<ObjectReferenceType> evaluateRefExpression(ExpressionType expressionType, ExpressionVariables expressionVariables, String shortDesc, Task task, OperationResult result) throws ObjectNotFoundException, SchemaException, ExpressionEvaluationException {
QName resultName = new QName(SchemaConstants.NS_C, "result");
PrismReferenceDefinition resultDef = new PrismReferenceDefinitionImpl(resultName, ObjectReferenceType.COMPLEX_TYPE, prismContext);
Expression<PrismReferenceValue, PrismReferenceDefinition> expression = expressionFactory.makeExpression(expressionType, resultDef, shortDesc, task, result);
ExpressionEvaluationContext context = new ExpressionEvaluationContext(null, expressionVariables, shortDesc, task, result);
context.setAdditionalConvertor(ExpressionUtil.createRefConvertor(UserType.COMPLEX_TYPE));
PrismValueDeltaSetTriple<PrismReferenceValue> exprResult = ModelExpressionThreadLocalHolder.evaluateRefExpressionInContext(expression, context, task, result);
List<ObjectReferenceType> retval = new ArrayList<>();
for (PrismReferenceValue value : exprResult.getZeroSet()) {
ObjectReferenceType ort = new ObjectReferenceType();
ort.setupReferenceValue(value);
retval.add(ort);
}
return retval;
}
use of com.evolveum.midpoint.xml.ns._public.common.common_3.ExpressionType in project midpoint by Evolveum.
the class ExpressionHandlerImplTest method testConfirmUser.
@Test
@SuppressWarnings("unchecked")
public void testConfirmUser() throws Exception {
PrismObject<ShadowType> account = PrismTestUtil.parseObject(new File(TEST_FOLDER, "account-xpath-evaluation.xml"));
PrismObject<UserType> user = PrismTestUtil.parseObject(new File(TEST_FOLDER, "user-new.xml"));
//TODO: "$c:user/c:givenName/t:orig replaced with "$c:user/c:givenName
ExpressionType expression = PrismTestUtil.parseAtomicValue("<object xsi:type=\"ExpressionType\" xmlns=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\" " + "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "<script>\n" + "<language>http://www.w3.org/TR/xpath/</language>\n" + "<code>declare namespace c=\"http://midpoint.evolveum.com/xml/ns/public/common/common-3\";\n" + "declare namespace t=\"http://prism.evolveum.com/xml/ns/public/types-2\";\n" + "declare namespace dj=\"http://midpoint.evolveum.com/xml/ns/samples/localhostOpenDJ\";\n" + "$c:user/c:givenName = $c:account/c:attributes/dj:givenName</code>" + "</script>" + "</object>", ExpressionType.COMPLEX_TYPE);
OperationResult result = new OperationResult("testConfirmUser");
boolean confirmed = expressionHandler.evaluateConfirmationExpression(user.asObjectable(), account.asObjectable(), expression, null, result);
LOGGER.info(result.debugDump());
assertTrue("Wrong expression result (expected true)", confirmed);
}
Aggregations