Search in sources :

Example 16 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class DistinguishedNameMatchingRule method match.

/* (non-Javadoc)
	 * @see com.evolveum.midpoint.model.match.MatchingRule#match(java.lang.Object, java.lang.Object)
	 */
@Override
public boolean match(String a, String b) throws SchemaException {
    if (StringUtils.isBlank(a) && StringUtils.isBlank(b)) {
        return true;
    }
    if (StringUtils.isBlank(a) || StringUtils.isBlank(b)) {
        return false;
    }
    LdapName dnA;
    try {
        dnA = new LdapName(a);
    } catch (InvalidNameException e) {
        throw new SchemaException("String '" + a + "' is not a DN: " + e.getMessage(), e);
    }
    LdapName dnB;
    try {
        dnB = new LdapName(b);
    } catch (InvalidNameException e) {
        throw new SchemaException("String '" + b + "' is not a DN: " + e.getMessage(), e);
    }
    return dnA.equals(dnB);
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) InvalidNameException(javax.naming.InvalidNameException) LdapName(javax.naming.ldap.LdapName)

Example 17 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class SchemaToDomProcessor method parseSchema.

/**
	 * Main entry point.
	 * 
	 * @param schema midPoint schema
	 * @return XSD schema in DOM form
	 * @throws SchemaException error parsing the midPoint schema or converting values
	 */
@NotNull
Document parseSchema(PrismSchema schema) throws SchemaException {
    if (schema == null) {
        throw new IllegalArgumentException("Schema can't be null.");
    }
    this.schema = schema;
    try {
        // here the document is initialized
        init();
        // Process complex types first. 
        Collection<ComplexTypeDefinition> complexTypes = schema.getDefinitions(ComplexTypeDefinition.class);
        for (ComplexTypeDefinition complexTypeDefinition : complexTypes) {
            addComplexTypeDefinition(complexTypeDefinition, document.getDocumentElement());
        }
        Collection<Definition> definitions = schema.getDefinitions();
        for (Definition definition : definitions) {
            if (definition instanceof PrismContainerDefinition) {
                // Add property container definition. This will add <complexType> and <element> definitions to XSD
                addContainerDefinition((PrismContainerDefinition) definition, document.getDocumentElement(), document.getDocumentElement());
            } else if (definition instanceof PrismPropertyDefinition) {
                // Add top-level property definition. It will create <element> XSD definition
                addPropertyDefinition((PrismPropertyDefinition) definition, document.getDocumentElement());
            } else if (definition instanceof ComplexTypeDefinition) {
            // Skip this. Already processed above.
            } else {
                throw new IllegalArgumentException("Encountered unsupported definition in schema: " + definition);
            }
        // TODO: process unprocessed ComplexTypeDefinitions
        }
        // Add import definition. These were accumulated during previous processing.
        addImports();
    } catch (Exception ex) {
        throw new SchemaException("Couldn't parse schema, reason: " + ex.getMessage(), ex);
    }
    return document;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class SchemaRegistryImpl method initialize.

/**
	 * This can be used to read additional schemas even after the registry was initialized.
	 */
@Override
public void initialize() throws SAXException, IOException, SchemaException {
    if (prismContext == null) {
        throw new IllegalStateException("Prism context not set");
    }
    if (namespacePrefixMapper == null) {
        throw new IllegalStateException("Namespace prefix mapper not set");
    }
    try {
        // TODO remove (all of these)
        LOGGER.trace("initialize() starting");
        initResolver();
        LOGGER.trace("initResolver() done");
        parsePrismSchemas();
        LOGGER.trace("parsePrismSchemas() done");
        parseJavaxSchema();
        LOGGER.trace("parseJavaxSchema() done");
        compileCompileTimeClassList();
        LOGGER.trace("compileCompileTimeClassList() done");
        initialized = true;
    } catch (SAXException ex) {
        if (ex instanceof SAXParseException) {
            SAXParseException sex = (SAXParseException) ex;
            throw new SchemaException("Error parsing schema " + sex.getSystemId() + " line " + sex.getLineNumber() + ": " + sex.getMessage(), sex);
        }
        throw ex;
    }
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SAXParseException(org.xml.sax.SAXParseException) SAXException(org.xml.sax.SAXException)

Example 19 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class DomToSchemaProcessor method parseSchema.

private XSSchemaSet parseSchema(Element schema) throws SchemaException {
    // Make sure that the schema parser sees all the namespace declarations
    DOMUtil.fixNamespaceDeclarations(schema);
    XSSchemaSet xss = null;
    try {
        TransformerFactory transfac = TransformerFactory.newInstance();
        Transformer trans = transfac.newTransformer();
        trans.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
        trans.setOutputProperty(OutputKeys.INDENT, "yes");
        DOMSource source = new DOMSource(schema);
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        StreamResult result = new StreamResult(out);
        trans.transform(source, result);
        XSOMParser parser = createSchemaParser();
        InputSource inSource = new InputSource(new ByteArrayInputStream(out.toByteArray()));
        // XXX: hack: it's here to make entity resolver work...
        inSource.setSystemId("SystemId");
        // XXX: end hack
        inSource.setEncoding("utf-8");
        parser.parse(inSource);
        xss = parser.getResult();
    } catch (SAXException e) {
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + "(embedded exception " + e.getException() + ") in " + shortDescription, e);
    } catch (TransformerException e) {
        throw new SchemaException("XML transformer error during XSD schema parsing: " + e.getMessage() + "(locator: " + e.getLocator() + ", embedded exception:" + e.getException() + ") in " + shortDescription, e);
    } catch (RuntimeException e) {
        // This sometimes happens, e.g. NPEs in Saxon
        if (LOGGER.isErrorEnabled()) {
            LOGGER.error("Unexpected error {} during parsing of schema:\n{}", e.getMessage(), DOMUtil.serializeDOMToString(schema));
        }
        throw new SchemaException("XML error during XSD schema parsing: " + e.getMessage() + " in " + shortDescription, e);
    }
    return xss;
}
Also used : SchemaException(com.evolveum.midpoint.util.exception.SchemaException) DOMSource(javax.xml.transform.dom.DOMSource) InputSource(org.xml.sax.InputSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) XSOMParser(com.sun.xml.xsom.parser.XSOMParser) StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SAXException(org.xml.sax.SAXException) ByteArrayInputStream(java.io.ByteArrayInputStream) TransformerException(javax.xml.transform.TransformerException)

Example 20 with SchemaException

use of com.evolveum.midpoint.util.exception.SchemaException in project midpoint by Evolveum.

the class AccessCertificationCloseStageTriggerHandler method handle.

@Override
public <O extends ObjectType> void handle(PrismObject<O> prismObject, TriggerType trigger, Task task, OperationResult result) {
    try {
        ObjectType object = prismObject.asObjectable();
        if (!(object instanceof AccessCertificationCampaignType)) {
            LOGGER.error("Trigger of this type is supported only on {} objects, not on {}", AccessCertificationCampaignType.class.getSimpleName(), object.getClass().getName());
            return;
        }
        AccessCertificationCampaignType campaign = (AccessCertificationCampaignType) object;
        LOGGER.info("Automatically closing current stage of {}", ObjectTypeUtil.toShortString(campaign));
        if (campaign.getState() != IN_REVIEW_STAGE) {
            LOGGER.warn("Campaign {} is not in a review stage; this 'close stage' trigger will be ignored.", ObjectTypeUtil.toShortString(campaign));
            return;
        }
        int currentStageNumber = campaign.getStageNumber();
        certificationManager.closeCurrentStage(campaign.getOid(), currentStageNumber, task, result);
        if (currentStageNumber < CertCampaignTypeUtil.getNumberOfStages(campaign)) {
            LOGGER.info("Automatically opening next stage of {}", ObjectTypeUtil.toShortString(campaign));
            certificationManager.openNextStage(campaign.getOid(), currentStageNumber + 1, task, result);
        } else {
            LOGGER.info("Automatically starting remediation for {}", ObjectTypeUtil.toShortString(campaign));
            certificationManager.startRemediation(campaign.getOid(), task, result);
        }
    } catch (SchemaException | ObjectNotFoundException | ObjectAlreadyExistsException | SecurityViolationException | RuntimeException e) {
        LoggingUtils.logException(LOGGER, "Couldn't close current campaign and possibly advance to the next one", e);
    }
}
Also used : ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) SchemaException(com.evolveum.midpoint.util.exception.SchemaException) SecurityViolationException(com.evolveum.midpoint.util.exception.SecurityViolationException) ObjectNotFoundException(com.evolveum.midpoint.util.exception.ObjectNotFoundException) ObjectAlreadyExistsException(com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException) AccessCertificationCampaignType(com.evolveum.midpoint.xml.ns._public.common.common_3.AccessCertificationCampaignType)

Aggregations

SchemaException (com.evolveum.midpoint.util.exception.SchemaException)576 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)235 ObjectNotFoundException (com.evolveum.midpoint.util.exception.ObjectNotFoundException)214 QName (javax.xml.namespace.QName)132 SystemException (com.evolveum.midpoint.util.exception.SystemException)113 ExpressionEvaluationException (com.evolveum.midpoint.util.exception.ExpressionEvaluationException)100 SecurityViolationException (com.evolveum.midpoint.util.exception.SecurityViolationException)100 CommunicationException (com.evolveum.midpoint.util.exception.CommunicationException)92 ConfigurationException (com.evolveum.midpoint.util.exception.ConfigurationException)89 Task (com.evolveum.midpoint.task.api.Task)87 PrismObject (com.evolveum.midpoint.prism.PrismObject)86 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)69 ObjectAlreadyExistsException (com.evolveum.midpoint.util.exception.ObjectAlreadyExistsException)68 ArrayList (java.util.ArrayList)67 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)59 ObjectDelta (com.evolveum.midpoint.prism.delta.ObjectDelta)49 PolyString (com.evolveum.midpoint.prism.polystring.PolyString)47 ObjectQuery (com.evolveum.midpoint.prism.query.ObjectQuery)46 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)34 Test (org.testng.annotations.Test)34