List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:org.apache.openaz.xacml.std.dom.DOMResult.java
/** * Creates a new <code>DOMResult</code> by parsing the given <code>Node</code> representing a XACML Result * element.//from w ww .j a v a 2 s . c om * * @param nodeResult the <code>Node</code> representing the XACML Result element * @return a new <code>DOMResult</code> parsed from the given <code>Node</code> * @throws DOMStructureException if the conversion cannot be made */ public static Result newInstance(Node nodeResult) throws DOMStructureException { Element elementResult = DOMUtil.getElement(nodeResult); boolean bLenient = DOMProperties.isLenient(); StdMutableResult mutableResult = new StdMutableResult(); NodeList children = elementResult.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_DECISION.equals(childName)) { Decision decision = Decision.get(child.getTextContent()); if (decision == null) { if (!bLenient) { throw new DOMStructureException(child, "Unknown Decision \"" + child.getTextContent() + "\" in \"" + DOMUtil.getNodeLabel(child) + "\""); } } else { mutableResult.setDecision(decision); } } else if (XACML3.ELEMENT_STATUS.equals(childName)) { mutableResult.setStatus(DOMStatus.newInstance(child)); } else if (XACML3.ELEMENT_OBLIGATIONS.equals(childName)) { mutableResult.addObligations(DOMObligation.newList(child)); } else if (XACML3.ELEMENT_ASSOCIATEDADVICE.equals(childName)) { mutableResult.addAdvice(DOMAdvice.newList(child)); } else if (XACML3.ELEMENT_ATTRIBUTES.equals(childName)) { mutableResult.addAttributeCategory(DOMAttributeCategory.newInstance(child)); } else if (XACML3.ELEMENT_POLICYIDENTIFIERLIST.equals(childName)) { NodeList grandchildren = child.getChildNodes(); int numGrandchildren; if (grandchildren != null && (numGrandchildren = grandchildren.getLength()) > 0) { for (int j = 0; j < numGrandchildren; j++) { Node grandchild = grandchildren.item(j); if (DOMUtil.isElement(grandchild)) { String grandchildName = grandchild.getLocalName(); if (DOMUtil.isInNamespace(grandchild, XACML3.XMLNS)) { if (XACML3.ELEMENT_POLICYIDREFERENCE.equals(grandchildName)) { mutableResult.addPolicyIdentifier( DOMIdReference.newInstance(grandchild)); } else if (XACML3.ELEMENT_POLICYSETIDREFERENCE.equals(grandchildName)) { mutableResult.addPolicySetIdentifier( DOMIdReference.newInstance(grandchild)); } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(grandchild, child); } } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(grandchild, child); } } } } } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeResult); } } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeResult); } } } } } if (mutableResult.getDecision() == null && !bLenient) { throw DOMUtil.newMissingElementException(nodeResult, XACML3.XMLNS, XACML3.ELEMENT_DECISION); } return new StdResult(mutableResult); }
From source file:org.apache.openaz.xacml.std.dom.DOMResult.java
public static boolean repair(Node nodeResult) throws DOMStructureException { Element elementResult = DOMUtil.getElement(nodeResult); boolean result = false; NodeList children = elementResult.getChildNodes(); int numChildren; boolean sawDecision = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_DECISION.equals(childName)) { Decision decision = Decision.get(child.getTextContent()); if (decision == null) { throw new DOMStructureException(child, "Unknown Decision \"" + child.getTextContent() + "\" in \"" + DOMUtil.getNodeLabel(child) + "\""); }/*from w w w. j ava 2s. co m*/ sawDecision = true; } else if (XACML3.ELEMENT_STATUS.equals(childName)) { result = DOMStatus.repair(child) || result; } else if (XACML3.ELEMENT_OBLIGATIONS.equals(childName)) { result = DOMObligation.repairList(child) || result; } else if (XACML3.ELEMENT_ASSOCIATEDADVICE.equals(childName)) { result = DOMAdvice.repairList(child) || result; } else if (XACML3.ELEMENT_ATTRIBUTES.equals(childName)) { result = DOMAttributeCategory.repair(child) || result; } else if (XACML3.ELEMENT_POLICYIDENTIFIERLIST.equals(childName)) { NodeList grandchildren = child.getChildNodes(); int numGrandchildren; if (grandchildren != null && (numGrandchildren = grandchildren.getLength()) > 0) { for (int j = 0; j < numGrandchildren; j++) { Node grandchild = grandchildren.item(j); if (DOMUtil.isElement(grandchild)) { String grandchildName = grandchild.getLocalName(); if (DOMUtil.isInNamespace(grandchild, XACML3.XMLNS)) { if (XACML3.ELEMENT_POLICYIDREFERENCE.equals(grandchildName)) { result = DOMIdReference.repair(grandchild) || result; } else if (XACML3.ELEMENT_POLICYSETIDREFERENCE.equals(grandchildName)) { result = DOMIdReference.repair(grandchild) || result; } else { logger.warn("Unexpected element " + grandchild.getNodeName()); child.removeChild(grandchild); result = true; } } else { logger.warn("Unexpected element " + grandchild.getNodeName()); child.removeChild(grandchild); result = true; } } } } } else { logger.warn("Unexpected element " + child.getNodeName()); elementResult.removeChild(child); result = true; } } else { logger.warn("Unexpected element " + child.getNodeName()); elementResult.removeChild(child); result = true; } } } } if (!sawDecision) { throw DOMUtil.newMissingElementException(nodeResult, XACML3.XMLNS, XACML3.ELEMENT_DECISION); } return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMStatus.java
/** * Creates a new <code>DOMStatus</code> by parsing the given <code>Node</code> representing a XACML Status * element.//from ww w . j a va2s . c o m * * @param nodeStatus the <code>Node</code> representing the Status element * @return a new <code>DOMStatus</code> parsed from the given <code>Node</code> * @throws DOMStructureException if the conversion cannot be made */ public static Status newInstance(Node nodeStatus) throws DOMStructureException { Element elementStatus = DOMUtil.getElement(nodeStatus); boolean bLenient = DOMProperties.isLenient(); StdMutableStatus mutableStatus = new StdMutableStatus(); NodeList children = elementStatus.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_STATUSCODE.equals(childName)) { mutableStatus.setStatusCode(DOMStatusCode.newInstance(child)); } else if (XACML3.ELEMENT_STATUSMESSAGE.equals(childName)) { mutableStatus.setStatusMessage(child.getTextContent()); } else if (XACML3.ELEMENT_STATUSDETAIL.equals(childName)) { mutableStatus.setStatusDetail(DOMStatusDetail.newInstance(child)); } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatus); } } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatus); } } } } } if (mutableStatus.getStatusCode() == null && !bLenient) { throw DOMUtil.newMissingElementException(nodeStatus, XACML3.XMLNS, XACML3.ELEMENT_STATUSCODE); } return new StdStatus(mutableStatus); }
From source file:org.apache.openaz.xacml.std.dom.DOMStatus.java
public static boolean repair(Node nodeStatus) throws DOMStructureException { Element elementStatus = DOMUtil.getElement(nodeStatus); boolean result = false; NodeList children = elementStatus.getChildNodes(); int numChildren; boolean sawStatusCode = false; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { String childName = child.getLocalName(); if (XACML3.ELEMENT_STATUSCODE.equals(childName)) { result = DOMStatusCode.repair(child) || result; sawStatusCode = true; //} else if (XACML3.ELEMENT_STATUSMESSAGE.equals(childName)) { } else if (XACML3.ELEMENT_STATUSDETAIL.equals(childName)) { result = DOMStatusDetail.repair(child) || result; } else { logger.warn("Unexpected element " + child.getNodeName()); elementStatus.removeChild(child); result = true;//from w ww.j a v a2 s. co m } } else { logger.warn("Unexpected element " + child.getNodeName()); elementStatus.removeChild(child); result = true; } } } } if (!sawStatusCode) { throw DOMUtil.newMissingElementException(nodeStatus, XACML3.XMLNS, XACML3.ELEMENT_STATUSCODE); } return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMStatusCode.java
/** * Creates a new <code>DOMStatusCode</code> by parsing the given <code>Node</code> representing a XACML * StatusCode element.//from w w w. j a va2 s. com * * @param nodeStatusCode the <code>Node</code> representing a StatusCode element * @return a new <code>DOMStatusCode</code> parsed from the given <code>Node</code> * @throws DOMStructureException if the conversion cannot be made */ public static StatusCode newInstance(Node nodeStatusCode) throws DOMStructureException { Element elementStatusCode = DOMUtil.getElement(nodeStatusCode); boolean bLenient = DOMProperties.isLenient(); Identifier identifierStatusCode = DOMUtil.getIdentifierAttribute(elementStatusCode, XACML3.ATTRIBUTE_VALUE, !bLenient); StatusCode statusCodeChild = null; NodeList children = elementStatusCode.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS)) { if (child.getLocalName().equals(XACML3.ELEMENT_STATUSCODE)) { if (statusCodeChild != null) { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatusCode); } } else { statusCodeChild = DOMStatusCode.newInstance(child); } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatusCode); } } } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatusCode); } } } } } return new StdStatusCode(identifierStatusCode, statusCodeChild); }
From source file:org.apache.openaz.xacml.std.dom.DOMStatusDetail.java
/** * Creates a new <code>DOMStatusDetail</code> by parsing the given <code>Node</code> representing a XACML * StatusDetail element./*from w w w .j a v a2s .c o m*/ * * @param nodeStatusDetail the <code>Node</code> representing the StatusDetail element * @return a new <code>DOMStatusDetail</code> parsed from the given <code>Node</code> * @throws DOMStructureException if the conversion cannot be made */ public static StatusDetail newInstance(Node nodeStatusDetail) throws DOMStructureException { Element elementStatusDetail = DOMUtil.getElement(nodeStatusDetail); boolean bLenient = DOMProperties.isLenient(); StdMutableStatusDetail mutableStatusDetail = new StdMutableStatusDetail(); NodeList children = elementStatusDetail.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_MISSINGATTRIBUTEDETAIL.equals(child.getLocalName())) { mutableStatusDetail.addMissingAttributeDetail(DOMMissingAttributeDetail.newInstance(child)); } else { if (!bLenient) { throw DOMUtil.newUnexpectedElementException(child, nodeStatusDetail); } } } } } return new StdStatusDetail(mutableStatusDetail); }
From source file:org.apache.openaz.xacml.std.dom.DOMStatusDetail.java
public static boolean repair(Node nodeStatusDetail) throws DOMStructureException { Element elementStatusDetail = DOMUtil.getElement(nodeStatusDetail); boolean result = false; NodeList children = elementStatusDetail.getChildNodes(); int numChildren; if (children != null && (numChildren = children.getLength()) > 0) { for (int i = 0; i < numChildren; i++) { Node child = children.item(i); if (DOMUtil.isElement(child)) { if (DOMUtil.isInNamespace(child, XACML3.XMLNS) && XACML3.ELEMENT_MISSINGATTRIBUTEDETAIL.equals(child.getLocalName())) { result = DOMMissingAttributeDetail.repair(child) || result; } else { logger.warn("Unexpected element " + child.getNodeName()); elementStatusDetail.removeChild(child); result = true;/*from w ww .j a v a2 s . c o m*/ } } } } return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMUtil.java
public static String getNodeLabel(Node node) { String namespaceURI = node.getNamespaceURI(); return (namespaceURI == null ? node.getLocalName() : namespaceURI + ":" + node.getLocalName()); }
From source file:org.apache.rahas.impl.util.SAML2Utils.java
public static SAML2KeyInfo getSAML2KeyInfo(Assertion assertion, Crypto crypto, CallbackHandler cb) throws WSSecurityException { //First ask the cb whether it can provide the secret WSPasswordCallback pwcb = new WSPasswordCallback(assertion.getID(), WSPasswordCallback.CUSTOM_TOKEN); if (cb != null) { try {/*from ww w .j a v a 2 s . c om*/ cb.handle(new Callback[] { pwcb }); } catch (Exception e1) { throw new WSSecurityException(WSSecurityException.FAILURE, "noKey", new Object[] { assertion.getID() }, e1); } } byte[] key = pwcb.getKey(); if (key != null) { return new SAML2KeyInfo(assertion, key); } else { // if the cb fails to provide the secret. try { // extract the subject Subject samlSubject = assertion.getSubject(); if (samlSubject == null) { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token", new Object[] { "for Signature (no Subject)" }); } // extract the subject confirmation element from the subject SubjectConfirmation subjectConf = (SubjectConfirmation) samlSubject.getSubjectConfirmations() .get(0); if (subjectConf == null) { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token", new Object[] { "for Signature (no Subject Confirmation)" }); } // Get the subject confirmation data, KeyInfoConfirmationDataType extends SubjectConfirmationData. SubjectConfirmationData scData = subjectConf.getSubjectConfirmationData(); if (scData == null) { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token", new Object[] { "for Signature (no Subject Confirmation Data)" }); } // Get the SAML specific XML representation of the keyInfo object XMLObject KIElem = null; List<XMLObject> scDataElements = scData.getOrderedChildren(); Iterator<XMLObject> iterator = scDataElements.iterator(); while (iterator.hasNext()) { XMLObject xmlObj = iterator.next(); if (xmlObj instanceof org.opensaml.xml.signature.KeyInfo) { KIElem = xmlObj; break; } } Element keyInfoElement; // Generate a DOM element from the XMLObject. if (KIElem != null) { // Set the "javax.xml.parsers.DocumentBuilderFactory" system property to make sure the endorsed JAXP // implementation is picked over the default jaxp impl shipped with the JDK. String jaxpProperty = System.getProperty("javax.xml.parsers.DocumentBuilderFactory"); System.setProperty("javax.xml.parsers.DocumentBuilderFactory", "org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); MarshallerFactory marshallerFactory = org.opensaml.xml.Configuration.getMarshallerFactory(); Marshaller marshaller = marshallerFactory.getMarshaller(KIElem); keyInfoElement = marshaller.marshall(KIElem); // Reset the sys. property to its previous value. if (jaxpProperty == null) { System.getProperties().remove("javax.xml.parsers.DocumentBuilderFactory"); } else { System.setProperty("javax.xml.parsers.DocumentBuilderFactory", jaxpProperty); } } else { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAML2Token", new Object[] { "for Signature (no key info element)" }); } AttributeStatement attrStmt = assertion.getAttributeStatements().size() != 0 ? (AttributeStatement) assertion.getAttributeStatements().get(0) : null; AuthnStatement authnStmt = assertion.getAuthnStatements().size() != 0 ? (AuthnStatement) assertion.getAuthnStatements().get(0) : null; // if an attr stmt is present, then it has a symmetric key. if (attrStmt != null) { NodeList children = keyInfoElement.getChildNodes(); int len = children.getLength(); for (int i = 0; i < len; i++) { Node child = children.item(i); if (child.getNodeType() != Node.ELEMENT_NODE) { continue; } QName el = new QName(child.getNamespaceURI(), child.getLocalName()); if (el.equals(WSSecurityEngine.ENCRYPTED_KEY)) { EncryptedKeyProcessor proc = new EncryptedKeyProcessor(); proc.handleEncryptedKey((Element) child, cb, crypto, null); return new SAML2KeyInfo(assertion, proc.getDecryptedBytes()); } else if (el.equals(new QName(WSConstants.WST_NS, "BinarySecret"))) { Text txt = (Text) child.getFirstChild(); return new SAML2KeyInfo(assertion, Base64.decode(txt.getData())); } else if (el.equals(new QName(WSConstants.SIG_NS, "X509Data"))) { X509Certificate[] certs = null; try { KeyInfo ki = new KeyInfo(keyInfoElement, null); if (ki.containsX509Data()) { X509Data data = ki.itemX509Data(0); XMLX509Certificate certElem = null; if (data != null && data.containsCertificate()) { certElem = data.itemCertificate(0); } if (certElem != null) { X509Certificate cert = certElem.getX509Certificate(); certs = new X509Certificate[1]; certs[0] = cert; return new SAML2KeyInfo(assertion, certs); } } } catch (XMLSecurityException e3) { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity", new Object[] { "cannot get certificate (key holder)" }, e3); } } } } // If an authn stmt is present then it has a public key. if (authnStmt != null) { X509Certificate[] certs = null; try { KeyInfo ki = new KeyInfo(keyInfoElement, null); if (ki.containsX509Data()) { X509Data data = ki.itemX509Data(0); XMLX509Certificate certElem = null; if (data != null && data.containsCertificate()) { certElem = data.itemCertificate(0); } if (certElem != null) { X509Certificate cert = certElem.getX509Certificate(); certs = new X509Certificate[1]; certs[0] = cert; return new SAML2KeyInfo(assertion, certs); } } } catch (XMLSecurityException e3) { throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity", new Object[] { "cannot get certificate (key holder)" }, e3); } } throw new WSSecurityException(WSSecurityException.FAILURE, "invalidSAMLsecurity", new Object[] { "cannot get certificate or key " }); } catch (MarshallingException e) { throw new WSSecurityException(WSSecurityException.FAILURE, "Failed marshalling the SAML Assertion", null, e); } } }
From source file:org.apache.sling.its.servlets.ItsImportServlet.java
/** * If element has child elements, don't process them and skip those nodes. * * @param element/*from www . ja va 2 s . c om*/ * current element * @param itsEng * the ITSEngine */ private void skipChildren(final Element element, final ITraversal itsEng) { if (element.hasChildNodes()) { Node node; while ((node = itsEng.nextNode()) != null) { if (node.getNodeType() == Node.ELEMENT_NODE) { if (itsEng.backTracking() && StringUtils.equals(node.getLocalName(), element.getLocalName())) { break; } } } } }