use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class Expression method processInnerVariables.
private ExpressionVariables processInnerVariables(ExpressionVariables variables, String contextDescription, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException {
if (expressionType == null) {
// shortcut
return variables;
}
ExpressionVariables newVariables = new ExpressionVariables();
// We need to add actor variable before we switch user identity (runAs)
ExpressionUtil.addActorVariable(newVariables, securityEnforcer);
for (Entry<QName, Object> entry : variables.entrySet()) {
newVariables.addVariableDefinition(entry.getKey(), entry.getValue());
}
for (ExpressionVariableDefinitionType variableDefType : expressionType.getVariable()) {
QName varName = variableDefType.getName();
if (varName == null) {
throw new SchemaException("No variable name in expression in " + contextDescription);
}
if (variableDefType.getObjectRef() != null) {
ObjectReferenceType ref = variableDefType.getObjectRef();
ref.setType(prismContext.getSchemaRegistry().qualifyTypeName(ref.getType()));
ObjectType varObject = objectResolver.resolve(ref, ObjectType.class, null, "variable " + varName + " in " + contextDescription, task, result);
newVariables.addVariableDefinition(varName, varObject);
} else if (variableDefType.getValue() != null) {
// Only string is supported now
Object valueObject = variableDefType.getValue();
if (valueObject instanceof String) {
newVariables.addVariableDefinition(varName, valueObject);
} else if (valueObject instanceof Element) {
newVariables.addVariableDefinition(varName, ((Element) valueObject).getTextContent());
} else if (valueObject instanceof RawType) {
newVariables.addVariableDefinition(varName, ((RawType) valueObject).getParsedValue(null, varName));
} else {
throw new SchemaException("Unexpected type " + valueObject.getClass() + " in variable definition " + varName + " in " + contextDescription);
}
} else if (variableDefType.getPath() != null) {
ItemPath itemPath = variableDefType.getPath().getItemPath();
Object resolvedValue = ExpressionUtil.resolvePath(itemPath, variables, null, objectResolver, contextDescription, task, result);
newVariables.addVariableDefinition(varName, resolvedValue);
} else {
throw new SchemaException("No value for variable " + varName + " in " + contextDescription);
}
}
return newVariables;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType 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.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class TestSanityLegacy method test502NotifyChangeModifyAccountPassword.
@Test
public void test502NotifyChangeModifyAccountPassword() throws Exception {
TestUtil.displayTestTile("test502NotifyChangeModifyAccountPassword");
OperationResult parentResult = new OperationResult("test500notifyChange.addAngelicaAccount");
PrismObject<UserType> userAngelika = findUserByUsername(ANGELIKA_NAME);
assertNotNull("User with the name angelika must exist.", userAngelika);
UserType user = userAngelika.asObjectable();
assertNotNull("User with the name angelika must have one link ref.", user.getLinkRef());
assertEquals("Expected one account ref in user", 1, user.getLinkRef().size());
String oid = user.getLinkRef().get(0).getOid();
// PrismObject<ShadowType> angelicaAcc = modelService.getObject(ShadowType.class, oid, null, taskManager.createTaskInstance(), parentResult);
// ShadowType angelicaShadowType = angelicaAcc.asObjectable();
String newPassword = "newPassword";
// ProtectedStringType decrypted= ModelClientUtil.createProtectedString(newPassword);
// protector.encrypt(decrypted);
// angelicaShadowType.getCredentials().getPassword().setValue(decrypted);
ResourceObjectShadowChangeDescriptionType changeDescription = new ResourceObjectShadowChangeDescriptionType();
ObjectDeltaType delta = new ObjectDeltaType();
delta.setChangeType(ChangeTypeType.MODIFY);
delta.setObjectType(ShadowType.COMPLEX_TYPE);
Document doc = DOMUtil.getDocument();
ItemDeltaType passwordDelta = new ItemDeltaType();
passwordDelta.setModificationType(ModificationTypeType.REPLACE);
passwordDelta.setPath(ModelClientUtil.createItemPathType("credentials/password/value"));
RawType passwordValue = new RawType(((PrismContextImpl) prismContext).getBeanMarshaller().marshall(ModelClientUtil.createProtectedString(newPassword)), prismContext);
passwordDelta.getValue().add(passwordValue);
// ItemDeltaType mod1 = new ItemDeltaType();
// mod1.setModificationType(ModificationTypeType.REPLACE);
// ModelClientUtil.createProtectedString(clearValue)
// XPathHolder xpath = new XPathHolder(SchemaConstants.PATH_PASSWORD);
// Element path = xpath.toElement(SchemaConstantsGenerated.NS_TYPES, "path");
// mod1.setPath(path);
// String newPassword = "newPassword";
// ItemDeltaType.Value value = new ItemDeltaType.Value();
// Document doc = DOMUtil.getDocument();
// Element el = DOMUtil.createElement(doc, SchemaConstantsGenerated.C_VALUE);
// Element passwdEl = DOMUtil.createElement(doc, new QName(SchemaConstants.NS_C, "clearValue"));
// passwdEl.setTextContent(newPassword);
// el.appendChild(passwdEl);
// value.getAny().add(el);
// mod1.setValue(value);
// delta.getModification().add(mod1);
delta.getItemDelta().add(passwordDelta);
delta.setOid(oid);
LOGGER.info("item delta: {}", SchemaDebugUtil.prettyPrint(passwordDelta));
LOGGER.info("delta: {}", DebugUtil.dump(passwordDelta));
changeDescription.setObjectDelta(delta);
changeDescription.setOldShadowOid(oid);
// changeDescription.setCurrentShadow(angelicaShadowType);
changeDescription.setChannel(SchemaConstants.CHANNEL_WEB_SERVICE_URI);
TaskType task = modelWeb.notifyChange(changeDescription);
OperationResult result = OperationResult.createOperationResult(task.getResult());
display(result);
assertSuccess(result);
PrismObject<UserType> userAngelikaAfterSync = findUserByUsername(ANGELIKA_NAME);
assertNotNull("User with the name angelika must exist.", userAngelikaAfterSync);
assertPassword(userAngelikaAfterSync, newPassword);
// UserType userAfterSync = userAngelikaAfterSync.asObjectable();
// PrismAsserts.assertEqualsPolyString("wrong given name in user angelika", PrismTestUtil.createPolyStringType("newAngelika"), userAfterSync.getGivenName());
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class RawTypeUtil method getParsedItem.
public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> getParsedItem(ID itemDefinition, List<RawType> values, QName elementQName, PrismContainerDefinition containerDef) throws SchemaException {
Item<IV, ID> subItem = null;
List<IV> parsedValues = new ArrayList<IV>();
for (RawType rawValue : values) {
if (itemDefinition == null && containerDef != null) {
itemDefinition = (ID) ((PrismContextImpl) containerDef.getPrismContext()).getPrismUnmarshaller().locateItemDefinition(containerDef, elementQName, rawValue.getXnode());
}
IV parsed = rawValue.getParsedValue(itemDefinition, elementQName);
if (parsed != null) {
parsedValues.add(parsed);
}
}
PrismContext prismContext = null;
if (containerDef != null) {
prismContext = containerDef.getPrismContext();
}
if (prismContext == null && itemDefinition != null) {
prismContext = itemDefinition.getPrismContext();
}
if (itemDefinition == null) {
PrismProperty property = new PrismProperty(elementQName, prismContext);
property.addAll(PrismValue.cloneCollection(parsedValues));
return property;
}
if (itemDefinition instanceof PrismPropertyDefinition<?>) {
// property
PrismProperty<?> property = ((PrismPropertyDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
property.add((PrismPropertyValue) val.clone());
}
subItem = (Item<IV, ID>) property;
} else if (itemDefinition instanceof PrismContainerDefinition<?>) {
PrismContainer<?> container = ((PrismContainerDefinition<?>) itemDefinition).instantiate();
for (IV val : parsedValues) {
container.add((PrismContainerValue) val.clone());
}
subItem = (Item<IV, ID>) container;
} else if (itemDefinition instanceof PrismReferenceDefinition) {
// TODO
PrismReference reference = ((PrismReferenceDefinition) itemDefinition).instantiate();
for (IV val : parsedValues) {
PrismReferenceValue ref;
if (val instanceof PrismReferenceValue) {
ref = (PrismReferenceValue) val.clone();
} else if (val instanceof PrismContainerValue) {
// this is embedded (full) object
Containerable c = ((PrismContainerValue) val).asContainerable();
if (!(c instanceof Objectable)) {
throw new IllegalStateException("Content of " + itemDefinition + " is a Containerable but not Objectable: " + c);
}
Objectable o = (Objectable) c;
ref = new PrismReferenceValue();
ref.setObject(o.asPrismObject());
} else {
throw new IllegalStateException("Content of " + itemDefinition + " is neither PrismReferenceValue nor PrismContainerValue: " + val);
}
reference.merge(ref);
}
subItem = (Item<IV, ID>) reference;
} else {
throw new IllegalArgumentException("Unsupported definition type " + itemDefinition.getClass());
}
return subItem;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ChangeExecutor method evaluateScriptArgument.
private void evaluateScriptArgument(ProvisioningScriptArgumentType argument, ExpressionVariables variables, LensContext<?> context, LensElementContext<?> objectContext, Task task, OperationResult result) throws SchemaException, ObjectNotFoundException, ExpressionEvaluationException {
QName FAKE_SCRIPT_ARGUMENT_NAME = new QName(SchemaConstants.NS_C, "arg");
PrismPropertyDefinition<String> scriptArgumentDefinition = new PrismPropertyDefinitionImpl<>(FAKE_SCRIPT_ARGUMENT_NAME, DOMUtil.XSD_STRING, prismContext);
String shortDesc = "Provisioning script argument expression";
Expression<PrismPropertyValue<String>, PrismPropertyDefinition<String>> expression = expressionFactory.makeExpression(argument, scriptArgumentDefinition, shortDesc, task, result);
ExpressionEvaluationContext params = new ExpressionEvaluationContext(null, variables, shortDesc, task, result);
PrismValueDeltaSetTriple<PrismPropertyValue<String>> outputTriple = ModelExpressionThreadLocalHolder.evaluateExpressionInContext(expression, params, context, objectContext instanceof LensProjectionContext ? (LensProjectionContext) objectContext : null, task, result);
Collection<PrismPropertyValue<String>> nonNegativeValues = null;
if (outputTriple != null) {
nonNegativeValues = outputTriple.getNonNegativeValues();
}
// replace dynamic script with static value..
argument.getExpressionEvaluator().clear();
if (nonNegativeValues == null || nonNegativeValues.isEmpty()) {
// We need to create at least one evaluator. Otherwise the
// expression code will complain
// Element value = DOMUtil.createElement(SchemaConstants.C_VALUE);
// DOMUtil.setNill(value);
JAXBElement<RawType> el = new JAXBElement(SchemaConstants.C_VALUE, RawType.class, new RawType(prismContext));
argument.getExpressionEvaluator().add(el);
} else {
for (PrismPropertyValue<String> val : nonNegativeValues) {
// Element value =
// DOMUtil.createElement(SchemaConstants.C_VALUE);
// value.setTextContent(val.getValue());
PrimitiveXNode<String> prim = new PrimitiveXNode<>();
prim.setValue(val.getValue(), DOMUtil.XSD_STRING);
JAXBElement<RawType> el = new JAXBElement(SchemaConstants.C_VALUE, RawType.class, new RawType(prim, prismContext));
argument.getExpressionEvaluator().add(el);
}
}
}
Aggregations