use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class PrismUnmarshaller method parsePropertyValue.
// if definition == null or any AND node has type defined, this type must be non-containerable (fit into PPV)
private <T> PrismPropertyValue<T> parsePropertyValue(@NotNull XNode node, @Nullable PrismPropertyDefinition<T> definition, @NotNull ParsingContext pc) throws SchemaException {
QName typeFromDefinition = definition != null && !definition.isAnyType() ? definition.getTypeName() : null;
QName typeName = getSchemaRegistry().areComparable(typeFromDefinition, node.getTypeQName()) ? getSchemaRegistry().selectMoreSpecific(typeFromDefinition, node.getTypeQName()) : null;
if (typeName == null) {
return createRawPrismPropertyValue(node);
} else if (getBeanUnmarshaller().canProcess(typeName)) {
T realValue = getBeanUnmarshaller().unmarshal(node, typeName, pc);
// It also doesn't know about prism-specific things like allowed values, etc.
if (realValue instanceof PolyStringType) {
@SuppressWarnings("unchecked") T valueT = (T) ((PolyStringType) realValue).toPolyString();
realValue = valueT;
}
PrismUtil.recomputeRealValue(realValue, prismContext);
if (!isValueAllowed(realValue, definition)) {
pc.warnOrThrow(LOGGER, "Unknown (not allowed) value of type " + typeName + ". Value: " + realValue + ". Allowed values: " + definition.getAllowedValues());
return null;
}
if (realValue == null) {
// Be careful here. Expression element can be legal sub-element of complex properties.
// Therefore parse expression only if there is no legal value.
ExpressionWrapper expression = PrismUtil.parseExpression(node, prismContext);
if (expression != null) {
PrismPropertyValue<T> ppv = new PrismPropertyValue<>(null, prismContext, null, null, expression);
return ppv;
}
}
PrismPropertyValue<T> ppv = new PrismPropertyValue<>(realValue);
ppv.setPrismContext(prismContext);
return ppv;
} else {
pc.warnOrThrow(LOGGER, "Cannot parse as " + typeName + ": " + node.debugDump());
return createRawPrismPropertyValue(node);
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class JAXBUtilTest method testUnmarshallerUtf.
@Test
public void testUnmarshallerUtf() throws JAXBException, SchemaException, FileNotFoundException {
// GIVEN
UserType user = JaxbTestUtil.getInstance().unmarshalElement(new File("src/test/resources/util/user-utf8.xml"), UserType.class).getValue();
// WHEN
PolyStringType fullName = user.getFullName();
// THEN
assertTrue("National characters incorrectly decoded", "Jožko Nováčik".equals(fullName.getOrig()));
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class LensUtil method checkObjectPolicy.
private static <F extends ObjectType> void checkObjectPolicy(LensFocusContext<F> focusContext, ObjectPolicyConfigurationType objectPolicyConfigurationType) throws SchemaException, PolicyViolationException {
if (objectPolicyConfigurationType == null) {
return;
}
PrismObject<F> focusObjectNew = focusContext.getObjectNew();
ObjectDelta<F> focusDelta = focusContext.getDelta();
for (PropertyConstraintType propertyConstraintType : objectPolicyConfigurationType.getPropertyConstraint()) {
ItemPath itemPath = propertyConstraintType.getPath().getItemPath();
if (BooleanUtils.isTrue(propertyConstraintType.isOidBound())) {
if (focusDelta != null) {
if (focusDelta.isAdd()) {
PrismProperty<Object> propNew = focusObjectNew.findProperty(itemPath);
if (propNew != null) {
// prop delta is OK, but it has to match
if (focusObjectNew.getOid() != null) {
if (!focusObjectNew.getOid().equals(propNew.getRealValue().toString())) {
throw new PolicyViolationException("Cannot set " + itemPath + " to a value different than OID in oid bound mode");
}
}
}
} else {
PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(itemPath);
if (nameDelta != null) {
if (nameDelta.isReplace()) {
Collection<PrismPropertyValue<Object>> 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");
}
}
}
}
}
// Deprecated
if (BooleanUtils.isTrue(objectPolicyConfigurationType.isOidNameBoundMode())) {
if (focusDelta != null) {
if (focusDelta.isAdd()) {
PolyStringType namePolyType = focusObjectNew.asObjectable().getName();
if (namePolyType != null) {
// name delta is OK, but it has to match
if (focusObjectNew.getOid() != null) {
if (!focusObjectNew.getOid().equals(namePolyType.getOrig())) {
throw new PolicyViolationException("Cannot set name to a value different than OID in name-oid bound mode");
}
}
}
} else {
PropertyDelta<Object> nameDelta = focusDelta.findPropertyDelta(FocusType.F_NAME);
if (nameDelta != null) {
throw new PolicyViolationException("Cannot change name in name-oid bound mode");
}
}
}
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class InitialDataImport method init.
public void init() throws SchemaException {
LOGGER.info("Starting initial object import (if necessary).");
OperationResult mainResult = new OperationResult(OPERATION_INITIAL_OBJECTS_IMPORT);
Task task = taskManager.createTaskInstance(OPERATION_INITIAL_OBJECTS_IMPORT);
task.setChannel(SchemaConstants.CHANNEL_GUI_INIT_URI);
int count = 0;
int errors = 0;
File[] files = getInitialImportObjects();
LOGGER.debug("Files to be imported: {}.", Arrays.toString(files));
// We need to provide a fake Spring security context here.
// We have to fake it because we do not have anything in the repository yet. And to get
// something to the repository we need a context. Chicken and egg. So we fake the egg.
SecurityContext securityContext = SecurityContextHolder.getContext();
UserType userAdministrator = new UserType();
prismContext.adopt(userAdministrator);
userAdministrator.setName(new PolyStringType(new PolyString("initAdmin", "initAdmin")));
MidPointPrincipal principal = new MidPointPrincipal(userAdministrator);
AuthorizationType superAutzType = new AuthorizationType();
prismContext.adopt(superAutzType, RoleType.class, new ItemPath(RoleType.F_AUTHORIZATION));
superAutzType.getAction().add(AuthorizationConstants.AUTZ_ALL_URL);
Authorization superAutz = new Authorization(superAutzType);
Collection<Authorization> authorities = principal.getAuthorities();
authorities.add(superAutz);
Authentication authentication = new PreAuthenticatedAuthenticationToken(principal, null);
securityContext.setAuthentication(authentication);
for (File file : files) {
try {
LOGGER.debug("Considering initial import of file {}.", file.getName());
PrismObject object = prismContext.parseObject(file);
if (ReportType.class.equals(object.getCompileTimeClass())) {
ReportTypeUtil.applyDefinition(object, prismContext);
}
Boolean importObject = importObject(object, file, task, mainResult);
if (importObject == null) {
continue;
}
if (importObject) {
count++;
} else {
errors++;
}
} catch (Exception ex) {
LoggingUtils.logUnexpectedException(LOGGER, "Couldn't import file {}", ex, file.getName());
mainResult.recordFatalError("Couldn't import file '" + file.getName() + "'", ex);
}
}
securityContext.setAuthentication(null);
mainResult.recomputeStatus("Couldn't import objects.");
LOGGER.info("Initial object import finished ({} objects imported, {} errors)", count, errors);
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("Initialization status:\n" + mainResult.debugDump());
}
}
use of com.evolveum.prism.xml.ns._public.types_3.PolyStringType in project midpoint by Evolveum.
the class WebComponentUtil method createPolyFromOrigString.
public static PolyStringType createPolyFromOrigString(String str) {
if (str == null) {
return null;
}
PolyStringType poly = new PolyStringType();
poly.setOrig(str);
return poly;
}
Aggregations