Search in sources :

Example 41 with PrismProperty

use of com.evolveum.midpoint.prism.PrismProperty in project midpoint by Evolveum.

the class CredentialsProcessor method transformFocusExectionDeltaCredential.

private <O extends ObjectType> void transformFocusExectionDeltaCredential(LensContext<O> context, CredentialsPolicyType credsType, CredentialPolicyType credPolicyType, ItemPath valuePropertyPath, ObjectDelta<O> delta) throws SchemaException, EncryptionException {
    if (delta.isDelete()) {
        return;
    }
    CredentialPolicyType defaltCredPolicyType = credsType.getDefault();
    CredentialsStorageMethodType storageMethod = SecurityUtil.getCredPolicyItem(defaltCredPolicyType, credPolicyType, pol -> pol.getStorageMethod());
    if (storageMethod == null) {
        return;
    }
    CredentialsStorageTypeType storageType = storageMethod.getStorageType();
    if (storageType == null || storageType == CredentialsStorageTypeType.ENCRYPTION) {
        return;
    } else if (storageType == CredentialsStorageTypeType.HASHING) {
        PrismPropertyValue<ProtectedStringType> pval = null;
        if (delta.isAdd()) {
            PrismProperty<ProtectedStringType> prop = delta.getObjectToAdd().findProperty(valuePropertyPath);
            hashValues(prop.getValues(), storageMethod);
        } else {
            PropertyDelta<ProtectedStringType> propDelta = delta.findPropertyDelta(valuePropertyPath);
            if (propDelta != null) {
                hashValues(propDelta.getValuesToAdd(), storageMethod);
                hashValues(propDelta.getValuesToReplace(), storageMethod);
                hashValues(propDelta.getValuesToDelete(), storageMethod);
            }
        }
    } else if (storageType == CredentialsStorageTypeType.NONE) {
        if (delta.isAdd()) {
            delta.getObjectToAdd().removeProperty(valuePropertyPath);
        } else {
            PropertyDelta<ProtectedStringType> propDelta = delta.findPropertyDelta(valuePropertyPath);
            if (propDelta != null) {
                // Replace with nothing. We need this to clear any existing value that there might be.
                propDelta.setValueToReplace();
            }
        }
    } else {
        throw new SchemaException("Unkwnon storage type " + storageType);
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) PrismProperty(com.evolveum.midpoint.prism.PrismProperty) CredentialsStorageTypeType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsStorageTypeType) CredentialsStorageMethodType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialsStorageMethodType) PropertyDelta(com.evolveum.midpoint.prism.delta.PropertyDelta) ProtectedStringType(com.evolveum.prism.xml.ns._public.types_3.ProtectedStringType) CredentialPolicyType(com.evolveum.midpoint.xml.ns._public.common.common_3.CredentialPolicyType) PrismPropertyValue(com.evolveum.midpoint.prism.PrismPropertyValue)

Aggregations

PrismProperty (com.evolveum.midpoint.prism.PrismProperty)41 PrismObject (com.evolveum.midpoint.prism.PrismObject)14 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)13 QName (javax.xml.namespace.QName)13 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 ArrayList (java.util.ArrayList)11 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)8 PrismContainer (com.evolveum.midpoint.prism.PrismContainer)7 SystemException (com.evolveum.midpoint.util.exception.SystemException)7 Containerable (com.evolveum.midpoint.prism.Containerable)6 PrismPropertyValue (com.evolveum.midpoint.prism.PrismPropertyValue)6 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)6 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)6 Test (org.testng.annotations.Test)6 PropertyDelta (com.evolveum.midpoint.prism.delta.PropertyDelta)5 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)5 Item (com.evolveum.midpoint.prism.Item)4 PrismPropertyDefinition (com.evolveum.midpoint.prism.PrismPropertyDefinition)4 Task (com.evolveum.midpoint.task.api.Task)4