Search in sources :

Example 11 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project cloudstack by apache.

the class SAML2LoginAPIAuthenticatorCmd method processSAMLResponse.

public Response processSAMLResponse(String responseMessage) {
    Response responseObject = null;
    try {
        DefaultBootstrap.bootstrap();
        responseObject = SAMLUtils.decodeSAMLResponse(responseMessage);
    } catch (ConfigurationException | FactoryConfigurationError | ParserConfigurationException | SAXException | IOException | UnmarshallingException e) {
        s_logger.error("SAMLResponse processing error: " + e.getMessage());
    }
    return responseObject;
}
Also used : LoginCmdResponse(org.apache.cloudstack.api.response.LoginCmdResponse) Response(org.opensaml.saml2.core.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ConfigurationException(org.opensaml.xml.ConfigurationException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) UnmarshallingException(org.opensaml.xml.io.UnmarshallingException) SAXException(org.xml.sax.SAXException)

Example 12 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project cloudstack by apache.

the class SAML2AuthManagerImpl method setup.

private boolean setup() {
    if (!initSP()) {
        s_logger.error("SAML Plugin failed to initialize, please fix the configuration and restart management server");
        return false;
    }
    _timer = new Timer();
    final HttpClient client = new HttpClient();
    final String idpMetaDataUrl = getSAMLIdentityProviderMetadataURL();
    if (SAMLTimeout.value() != null && SAMLTimeout.value() > SAMLPluginConstants.SAML_REFRESH_INTERVAL) {
        _refreshInterval = SAMLTimeout.value();
    }
    try {
        DefaultBootstrap.bootstrap();
        if (idpMetaDataUrl.startsWith("http")) {
            _idpMetaDataProvider = new HTTPMetadataProvider(_timer, client, idpMetaDataUrl);
        } else {
            File metadataFile = PropertiesUtil.findConfigFile(idpMetaDataUrl);
            if (metadataFile == null) {
                s_logger.error("Provided Metadata is not a URL, Unable to locate metadata file from local path: " + idpMetaDataUrl);
                return false;
            } else {
                s_logger.debug("Provided Metadata is not a URL, trying to read metadata file from local path: " + metadataFile.getAbsolutePath());
                _idpMetaDataProvider = new FilesystemMetadataProvider(_timer, metadataFile);
            }
        }
        _idpMetaDataProvider.setRequireValidMetadata(true);
        _idpMetaDataProvider.setParserPool(new BasicParserPool());
        _idpMetaDataProvider.initialize();
        _timer.scheduleAtFixedRate(new MetadataRefreshTask(), 0, _refreshInterval * 1000);
    } catch (MetadataProviderException e) {
        s_logger.error("Unable to read SAML2 IDP MetaData URL, error:" + e.getMessage());
        s_logger.error("SAML2 Authentication may be unavailable");
        return false;
    } catch (ConfigurationException | FactoryConfigurationError e) {
        s_logger.error("OpenSAML bootstrapping failed: error: " + e.getMessage());
        return false;
    } catch (NullPointerException e) {
        s_logger.error("Unable to setup SAML Auth Plugin due to NullPointerException" + " please check the SAML global settings: " + e.getMessage());
        return false;
    }
    return true;
}
Also used : Timer(java.util.Timer) ConfigurationException(org.opensaml.xml.ConfigurationException) HttpClient(org.apache.commons.httpclient.HttpClient) BasicParserPool(org.opensaml.xml.parse.BasicParserPool) FilesystemMetadataProvider(org.opensaml.saml2.metadata.provider.FilesystemMetadataProvider) HTTPMetadataProvider(org.opensaml.saml2.metadata.provider.HTTPMetadataProvider) File(java.io.File) MetadataProviderException(org.opensaml.saml2.metadata.provider.MetadataProviderException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 13 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project openolat by klemens.

the class CopyAndConvertVisitor method convertXmlFile.

/**
 * Convert the XML files, assessmentItem or assessmentTest
 *
 * @param inputFile
 * @param outputFile
 */
public boolean convertXmlFile(Path inputFile, Path outputFile) {
    try {
        boolean validated = true;
        QTI21Infos fileInfos = scanFile(inputFile);
        // inherit from test if needed
        if (fileInfos.getEditor() == null && infos.getEditor() != null) {
            fileInfos.setEditor(infos.getEditor());
            fileInfos.setVersion(infos.getVersion());
        }
        if (onyx38Family(fileInfos)) {
            validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {

                @Override
                public DefaultHandler2 create(XMLStreamWriter xtw) {
                    return new Onyx38ToQtiWorksHandler(xtw);
                }
            });
        } else if (onyxWebFamily(fileInfos)) {
            validated = convertXmlFile(inputFile, outputFile, fileInfos.getType(), new HandlerProvider() {

                @Override
                public DefaultHandler2 create(XMLStreamWriter xtw) {
                    return new OnyxToQtiWorksHandler(xtw, infos);
                }
            });
            if (validated && fileInfos.getType() == InputType.assessmentItem) {
                // check templateVariables
                checkAssessmentItem(outputFile);
            }
        } else {
            Files.copy(inputFile, outputFile, StandardCopyOption.REPLACE_EXISTING);
        }
        return validated;
    } catch (IOException | FactoryConfigurationError e) {
        log.error("", e);
        return false;
    }
}
Also used : Onyx38ToQtiWorksHandler(org.olat.ims.qti21.model.xml.Onyx38ToQtiWorksHandler) DefaultHandler2(org.xml.sax.ext.DefaultHandler2) QTI21Infos(org.olat.ims.qti21.model.xml.QTI21Infos) OnyxToQtiWorksHandler(org.olat.ims.qti21.model.xml.OnyxToQtiWorksHandler) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) IOException(java.io.IOException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError)

Example 14 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project OpenOLAT by OpenOLAT.

the class QTI12To21Converter method blockedHtml.

/**
 * Make sure the HTML content is in block elements. Simple text
 * are returned as is.
 *
 * @param text
 * @return
 */
protected final String blockedHtml(String text) {
    if (StringHelper.containsNonWhitespace(text)) {
        collectMaterial(text);
        if (StringHelper.isHtml(text)) {
            String trimmedText = text.trim();
            trimmedText = trimmedText.replace("<hr />", "<hr></hr>");
            try {
                Writer out = new StringWriter();
                XMLOutputFactory xof = XMLOutputFactory.newInstance();
                XMLStreamWriter xtw = xof.createXMLStreamWriter(out);
                SAXParser parser = new SAXParser();
                QTI12To21HtmlHandler handler = new QTI12To21HtmlHandler(xtw);
                parser.setContentHandler(handler);
                parser.parse(new InputSource(new StringReader(trimmedText)));
                String blockedHtml = out.toString();
                text = blockedHtml.replace("<start>", "").replace("</start>", "");
                materialMappings.putAll(handler.getMaterialsMapping());
            } catch (FactoryConfigurationError | XMLStreamException | SAXException | IOException e) {
                log.error("", e);
            }
        } else {
            text = StringEscapeUtils.unescapeHtml(text);
        }
    }
    return text;
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) InputSource(org.xml.sax.InputSource) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringReader(java.io.StringReader) SAXParser(org.cyberneko.html.parsers.SAXParser) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 15 with FactoryConfigurationError

use of javax.xml.stream.FactoryConfigurationError in project libSBOLj by SynBioDex.

the class SBOLReader method readRDF.

/**
 * @param reader
 * @return
 * @throws SBOLValidationException if either of the following SBOL validation rules was violated: 10105, 10201.
 */
private static DocumentRoot<QName> readRDF(Reader reader) throws SBOLValidationException {
    try {
        XMLStreamReader xmlReader = XMLInputFactory.newInstance().createXMLStreamReader(reader);
        RdfIo rdfIo = new RdfIo();
        return rdfIo.createIoReader(xmlReader).read();
    } catch (FactoryConfigurationError e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (XMLStreamException e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (CoreIoException e) {
        throw new SBOLValidationException("sbol-10105", e);
    } catch (ClassCastException e) {
        if (e.getMessage().contains("IdentifiableDocument")) {
            throw new SBOLValidationException("sbol-10201", e);
        }
        throw new SBOLValidationException("sbol-10105", e);
    } catch (IllegalArgumentException e) {
        if (e.getCause() instanceof URISyntaxException) {
            throw new SBOLValidationException("sbol-10201", e);
        }
        throw new SBOLValidationException("sbol-10105", e);
    }
}
Also used : XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) RdfIo(org.sbolstandard.core.io.rdf.RdfIo) URISyntaxException(java.net.URISyntaxException) FactoryConfigurationError(javax.xml.stream.FactoryConfigurationError) CoreIoException(org.sbolstandard.core.io.CoreIoException)

Aggregations

FactoryConfigurationError (javax.xml.stream.FactoryConfigurationError)25 IOException (java.io.IOException)14 XMLStreamException (javax.xml.stream.XMLStreamException)11 StringWriter (java.io.StringWriter)6 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)5 ConfigurationException (org.opensaml.xml.ConfigurationException)5 SAXException (org.xml.sax.SAXException)5 StringReader (java.io.StringReader)3 Writer (java.io.Writer)3 XMLInputFactory (javax.xml.stream.XMLInputFactory)3 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)3 XMLEvent (javax.xml.stream.events.XMLEvent)3 MarshallingException (org.opensaml.xml.io.MarshallingException)3 InputStream (java.io.InputStream)2 InvalidKeyException (java.security.InvalidKeyException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SignatureException (java.security.SignatureException)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 XMLEventReader (javax.xml.stream.XMLEventReader)2