List of usage examples for org.w3c.dom Element getLocalName
public String getLocalName();
From source file:org.apache.syncope.core.logic.SAML2IdPLogic.java
private List<SAML2IdPTO> importIdPs(final InputStream input) throws Exception { List<EntityDescriptor> idpEntityDescriptors = new ArrayList<>(); Element root = OpenSAMLUtil.getParserPool().parse(new InputStreamReader(input)).getDocumentElement(); if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) { idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom(root)); } else if (SAMLConstants.SAML20MD_NS.equals(root.getNamespaceURI()) && EntitiesDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(root.getLocalName())) { NodeList children = root.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (SAMLConstants.SAML20MD_NS.equals(child.getNamespaceURI()) && EntityDescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(child.getLocalName())) { NodeList descendants = child.getChildNodes(); for (int j = 0; j < descendants.getLength(); j++) { Node descendant = descendants.item(j); if (SAMLConstants.SAML20MD_NS.equals(descendant.getNamespaceURI()) && IDPSSODescriptor.DEFAULT_ELEMENT_LOCAL_NAME.equals(descendant.getLocalName())) { idpEntityDescriptors.add((EntityDescriptor) OpenSAMLUtil.fromDom((Element) child)); }//ww w. ja v a2 s .co m } } } } List<SAML2IdPTO> result = new ArrayList<>(idpEntityDescriptors.size()); for (EntityDescriptor idpEntityDescriptor : idpEntityDescriptors) { SAML2IdPTO idpTO = new SAML2IdPTO(); idpTO.setEntityID(idpEntityDescriptor.getEntityID()); idpTO.setName(idpEntityDescriptor.getEntityID()); idpTO.setUseDeflateEncoding(false); try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) { saml2rw.write(new OutputStreamWriter(baos), idpEntityDescriptor, false); idpTO.setMetadata(Base64.getEncoder().encodeToString(baos.toByteArray())); } ItemTO connObjectKeyItem = new ItemTO(); connObjectKeyItem.setIntAttrName("username"); connObjectKeyItem.setExtAttrName("NameID"); idpTO.setConnObjectKeyItem(connObjectKeyItem); SAML2IdPEntity idp = cache.put(idpEntityDescriptor, idpTO); if (idp.getSSOLocation(SAML2BindingType.POST) != null) { idpTO.setBindingType(SAML2BindingType.POST); } else if (idp.getSSOLocation(SAML2BindingType.REDIRECT) != null) { idpTO.setBindingType(SAML2BindingType.REDIRECT); } else { throw new IllegalArgumentException( "Neither POST nor REDIRECT artifacts supported by " + idp.getId()); } result.add(idpTO); } return result; }
From source file:org.apache.webdav.lib.properties.AclProperty.java
/** * Parse a privilege element./* ww w .java2s .c o m*/ */ protected Privilege parsePrivilege(Element privilegeElement) { return new Privilege(privilegeElement.getNamespaceURI(), privilegeElement.getLocalName(), null); }
From source file:org.apache.woden.internal.DOMWSDLReader.java
protected DescriptionElement getWSDLFromLocation(String locationURI, DescriptionElement desc, Map wsdlModules) throws WSDLException { DescriptionElement referencedDesc = null; Element docEl; URL locationURL = null;//from w w w .ja va2 s. c o m URI contextURI = null; try { /* * For simple resolvers, we resolve the parent (Description) URI * to be used as the context. This allows for relative locationURIs * to be resolved implicitly - they are considered to be located * relative to the resolved parent. Therefore, relative URIs such as these * need not be listed in the catalog file. */ /* TODO * OASIS-style catalogs have a convenience notation to define root URIs * thus grouping related URLs together. In this case the context URI here * should be left alone, but the resultant locationURL resolved instead. * * Implement a boolean system property like org.apache.woden.resolver.useRelativeURLs * (set by the resolver ctor). SimpleURIResolver (et al) should set this to true, * OASISCatalogResolver should set to false. */ // contextURI = desc.getDocumentBaseURI(); contextURI = resolveURI(desc.getDocumentBaseURI()); URL contextURL = (contextURI != null) ? contextURI.toURL() : null; locationURL = StringUtils.getURL(contextURL, locationURI); } catch (MalformedURLException e) { String baseURI = contextURI != null ? contextURI.toString() : null; getErrorReporter().reportError(new ErrorLocatorImpl(), //TODO line&col nos. "WSDL502", new Object[] { baseURI, locationURI }, ErrorReporter.SEVERITY_ERROR); //can't continue import with a bad URL. return null; } String locationStr = locationURL.toString(); //Check if WSDL imported or included previously from this location. referencedDesc = (DescriptionElement) wsdlModules.get(locationStr); if (referencedDesc == null) { //not previously imported or included, so retrieve the WSDL. try { Document doc = getDocument(new InputSource(locationStr), locationStr); docEl = doc.getDocumentElement(); } catch (IOException e) { //document retrieval failed (e.g. 'not found') getErrorReporter().reportError(new ErrorLocatorImpl(), //TODO line&col nos. "WSDL503", new Object[] { locationStr }, ErrorReporter.SEVERITY_WARNING, e); //cannot continue without the referenced document return null; } //The referenced document should contain a WSDL <description> QName docElQN = new QName(docEl.getNamespaceURI(), docEl.getLocalName()); if (!Constants.Q_ELEM_DESCRIPTION.equals(docElQN)) { getErrorReporter().reportError(new ErrorLocatorImpl(), //TODO line&col nos. "WSDL501", new Object[] { Constants.Q_ELEM_DESCRIPTION, docElQN }, ErrorReporter.SEVERITY_ERROR); //cannot continue without a <description> element return null; } XMLElement descEl = createXMLElement(docEl); referencedDesc = parseDescription(locationStr, descEl, wsdlModules); if (!wsdlModules.containsKey(locationStr)) { wsdlModules.put(locationStr, referencedDesc); } } return referencedDesc; }
From source file:org.apache.ws.scout.registry.RegistryImpl.java
/** * /* ww w .j a v a 2s.c o m*/ */ public JAXBElement<?> execute(JAXBElement<?> uddiRequest, URI endPointURI) throws RegistryException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document doc; try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); this.marshaller.marshal(uddiRequest, baos); doc = docBuilder.parse(new ByteArrayInputStream(baos.toByteArray())); } catch (SAXException saxe) { throw (new RegistryException(saxe)); } catch (ParserConfigurationException pce) { throw (new RegistryException(pce)); } catch (IOException ioe) { throw (new RegistryException(ioe)); } catch (JAXBException ioe) { throw (new RegistryException(ioe)); } Element request = doc.getDocumentElement(); request.setAttribute("xmlns", this.getUddiNamespace()); if (!"3.0".equals(this.getUddiVersion())) { request.setAttribute("generic", this.getUddiVersion()); } //request.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace()); // A SOAP request is made and a SOAP response // is returned. Element response; try { response = transport.send(request, endPointURI); } catch (TransportException te) { throw new RegistryException(te); } /* if (response.hasAttributes()) { NamedNodeMap am = response.getAttributes(); ArrayList<String> al = new ArrayList<String>(); for (int i = 0; i < am.getLength(); i++) { Node n = am.item(i); String attribute = n.getNodeName(); if (attribute!= null && attribute.startsWith("xmlns")) { al.add(attribute); } } for (String attr : al) { response.removeAttribute(attr); } }*/ if (response.getNamespaceURI() == null) { response.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", this.getUddiNamespace()); } // If we are getting responses from a UDDI v3, remove the xmlns // First, let's make sure that a response // (any response) is found in the SOAP Body. String responseName = response.getLocalName(); if (responseName == null) { throw new RegistryException("Unsupported response " + "from registry. A value was not present."); } if (responseName.toLowerCase().equals("fault")) { NodeList nodeList = null; // Child Elements String fCode = null; nodeList = response.getElementsByTagName("faultcode"); if (nodeList.getLength() > 0) fCode = nodeList.item(0).getNodeValue(); String fString = null; nodeList = response.getElementsByTagName("faultstring"); if (nodeList.getLength() > 0) fString = nodeList.item(0).getNodeValue(); String fActor = null; nodeList = response.getElementsByTagName("faultactor"); if (nodeList.getLength() > 0) fActor = nodeList.item(0).getNodeValue(); DispositionReport dispRpt = null; nodeList = response.getElementsByTagName("detail"); if (nodeList.getLength() > 0) { nodeList = ((Element) nodeList.item(0)).getElementsByTagName("dispositionReport"); if (nodeList.getLength() > 0) { JAXBElement<DispositionReport> dispRptObj = null; try { dispRptObj = (JAXBElement<DispositionReport>) unmarshaller .unmarshal((Element) nodeList.item(0)); } catch (JAXBException xmle) { throw (new RegistryException(xmle)); } dispRpt = dispRptObj.getValue(); } } RegistryException e = new RegistryException(fCode, fString, fActor, dispRpt); // Create RegistryException instance and return throw e; } // Let's now try to determine which UDDI response // we received and unmarshal it appropriately or // throw a RegistryException if it's unknown. // Well, we have now determined that something was // returned and it is "a something" that we know // about so let's unmarshal it into a RegistryObject // Next, let's make sure we didn't recieve a SOAP // Fault. If it is a SOAP Fault then throw it // immediately. JAXBElement<?> uddiResponse = null; try { String xml = XMLUtils.convertNodeToXMLString(response); log.debug("Response is: " + xml); StringReader reader = new StringReader(xml); uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader)); //It is probably faster not to go to a String, but JAXB has issues with this //uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(response); } catch (JAXBException xmle) { throw (new RegistryException(xmle)); } return uddiResponse; }
From source file:org.apache.ws.scout.registry.RegistryV3Impl.java
/** * //from ww w . j a v a 2s . c o m */ public JAXBElement<?> execute(JAXBElement<?> uddiRequest, URI endPointURI) throws RegistryV3Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); Document doc; try { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance(); docBuilderFactory.setNamespaceAware(true); DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder(); this.marshaller.marshal(uddiRequest, baos); doc = docBuilder.parse(new ByteArrayInputStream(baos.toByteArray())); } catch (SAXException saxe) { throw (new RegistryV3Exception(saxe)); } catch (ParserConfigurationException pce) { throw (new RegistryV3Exception(pce)); } catch (IOException ioe) { throw (new RegistryV3Exception(ioe)); } catch (JAXBException ioe) { throw (new RegistryV3Exception(ioe)); } Element request = doc.getDocumentElement(); request.setAttribute("xmlns", this.getUddiNamespace()); if (!"3.0".equals(this.getUddiVersion())) { request.setAttribute("generic", this.getUddiVersion()); } //request.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns", this.getUddiNamespace()); // A SOAP request is made and a SOAP response // is returned. if (log.isDebugEnabled()) { String xmlIn = XMLUtils.convertNodeToXMLString(request); log.debug("Request send to UDDI Registry: " + xmlIn); } Element response; try { response = transport.send(request, endPointURI); } catch (TransportException te) { throw new RegistryV3Exception(te); } /* if (response.hasAttributes()) { NamedNodeMap am = response.getAttributes(); ArrayList<String> al = new ArrayList<String>(); for (int i = 0; i < am.getLength(); i++) { Node n = am.item(i); String attribute = n.getNodeName(); if (attribute!= null && attribute.startsWith("xmlns")) { al.add(attribute); } } for (String attr : al) { response.removeAttribute(attr); } }*/ JAXBElement<?> uddiResponse = null; if (response != null) { if (response.getNamespaceURI() == null) { response.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", this.getUddiNamespace()); } // If we are getting responses from a UDDI v3, remove the xmlns // First, let's make sure that a response // (any response) is found in the SOAP Body. String responseName = response.getLocalName(); if (responseName == null) { throw new RegistryV3Exception("Unsupported response " + "from registry. A value was not present."); } // Let's now try to determine which UDDI response // we received and unmarshal it appropriately or // throw a RegistryV3Exception if it's unknown. // Well, we have now determined that something was // returned and it is "a something" that we know // about so let's unmarshal it into a RegistryObject // Next, let's make sure we didn't recieve a SOAP // Fault. If it is a SOAP Fault then throw it // immediately. try { String xml = XMLUtils.convertNodeToXMLString(response); log.debug("Response is: " + xml); StringReader reader = new StringReader(xml); uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(new StreamSource(reader)); //It is probably faster not to go to a String, but JAXB has issues with this //uddiResponse = (JAXBElement<?>) unmarshaller.unmarshal(response); } catch (JAXBException xmle) { throw (new RegistryV3Exception(xmle)); } if (responseName.toLowerCase().equals("fault")) { NodeList nodeList = null; // Child Elements String fCode = null; nodeList = response.getElementsByTagName("faultcode"); if (nodeList.getLength() > 0) fCode = nodeList.item(0).getNodeValue(); String fString = null; nodeList = response.getElementsByTagName("faultstring"); if (nodeList.getLength() > 0) fString = nodeList.item(0).getNodeValue(); String fActor = null; nodeList = response.getElementsByTagName("faultactor"); if (nodeList.getLength() > 0) fActor = nodeList.item(0).getNodeValue(); DispositionReport dispRpt = null; nodeList = response.getElementsByTagName("detail"); if (nodeList.getLength() > 0) { nodeList = ((Element) nodeList.item(0)).getElementsByTagName("dispositionReport"); if (nodeList.getLength() > 0) { JAXBElement<DispositionReport> dispRptObj = null; try { dispRptObj = (JAXBElement<DispositionReport>) unmarshaller .unmarshal((Element) nodeList.item(0)); } catch (JAXBException xmle) { throw (new RegistryV3Exception(xmle)); } dispRpt = dispRptObj.getValue(); } } RegistryV3Exception e = new RegistryV3Exception(fCode, fString, fActor, dispRpt); // Create RegistryV3Exception instance and return throw e; } } return uddiResponse; }
From source file:org.apache.ws.security.message.EncryptionPartsTest.java
/** * Test getting a DOM Element from WSEncryptionPart directly *///w w w. j a v a 2 s .c o m @org.junit.Test public void testEncryptionPartDOMElement() throws Exception { Document doc = SOAPUtil.toSOAPPart(SOAPMSG); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement()); WSSecEncrypt encrypt = new WSSecEncrypt(); encrypt.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security"); encrypt.setKeyIdentifierType(WSConstants.ISSUER_SERIAL); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>(); // Give wrong names to make sure it's picking up the element WSEncryptionPart encP = new WSEncryptionPart("Incorrect Localname", "Incorrect N/S", ""); Element bodyElement = WSSecurityUtil.findBodyElement(doc); assertTrue(bodyElement != null && "Body".equals(bodyElement.getLocalName())); encP.setElement(bodyElement); parts.add(encP); encrypt.setParts(parts); Document encryptedDoc = encrypt.build(doc, crypto, secHeader); String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(encryptedDoc); if (LOG.isDebugEnabled()) { LOG.debug(outputString); } assertTrue(!outputString.contains("testMethod")); List<WSSecurityEngineResult> results = verify(encryptedDoc); QName bodyName = new QName(soapConstants.getEnvelopeURI(), "Body"); WSSecurityUtil.checkAllElementsProtected(results, WSConstants.ENCR, new QName[] { bodyName }); }
From source file:org.apache.ws.security.message.SignaturePartsTest.java
/** * Test getting a DOM Element from WSEncryptionPart directly *///from w ww. j a va 2s . c o m @org.junit.Test public void testSignaturePartDOMElement() throws Exception { WSSecSignature sign = new WSSecSignature(); sign.setUserInfo("16c73ab6-b892-458f-abf5-2f875f74882e", "security"); sign.setKeyIdentifierType(WSConstants.ISSUER_SERIAL); Document doc = SOAPUtil.toSOAPPart(SOAPMSG); SOAPConstants soapConstants = WSSecurityUtil.getSOAPConstants(doc.getDocumentElement()); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); List<WSEncryptionPart> parts = new ArrayList<WSEncryptionPart>(); // Give wrong names to make sure it's picking up the element WSEncryptionPart encP = new WSEncryptionPart("Incorrect Localname", "Incorrect N/S", ""); Element bodyElement = WSSecurityUtil.findBodyElement(doc); assertTrue(bodyElement != null && "Body".equals(bodyElement.getLocalName())); encP.setElement(bodyElement); parts.add(encP); sign.setParts(parts); Document signedDoc = sign.build(doc, crypto, secHeader); if (LOG.isDebugEnabled()) { String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc); LOG.debug(outputString); } List<WSSecurityEngineResult> results = verify(signedDoc); QName bodyName = new QName(soapConstants.getEnvelopeURI(), "Body"); WSSecurityUtil.checkAllElementsProtected(results, WSConstants.SIGN, new QName[] { bodyName }); }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
private static Node copyHeadersAndUpdateRefList(Node cur, Node dest, String newId) { Node temp = cur.cloneNode(true); dest.appendChild(temp);//from w w w . j av a 2s . co m if (newId != null && temp.getNodeType() == Node.ELEMENT_NODE) { Element t = (Element) temp; if (t.getLocalName().equals("ReferenceList")) { Element ref = getFirstChildElement(t, new QName("http://www.w3.org/2001/04/xmlenc#", "DataReference"), true); Element newRef = (Element) ref.cloneNode(true); newRef.setAttributeNS(null, "URI", "#" + newId); t.appendChild(newRef); } } return cur.getNextSibling(); }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
private static void search(List<Element> list, Element baseElement, QName nodeName, boolean recursive) { if (nodeName == null) { list.add(baseElement);/*from w w w. j a v a 2s . c o m*/ } else { QName qname; if (nodeName.getNamespaceURI().length() > 0) { qname = new QName(baseElement.getNamespaceURI(), baseElement.getLocalName()); } else { qname = new QName(baseElement.getLocalName()); } if (qname.equals(nodeName)) { list.add(baseElement); } } if (recursive) { NodeList nlist = baseElement.getChildNodes(); int len = nlist.getLength(); for (int i = 0; i < len; i++) { Node child = nlist.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { search(list, (Element) child, nodeName, recursive); } } } }
From source file:org.apache.ws.security.message.token.SecurityTokenReference.java
private XMLX509IssuerSerial getIssuerSerial() throws WSSecurityException { if (issuerSerial != null) { return issuerSerial; }//w w w.j a va 2 s . c om Element elem = getFirstElement(); if (elem == null) { return null; } try { if (Constants._TAG_X509DATA.equals(elem.getLocalName())) { elem = (Element) WSSecurityUtil.findElement(elem, Constants._TAG_X509ISSUERSERIAL, Constants.SignatureSpecNS); } issuerSerial = new XMLX509IssuerSerial(elem, ""); } catch (XMLSecurityException e) { throw new WSSecurityException(WSSecurityException.SECURITY_TOKEN_UNAVAILABLE, "noToken", new Object[] { "Issuer/Serial data element missing" }, e); } return issuerSerial; }