Search in sources :

Example 11 with PolyStringType

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);
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) QName(javax.xml.namespace.QName)

Example 12 with PolyStringType

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()));
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) File(java.io.File) Test(org.testng.annotations.Test)

Example 13 with PolyStringType

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");
                }
            }
        }
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 14 with PolyStringType

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());
    }
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType) Task(com.evolveum.midpoint.task.api.Task) PreAuthenticatedAuthenticationToken(org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken) OperationResult(com.evolveum.midpoint.schema.result.OperationResult) URISyntaxException(java.net.URISyntaxException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) IOException(java.io.IOException) Authorization(com.evolveum.midpoint.security.api.Authorization) PrismObject(com.evolveum.midpoint.prism.PrismObject) Authentication(org.springframework.security.core.Authentication) PolyString(com.evolveum.midpoint.prism.polystring.PolyString) SecurityContext(org.springframework.security.core.context.SecurityContext) AuthorizationType(com.evolveum.midpoint.xml.ns._public.common.common_3.AuthorizationType) File(java.io.File) UserType(com.evolveum.midpoint.xml.ns._public.common.common_3.UserType) MidPointPrincipal(com.evolveum.midpoint.security.api.MidPointPrincipal) ItemPath(com.evolveum.midpoint.prism.path.ItemPath)

Example 15 with PolyStringType

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;
}
Also used : PolyStringType(com.evolveum.prism.xml.ns._public.types_3.PolyStringType)

Aggregations

PolyStringType (com.evolveum.prism.xml.ns._public.types_3.PolyStringType)94 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)28 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)26 Test (org.testng.annotations.Test)23 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)20 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)14 SchemaException (com.evolveum.midpoint.util.exception.SchemaException)12 AssignmentType (com.evolveum.midpoint.xml.ns._public.common.common_3.AssignmentType)12 QName (javax.xml.namespace.QName)11 Task (com.evolveum.midpoint.task.api.Task)10 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)10 File (java.io.File)10 PrismObject (com.evolveum.midpoint.prism.PrismObject)9 OrgType (com.evolveum.midpoint.xml.ns._public.common.common_3.OrgType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 ArrayList (java.util.ArrayList)7 ResourceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ResourceType)5 AbstractInternalModelIntegrationTest (com.evolveum.midpoint.model.impl.AbstractInternalModelIntegrationTest)4 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)4 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)4