use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class ModelInteractionServiceImpl method validateValue.
private <T, O extends ObjectType> boolean validateValue(PrismObject<O> object, ValuePolicyType policy, PolicyItemDefinitionType policyItemDefinition, Task task, OperationResult parentResult) throws ExpressionEvaluationException, SchemaException, ObjectNotFoundException, CommunicationException, ConfigurationException, SecurityViolationException, PolicyViolationException {
ValuePolicyType stringPolicy = resolveValuePolicy(policyItemDefinition, policy, task, parentResult);
Object value = policyItemDefinition.getValue();
String valueToValidate;
if (value instanceof RawType) {
valueToValidate = ((RawType) value).getParsedRealValue(String.class);
} else {
valueToValidate = (String) value;
}
List<String> valuesToValidate = new ArrayList<>();
PolicyItemTargetType target = policyItemDefinition.getTarget();
ItemPath path = target != null ? target.getPath().getItemPath() : null;
if (StringUtils.isNotEmpty(valueToValidate)) {
valuesToValidate.add(valueToValidate);
} else {
if (target == null || target.getPath() == null) {
LOGGER.error("Target item path must be defined");
parentResult.recordFatalError("Target item path must be defined");
throw new SchemaException("Target item path must be defined");
}
if (object == null) {
LOGGER.error("Object which values should be validated is null. Nothing to validate.");
parentResult.recordFatalError("Object which values should be validated is null. Nothing to validate.");
throw new SchemaException("Object which values should be validated is null. Nothing to validate.");
}
PrismProperty<T> property = object.findProperty(path);
if (property == null || property.isEmpty()) {
LOGGER.error("Attribute {} has no value. Nothing to validate.", property);
parentResult.recordFatalError("Attribute " + property + " has no value. Nothing to validate");
throw new SchemaException("Attribute " + property + " has no value. Nothing to validate");
}
PrismPropertyDefinition<T> itemToValidateDefinition = property.getDefinition();
QName definitionName = itemToValidateDefinition.getTypeName();
if (!isSupportedType(definitionName)) {
LOGGER.error("Trying to validate string policy on the property of type {} failed. Unsupported type.", itemToValidateDefinition);
parentResult.recordFatalError("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
throw new SchemaException("Trying to validate string policy on the property of type " + itemToValidateDefinition + " failed. Unsupported type.");
}
if (itemToValidateDefinition.isSingleValue()) {
if (definitionName.equals(PolyStringType.COMPLEX_TYPE)) {
valueToValidate = ((PolyString) property.getRealValue()).getOrig();
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
ProtectedStringType protectedString = ((ProtectedStringType) property.getRealValue());
valueToValidate = getClearValue(protectedString);
} else {
valueToValidate = (String) property.getRealValue();
}
valuesToValidate.add(valueToValidate);
} else {
if (definitionName.equals(DOMUtil.XSD_STRING)) {
valuesToValidate.addAll(property.getRealValues(String.class));
} else if (definitionName.equals(ProtectedStringType.COMPLEX_TYPE)) {
for (ProtectedStringType protectedString : property.getRealValues(ProtectedStringType.class)) {
valuesToValidate.add(getClearValue(protectedString));
}
} else {
for (PolyString val : property.getRealValues(PolyString.class)) {
valuesToValidate.add(val.getOrig());
}
}
}
}
for (String newValue : valuesToValidate) {
OperationResult result = parentResult.createSubresult(OPERATION_VALIDATE_VALUE + ".value");
if (path != null) {
result.addParam("path", path.toString());
}
result.addParam("valueToValidate", newValue);
ObjectValuePolicyEvaluator.Builder evaluatorBuilder = new ObjectValuePolicyEvaluator.Builder().valuePolicy(stringPolicy).valuePolicyProcessor(policyProcessor).protector(protector).valueItemPath(path).originResolver(getOriginResolver(object)).task(task).shortDesc(" rest validate ");
O objectable = object != null ? object.asObjectable() : null;
if (path != null && objectable instanceof FocusType) {
// noinspection unchecked
PrismObject<? extends FocusType> focus = (PrismObject<? extends FocusType>) object;
if (path.isSuperPathOrEquivalent(SchemaConstants.PATH_PASSWORD)) {
evaluatorBuilder.securityPolicy(getSecurityPolicy(focus, task, parentResult));
PrismContainer<PasswordType> passwordContainer = focus.findContainer(SchemaConstants.PATH_PASSWORD);
PasswordType password = passwordContainer != null ? passwordContainer.getValue().asContainerable() : null;
evaluatorBuilder.oldCredential(password);
} else if (path.isSuperPathOrEquivalent(SchemaConstants.PATH_SECURITY_QUESTIONS)) {
LOGGER.trace("Setting security questions related policy.");
SecurityPolicyType securityPolicy = getSecurityPolicy(focus, task, parentResult);
evaluatorBuilder.securityPolicy(securityPolicy);
PrismContainer<SecurityQuestionsCredentialsType> securityQuestionsContainer = focus.findContainer(SchemaConstants.PATH_SECURITY_QUESTIONS);
SecurityQuestionsCredentialsType securityQuestions = securityQuestionsContainer != null ? securityQuestionsContainer.getValue().asContainerable() : null;
// evaluatorBuilder.oldCredentialType(securityQuestions); // TODO what with this?
evaluatorBuilder.valuePolicy(resolveSecurityQuestionsPolicy(securityPolicy, task, parentResult));
}
}
evaluatorBuilder.now(clock.currentTimeXMLGregorianCalendar());
LOGGER.trace("Validating value started");
evaluatorBuilder.build().validateStringValue(newValue, result);
LOGGER.trace("Validating value finished");
//
result.computeStatus();
// if (!policyProcessor.validateValue(newValue, stringPolicy, createOriginResolver(object, result), "validate value " + (path!= null ? "for " + path : "") + " for " + object + " value " + valueToValidate, task, result)) {
// result.recordFatalError("Validation for value " + newValue + " against policy " + stringPolicy + " failed");
// LOGGER.error("Validation for value {} against policy {} failed", newValue, stringPolicy);
// }
}
parentResult.computeStatus();
policyItemDefinition.setResult(parentResult.createOperationResultType());
return parentResult.isAcceptable();
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class StaticExpressionUtil method serializeValueElements.
public static <IV extends PrismValue, ID extends ItemDefinition> List<JAXBElement<RawType>> serializeValueElements(Item<IV, ID> item) throws SchemaException {
if (item == null) {
return null;
}
List<JAXBElement<RawType>> elements = new ArrayList<>(item.size());
for (PrismValue value : item.getValues()) {
RootXNode xnode = item.getPrismContext().xnodeSerializer().serialize(value);
RawType rawType = new RawType(xnode.getSubnode().frozen(), item.getPrismContext());
JAXBElement<RawType> jaxbElement = new JAXBElement<>(SchemaConstants.C_VALUE, RawType.class, rawType);
elements.add(jaxbElement);
}
return elements;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class StaticExpressionUtil method parseValueElements.
public static <IV extends PrismValue, ID extends ItemDefinition> Item<IV, ID> parseValueElements(Collection<?> valueElements, ID outputDefinition, String contextDescription) throws SchemaException {
Item<IV, ID> output = null;
for (Object valueElement : valueElements) {
RawType rawType = getRawType(valueElement, contextDescription);
Item<IV, ID> elementItem = rawType.getParsedItem(outputDefinition);
if (output == null) {
output = elementItem;
} else {
output.addAll(elementItem.getClonedValues());
}
}
return output;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class StaticExpressionUtil method parseValueElements.
/**
* Parses value elements without definitions into raw values - this allows further conversion.
*/
public static List<Object> parseValueElements(Collection<?> valueElements, String contextDescription) throws SchemaException {
List<Object> values = new ArrayList<>();
for (Object valueElement : valueElements) {
RawType rawType = getRawType(valueElement, contextDescription);
Object rawValue = rawType.getParsedRealValue(null, null);
// User has always the option to use the xsi:type for value to avoid RawType.Raw value.
if (!rawType.isParsed()) {
rawValue = rawType.getValue();
}
values.add(rawValue);
}
return values;
}
use of com.evolveum.prism.xml.ns._public.types_3.RawType in project midpoint by Evolveum.
the class TransformationBuiltinMapping method applyForTransformation.
/**
* Transformation merges the acquisitions into single yield.
*/
@Override
public void applyForTransformation(@NotNull TransformationalMetadataComputation computation) {
List<PrismValue> input = computation.getInputValues();
LOGGER.trace("Computing transformation metadata during value transformation. Input values:\n{}", lazy(() -> dumpInput(input)));
MappingTransformationType mappingTransformation = new MappingTransformationType(prismContext).mappingSpecification(computation.getMappingSpecification());
List<QName> sourceNames = computation.getSourceNames();
if (computation.getInputValues().size() < sourceNames.size()) {
throw new IllegalStateException("Couldn't compute transformational metadata: there are less values (" + computation.getInputValues().size() + ") than sources (" + sourceNames.size() + ") in " + computation.getContextDescription());
}
for (int i = 0; i < sourceNames.size(); i++) {
MappingSourceType source = new MappingSourceType(prismContext);
QName sourceName = sourceNames.get(i);
if (sourceName != null) {
source.setName(sourceName.getLocalPart());
}
PrismValue inputValue = computation.getInputValues().get(i);
if (inputValue != null) {
PrismValue inputValueClone = inputValue.clone();
markNotTransient(inputValueClone);
source.setValue(new RawType(inputValueClone, null, prismContext));
}
mappingTransformation.getSource().add(source);
}
TransformationMetadataType transformation = new TransformationMetadataType(prismContext).mappingTransformation(mappingTransformation);
LOGGER.trace("Output: transformation:\n{}", lazy(() -> transformation.asPrismContainerValue().debugDump()));
computation.getOutputMetadataValueBean().setTransformation(transformation);
}
Aggregations