List of usage examples for org.w3c.dom Element getElementsByTagNameNS
public NodeList getElementsByTagNameNS(String namespaceURI, String localName) throws DOMException;
NodeList
of all the descendant Elements
with a given local name and namespace URI in document order. From source file:org.ojbc.util.xml.TestXmlUtils.java
@Test public void testInsertElement() throws Exception { Document d = db.newDocument(); Element e1 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e1"); d.appendChild(e1);//from w w w .ja v a 2 s .c om Element e2 = d.createElementNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e22"); e1.appendChild(e2); e2 = XmlUtils.insertElementBefore(e1, e2, OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "e21"); NodeList nodeList = e1.getElementsByTagNameNS(OjbcNamespaceContext.NS_PERSON_SEARCH_RESULTS_EXT, "*"); assertEquals(2, nodeList.getLength()); assertEquals("e21", nodeList.item(0).getLocalName()); assertEquals("e22", nodeList.item(1).getLocalName()); }
From source file:org.openehealth.ipf.commons.ihe.xua.BasicXuaProcessor.java
private static Element extractAssertionElementFromCxfMessage(SoapMessage message, Header.Direction headerDirection) { Header header = message.getHeader(new QName(WSSecurityConstants.WSSE_NS, "Security")); if (!((header != null) && headerDirection.equals(header.getDirection()) && (header.getObject() instanceof Element))) { return null; }/*from w w w. j a va 2 s. co m*/ Element headerElem = (Element) header.getObject(); NodeList nodeList = headerElem.getElementsByTagNameNS(SAMLConstants.SAML20_NS, "Assertion"); return (Element) nodeList.item(0); }
From source file:org.osaf.caldav4j.model.response.TicketDiscoveryProperty.java
/** * Handles the reponse and Stores each ticketinfo as a TicketResponse * Object, in a List of TicketResponses// w ww . jav a 2 s . co m * */ public void parseTickets() { tickets = new ArrayList<TicketResponse>(); if (element != null) { NodeList list = element.getElementsByTagNameNS(CalDAVConstants.NS_XYTHOS, CalDAVConstants.ELEM_TICKETINFO); int length = list.getLength(); for (int r = 0; r < length; r++) { Element element = (Element) list.item(r); tickets.add(XMLUtils.createTicketResponseFromDOM(element)); } } }
From source file:org.osaf.caldav4j.util.XMLUtils.java
/** * Takes a ticketinfo element and creates/returns it as a TicketResponse * Object// w w w . ja v a2s. c o m * * @param element * @return */ public static TicketResponse createTicketResponseFromDOM(Element element) { TicketResponse tr = new TicketResponse(); NodeList list = element.getElementsByTagNameNS(CalDAVConstants.NS_XYTHOS, CalDAVConstants.ELEM_ID); Element temp = (Element) list.item(0); tr.setID(temp.getTextContent()); list = element.getElementsByTagNameNS(CalDAVConstants.NS_DAV, CalDAVConstants.ELEM_HREF); temp = (Element) list.item(0); tr.setOwner(temp.getTextContent()); list = element.getElementsByTagNameNS(CalDAVConstants.NS_XYTHOS, CalDAVConstants.ELEM_TIMEOUT); temp = (Element) list.item(0); String tempTO = temp.getTextContent(); // Parses the timeout element's value into units and value in form Second-99999, otherwise no timeout (Infinite) int idx = tempTO.indexOf('-'); if (idx != -1) { // Store the Parsed Values // default timeout is Integer("") tr.setUnits(tempTO.substring(0, idx)); tr.setTimeout(new Integer(tempTO.substring(idx + 1))); } list = element.getElementsByTagNameNS(CalDAVConstants.NS_XYTHOS, CalDAVConstants.ELEM_VISITS); temp = (Element) list.item(0); String visits = temp.getTextContent(); Integer visitsInt = null; if (visits.equals(CalDAVConstants.INFINITY_STRING)) { visitsInt = CalDAVConstants.INFINITY; } else { visitsInt = new Integer(visits); } tr.setVisits(visitsInt); if (element.getElementsByTagNameNS(CalDAVConstants.NS_DAV, CalDAVConstants.ELEM_READ) != null) { tr.setRead(true); } else { tr.setRead(false); } if (element.getElementsByTagNameNS(CalDAVConstants.NS_DAV, CalDAVConstants.ELEM_WRITE) != null) { tr.setWrite(true); } else { tr.setWrite(false); } return tr; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
private boolean hasDestinationIndicationSaml2Response(Element responseElement) { if (null != responseElement.getAttributeNode("Destination")) { return true; }/*from ww w . j a v a 2 s .c o m*/ NodeList assertionNodeList = responseElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion"); if (0 == assertionNodeList.getLength()) { return false; } Element assertionElement = (Element) assertionNodeList.item(0); NodeList audienceNodeList = assertionElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Audience"); if (0 != audienceNodeList.getLength()) { return true; } NodeList subjectConfirmationDataNodeList = assertionElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "SubjectConfirmationData"); if (0 == subjectConfirmationDataNodeList.getLength()) { return false; } Element subjectConfirmationDataElement = (Element) subjectConfirmationDataNodeList.item(0); if (null != subjectConfirmationDataElement.getAttributeNode("Recipient")) { return true; } if (null != subjectConfirmationDataElement.getAttributeNode("Address")) { return true; } return false; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
private boolean hasDestinationIndicationSaml1Response(Element responseElement) { if (null != responseElement.getAttributeNode("Recipient")) { return true; }//from w w w . j a v a2 s. c o m NodeList assertionNodeList = responseElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion"); if (0 == assertionNodeList.getLength()) { return false; } Element assertionElement = (Element) assertionNodeList.item(0); NodeList audienceNodeList = assertionElement.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Audience"); if (0 != audienceNodeList.getLength()) { return true; } return false; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
private boolean isDigested(NodeList nodeList, Element signatureElement) throws XMLSignatureException, XMLSecurityException { NodeList referenceNodeList = signatureElement.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Reference"); Document document = nodeList.item(0).getOwnerDocument(); Manifest manifest = new Manifest(document); VerifyReference[] references = new VerifyReference[referenceNodeList.getLength()]; for (int referenceIdx = 0; referenceIdx < referenceNodeList.getLength(); referenceIdx++) { Element referenceElement = (Element) referenceNodeList.item(referenceIdx); VerifyReference reference = new VerifyReference(referenceElement, manifest); reference.init();//from ww w.jav a 2 s. c o m references[referenceIdx] = reference; } return isDigested(nodeList, references); }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
public List<NamedValue> getSAMLAttributes(ConversationID id) { List<NamedValue> samlAttributes = new ArrayList<NamedValue>(); Document document = getSAMLDocument(id); if (null == document) { return samlAttributes; }/*from ww w . j a v a 2 s .co m*/ NodeList attributeNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Attribute"); for (int idx = 0; idx < attributeNodeList.getLength(); idx++) { Element attributeElement = (Element) attributeNodeList.item(idx); String attributeName = attributeElement.getAttribute("AttributeName"); NodeList attributeValueNodeList = attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } NodeList attribute2NodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); for (int idx = 0; idx < attribute2NodeList.getLength(); idx++) { Element attributeElement = (Element) attribute2NodeList.item(idx); String attributeName = attributeElement.getAttribute("Name"); NodeList attributeValueNodeList = attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } return samlAttributes; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
public boolean hasValidityIntervalIndication(ConversationID id) { Document document = getSAMLDocument(id); if (null == document) { return false; }//from w w w. j a va 2 s . co m NodeList saml1AssertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Assertion"); if (0 != saml1AssertionNodeList.getLength()) { Element assertionElement = (Element) saml1AssertionNodeList.item(0); NodeList conditionsNodeList = assertionElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:1.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } NodeList saml2AssertionNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion"); if (0 != saml2AssertionNodeList.getLength()) { Element assertionElement = (Element) saml2AssertionNodeList.item(0); NodeList conditionsNodeList = assertionElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } NodeList saml2AuthnRequestNodeList = document.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:protocol", "AuthnRequest"); if (0 != saml2AuthnRequestNodeList.getLength()) { Element authnRequestElement = (Element) saml2AuthnRequestNodeList.item(0); NodeList conditionsNodeList = authnRequestElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Conditions"); if (0 != conditionsNodeList.getLength()) { Element conditionsElement = (Element) conditionsNodeList.item(0); if (null != conditionsElement.getAttributeNode("NotBefore") && null != conditionsElement.getAttributeNode("NotOnOrAfter")) { return true; } } } return false; }
From source file:org.owasp.webscarab.plugin.saml.SamlModel.java
public List getDecryptedAttributes(ConversationID id, String hexKey) throws Exception { List samlAttributes = new ArrayList(); /*/* w w w. ja v a2s . c om*/ * We create a new DOM tree as XMLCipher will change the tree. */ String encodedSamlMessage = getEncodedSAMLMessage(id); String decodedSamlMessage = getDecodedSAMLMessage(encodedSamlMessage, id); ByteArrayInputStream inputStream = new ByteArrayInputStream(decodedSamlMessage.getBytes()); Document document = this.builder.parse(inputStream); byte[] keyBytes = Hex.decode(hexKey); SecretKeySpec secretKeySpec = new SecretKeySpec(keyBytes, "AES"); XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128); xmlCipher.init(XMLCipher.DECRYPT_MODE, secretKeySpec); NodeList encryptedAttributeNodeList = document .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "EncryptedAttribute"); for (int encryptedAttributeIdx = 0; encryptedAttributeIdx < encryptedAttributeNodeList .getLength(); encryptedAttributeIdx++) { Element encryptedAttributeElement = (Element) encryptedAttributeNodeList.item(encryptedAttributeIdx); NodeList encryptedDataNodeList = encryptedAttributeElement .getElementsByTagNameNS("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"); if (1 != encryptedDataNodeList.getLength()) { continue; } Element encryptedDataElement = (Element) encryptedDataNodeList.item(0); xmlCipher.doFinal(document, encryptedDataElement); NodeList attributeNodeList = encryptedAttributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Attribute"); if (1 != attributeNodeList.getLength()) { continue; } Element attributeElement = (Element) attributeNodeList.item(0); String attributeName = attributeElement.getAttribute("Name"); NodeList attributeValueNodeList = attributeElement .getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "AttributeValue"); if (0 == attributeValueNodeList.getLength()) { continue; } Element attributeValueElement = (Element) attributeValueNodeList.item(0); String attributeValue = attributeValueElement.getChildNodes().item(0).getNodeValue(); NamedValue attribute = new NamedValue(attributeName, attributeValue); samlAttributes.add(attribute); } return samlAttributes; }