Search in sources :

Example 1 with ProvisioningType

use of com.tremolosecurity.config.xml.ProvisioningType in project OpenUnison by TremoloSecurity.

the class ForRemoval method loadUnisonConfiguration.

@Override
public JAXBElement<TremoloType> loadUnisonConfiguration(Unmarshaller unmarshaller) throws Exception {
    InputStream in;
    if (configXML.startsWith("WEB-INF")) {
        in = new ByteArrayInputStream(OpenUnisonConfigLoader.generateOpenUnisonConfig(ctx.getRealPath("/" + configXML)).getBytes("UTF-8"));
    } else {
        in = new ByteArrayInputStream(OpenUnisonConfigLoader.generateOpenUnisonConfig(configXML).getBytes("UTF-8"));
    }
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder loader = factory.newDocumentBuilder();
    Document document = loader.parse(in);
    DocumentTraversal traversal = (DocumentTraversal) document;
    TreeWalker walker = traversal.createTreeWalker(document.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
    traverseLevel(walker, "");
    StringWriter writer = new StringWriter();
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer;
    transformer = tf.newTransformer();
    transformer.transform(new DOMSource(document), new StreamResult(writer));
    String xmlString = writer.getBuffer().toString();
    ByteArrayInputStream bais = new ByteArrayInputStream(xmlString.getBytes("UTF-8"));
    Object obj = unmarshaller.unmarshal(bais);
    JAXBElement<TremoloType> cfg = (JAXBElement<TremoloType>) obj;
    this.unisonConfig = cfg.getValue();
    QueueConfigType qct = (QueueConfigType) GlobalEntries.getGlobalEntries().get("openunison.queueconfig");
    if (qct != null) {
        logger.info("Overriding Queue Configuration");
        if (cfg.getValue().getProvisioning() == null) {
            cfg.getValue().setProvisioning(new ProvisioningType());
        }
        cfg.getValue().getProvisioning().setQueueConfig(qct);
    }
    return cfg;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TremoloType(com.tremolosecurity.config.xml.TremoloType) QueueConfigType(com.tremolosecurity.config.xml.QueueConfigType) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TreeWalker(org.w3c.dom.traversal.TreeWalker) JAXBElement(javax.xml.bind.JAXBElement) Document(org.w3c.dom.Document) ProvisioningType(com.tremolosecurity.config.xml.ProvisioningType) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) DocumentBuilder(javax.xml.parsers.DocumentBuilder) DocumentTraversal(org.w3c.dom.traversal.DocumentTraversal)

Aggregations

ProvisioningType (com.tremolosecurity.config.xml.ProvisioningType)1 QueueConfigType (com.tremolosecurity.config.xml.QueueConfigType)1 TremoloType (com.tremolosecurity.config.xml.TremoloType)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 JAXBElement (javax.xml.bind.JAXBElement)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 Transformer (javax.xml.transform.Transformer)1 TransformerFactory (javax.xml.transform.TransformerFactory)1 DOMSource (javax.xml.transform.dom.DOMSource)1 StreamResult (javax.xml.transform.stream.StreamResult)1 Document (org.w3c.dom.Document)1 DocumentTraversal (org.w3c.dom.traversal.DocumentTraversal)1 TreeWalker (org.w3c.dom.traversal.TreeWalker)1