Search in sources :

Example 41 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ObjectWrapperTest method testEmptyPolyString.

@Test
public void testEmptyPolyString() throws Exception {
    PrismObject<UserType> user = prismContext.parseObject(new File("./src/test/resources/wrapper/user.xml"));
    Task task = taskManager.createTaskInstance("testEmptyPolyString");
    ObjectWrapperFactory owf = new ObjectWrapperFactory(null);
    ObjectWrapper<UserType> wrapper = owf.createObjectWrapper(null, null, user, ContainerStatus.MODIFYING, task);
    //simulate change on honorific prefix
    ContainerWrapper containerWrapper = null;
    for (ContainerWrapper container : wrapper.getContainers()) {
        if (container.isMain()) {
            containerWrapper = container;
            break;
        }
    }
    PropertyWrapper propertyWrapper = (PropertyWrapper) containerWrapper.findPropertyWrapper(UserType.F_HONORIFIC_SUFFIX);
    ValueWrapper valueWrapper = (ValueWrapper) propertyWrapper.getValues().get(0);
    PolyString value = (PolyString) ((PrismPropertyValue) valueWrapper.getValue()).getValue();
    Field orig = PolyString.class.getDeclaredField("orig");
    orig.setAccessible(true);
    orig.set(value, null);
    orig.setAccessible(false);
    ObjectDelta delta = wrapper.getObjectDelta();
    AssertJUnit.assertNotNull(delta);
}
Also used : Field(java.lang.reflect.Field) Task(com.evolveum.midpoint.task.api.Task) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ObjectDelta(com.evolveum.midpoint.prism.delta.ObjectDelta) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) Test(org.testng.annotations.Test)

Example 42 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ModelInteractionServiceImpl method collectDeltasForGeneratedValuesIfNeeded.

private <O extends ObjectType> void collectDeltasForGeneratedValuesIfNeeded(PrismObject<O> object, PolicyItemDefinitionType policyItemDefinition, Collection<PropertyDelta<?>> deltasToExecute, ItemPath path, PrismPropertyDefinition<?> itemDef) throws SchemaException {
    Object value = policyItemDefinition.getValue();
    if (ProtectedStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
        ProtectedStringType pst = new ProtectedStringType();
        pst.setClearValue((String) value);
        value = pst;
    } else if (PolyStringType.COMPLEX_TYPE.equals(itemDef.getTypeName())) {
        value = new PolyString((String) value);
    }
    PropertyDelta<?> propertyDelta = PropertyDelta.createModificationReplaceProperty(path, object.getDefinition(), value);
    // in bulk actions we need to modify original objects - hope that REST is OK with this
    propertyDelta.applyTo(object);
    if (BooleanUtils.isTrue(policyItemDefinition.isExecute())) {
        deltasToExecute.add(propertyDelta);
    }
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)

Example 43 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString 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);
    RawType rawValue = (RawType) policyItemDefinition.getValue();
    String valueToValidate = null;
    List<String> valuesToValidate = new ArrayList<>();
    PolicyItemTargetType target = policyItemDefinition.getTarget();
    ItemPath path = null;
    if (target != null) {
        path = target.getPath().getItemPath();
    }
    if (rawValue != null) {
        valueToValidate = rawValue.getParsedRealValue(String.class);
        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");
        }
        path = target.getPath().getItemPath();
        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);
        result.addParam("valueToValidate", newValue);
        if (!policyProcessor.validateValue(newValue, stringPolicy, object, "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);
        }
        result.computeStatusIfUnknown();
    }
    parentResult.computeStatus();
    policyItemDefinition.setResult(parentResult.createOperationResultType());
    return parentResult.isAcceptable();
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) QName(javax.xml.namespace.QName) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) RawType(com.evolveum.prism.xml.ns._public.types_3.RawType) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) PolicyItemTargetType(com.evolveum.midpoint.xml.ns._public.common.api_types_3.PolicyItemTargetType) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 44 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ModelDiagController method checkObjectPropertyPolyString.

private <O extends ObjectType> void checkObjectPropertyPolyString(PrismObject<O> object, QName propQName, OperationResult parentResult, String... expectedValues) {
    String propName = propQName.getLocalPart();
    OperationResult result = parentResult.createSubresult(parentResult.getOperation() + "." + propName);
    PrismProperty<PolyString> prop = object.findProperty(propQName);
    Collection<PolyString> actualValues = prop.getRealValues();
    result.addArbitraryCollectionAsParam("actualValues", actualValues);
    assertMultivaluePolyString("User, property '" + propName + "'", expectedValues, actualValues, result);
    result.recordSuccessIfUnknown();
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) RandomString(com.evolveum.midpoint.util.RandomString) PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Example 45 with PolyString

use of com.evolveum.midpoint.prism.polystring.PolyString in project midpoint by Evolveum.

the class ModelDiagController method toPolyString.

private PolyString toPolyString(String orig) {
    PolyString polyString = new PolyString(orig);
    polyString.recompute(prismContext.getDefaultPolyStringNormalizer());
    return polyString;
}
Also used : PolyString(com.evolveum.midpoint.prism.polystring.PolyString)

Aggregations

PolyString (com.evolveum.midpoint.prism.polystring.PolyString)168 Test (org.testng.annotations.Test)103 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)90 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)67 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)53 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)44 Task (com.evolveum.midpoint.task.api.Task)41 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)27 PrismObject (com.evolveum.midpoint.prism.PrismObject)21 QName (javax.xml.namespace.QName)18 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)17 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)16 PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)15 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)12 ArrayList (java.util.ArrayList)12 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)10 File (java.io.File)10 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)9 PrismReferenceValue (com.evolveum.midpoint.prism.PrismReferenceValue)8 ProtectedStringType (com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType)8