List of usage examples for org.w3c.dom Element removeChild
public Node removeChild(Node oldChild) throws DOMException;
oldChild
from the list of children, and returns it. From source file:org.apache.openaz.xacml.std.dom.DOMRequestDefaults.java
public static boolean repair(Node nodeRequestDefaults) throws DOMStructureException { Element elementRequestDefaults = DOMUtil.getElement(nodeRequestDefaults); boolean result = false; NodeList children = elementRequestDefaults.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_XPATHVERSION.equals(child.getLocalName())) { try { DOMUtil.getURIContent(child); } catch (DOMStructureException ex) { logger.warn("Deleting invalid XPathVersion " + child.getTextContent()); elementRequestDefaults.removeChild(child); result = true;//from www.jav a 2 s . c o m } } else { logger.warn("Unexpected element " + child.getNodeName()); elementRequestDefaults.removeChild(child); result = true; } } } } return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMRequestReference.java
public static boolean repair(Node nodeRequestReference) throws DOMStructureException { Element elementRequestReference = DOMUtil.getElement(nodeRequestReference); boolean result = false; NodeList children = elementRequestReference.getChildNodes(); int numChildren; boolean sawAttributesReference = 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) && XACML3.ELEMENT_ATTRIBUTESREFERENCE.equals(child.getLocalName())) { result = DOMRequestAttributesReference.repair(child) || result; sawAttributesReference = true; } else { logger.warn("Unexpected element " + child.getNodeName()); elementRequestReference.removeChild(child); result = true;/*from w ww. j a va 2 s .c om*/ } } } } if (!sawAttributesReference) { throw DOMUtil.newMissingAttributeException(nodeRequestReference, XACML3.XMLNS, XACML3.ELEMENT_ATTRIBUTESREFERENCE); } return result; }
From source file:org.apache.openaz.xacml.std.dom.DOMResponse.java
/** * Change XACML2 into XACML3//from w w w . ja v a 2 s . c o m * * @param nodeResponse * @return * @throws DOMStructureException */ public static boolean repair(Node nodeResponse) throws DOMStructureException { Element elementResponse = DOMUtil.getElement(nodeResponse); boolean result = false; NodeList children = elementResponse.getChildNodes(); int numChildren; boolean sawResult = 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) && XACML3.ELEMENT_RESULT.equals(child.getLocalName())) { result = DOMResult.repair(child) || result; sawResult = true; } else { logger.warn("Unexpected element " + child.getNodeName()); elementResponse.removeChild(child); result = true; } } } } if (!sawResult) { throw DOMUtil.newMissingElementException(nodeResponse, XACML3.XMLNS, XACML3.ELEMENT_RESULT); } return result; }
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 a va2s. c o 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
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 www . ja v a 2 s.c o 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
public static boolean repair(Node nodeStatusCode) throws DOMStructureException { Element elementStatusCode = DOMUtil.getElement(nodeStatusCode); boolean result = false; result = DOMUtil.repairIdentifierAttribute(elementStatusCode, XACML3.ATTRIBUTE_VALUE, logger) || result; 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)) { result = DOMStatusCode.repair(child) || result; } else { logger.warn("Unexpected element " + child.getNodeName()); elementStatusCode.removeChild(child); result = true;//from w w w .ja v a 2s. com } } } } return result; }
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;//w ww. j a va2s . co m } } } } return result; }
From source file:org.apache.wiki.auth.user.XMLUserDatabase.java
/** * Saves a {@link UserProfile}to the user database, overwriting the * existing profile if it exists. The user name under which the profile * should be saved is returned by the supplied profile's * {@link UserProfile#getLoginName()}method. * @param profile the user profile to save * @throws WikiSecurityException if the profile cannot be saved *//*from ww w .j a v a2 s. c om*/ public synchronized void save(UserProfile profile) throws WikiSecurityException { if (c_dom == null) { log.fatal("Could not save profile " + profile + " database does not exist"); throw new IllegalStateException("FATAL: database does not exist"); } checkForRefresh(); DateFormat c_format = new SimpleDateFormat(DATE_FORMAT); String index = profile.getLoginName(); NodeList users = c_dom.getElementsByTagName(USER_TAG); Element user = null; for (int i = 0; i < users.getLength(); i++) { Element currentUser = (Element) users.item(i); if (currentUser.getAttribute(LOGIN_NAME).equals(index)) { user = currentUser; break; } } boolean isNew = false; Date modDate = new Date(System.currentTimeMillis()); if (user == null) { // Create new user node profile.setCreated(modDate); log.info("Creating new user " + index); user = c_dom.createElement(USER_TAG); c_dom.getDocumentElement().appendChild(user); setAttribute(user, CREATED, c_format.format(profile.getCreated())); isNew = true; } else { // To update existing user node, delete old attributes first... NodeList attributes = user.getElementsByTagName(ATTRIBUTES_TAG); for (int i = 0; i < attributes.getLength(); i++) { user.removeChild(attributes.item(i)); } } setAttribute(user, UID, profile.getUid()); setAttribute(user, LAST_MODIFIED, c_format.format(modDate)); setAttribute(user, LOGIN_NAME, profile.getLoginName()); setAttribute(user, FULL_NAME, profile.getFullname()); setAttribute(user, WIKI_NAME, profile.getWikiName()); setAttribute(user, EMAIL, profile.getEmail()); Date lockExpiry = profile.getLockExpiry(); setAttribute(user, LOCK_EXPIRY, lockExpiry == null ? "" : c_format.format(lockExpiry)); // Hash and save the new password if it's different from old one String newPassword = profile.getPassword(); if (newPassword != null && !newPassword.equals("")) { String oldPassword = user.getAttribute(PASSWORD); if (!oldPassword.equals(newPassword)) { setAttribute(user, PASSWORD, getHash(newPassword)); } } // Save the attributes as as Base64 string if (profile.getAttributes().size() > 0) { try { String encodedAttributes = Serializer.serializeToBase64(profile.getAttributes()); Element attributes = c_dom.createElement(ATTRIBUTES_TAG); user.appendChild(attributes); Text value = c_dom.createTextNode(encodedAttributes); attributes.appendChild(value); } catch (IOException e) { throw new WikiSecurityException("Could not save user profile attribute. Reason: " + e.getMessage(), e); } } // Set the profile timestamps if (isNew) { profile.setCreated(modDate); } profile.setLastModified(modDate); // Commit to disk saveDOM(); }
From source file:org.apache.ws.security.message.ModifiedRequestTest.java
/** * Test a duplicated signed SAML Assertion. *//*from w ww. ja va2 s .com*/ @org.junit.Test public void testDuplicatedSignedSAMLAssertion() throws Exception { SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler(); callbackHandler.setStatement(SAML1CallbackHandler.Statement.AUTHN); callbackHandler.setConfirmationMethod(SAML1Constants.CONF_SENDER_VOUCHES); callbackHandler.setIssuer("www.example.com"); SAMLParms samlParms = new SAMLParms(); samlParms.setCallbackHandler(callbackHandler); AssertionWrapper assertion = new AssertionWrapper(samlParms); WSSecSignatureSAML wsSign = new WSSecSignatureSAML(); wsSign.setKeyIdentifierType(WSConstants.BST_DIRECT_REFERENCE); Document doc = SOAPUtil.toSOAPPart(SOAPUtil.SAMPLE_SOAP_MSG); WSSecHeader secHeader = new WSSecHeader(); secHeader.insertSecurityHeader(doc); Document signedDoc = wsSign.build(doc, null, assertion, crypto, "16c73ab6-b892-458f-abf5-2f875f74882e", "security", secHeader); Element assertionElement = (Element) assertion.getElement().cloneNode(true); assertionElement.removeChild(assertionElement.getFirstChild()); secHeader.getSecurityHeader().appendChild(assertionElement); if (LOG.isDebugEnabled()) { LOG.debug("SAML 1.1 Authn Assertion (sender vouches):"); String outputString = org.apache.ws.security.util.XMLUtils.PrettyDocumentToString(signedDoc); LOG.debug(outputString); } try { verify(signedDoc); fail("Failure expected on duplicate tokens"); } catch (WSSecurityException ex) { assertTrue(ex.getMessage().contains("Multiple security tokens with the same Id have been detected")); } }
From source file:org.apache.ws.security.message.TestMessageTransformer.java
public static Element duplicateEncryptedDataInExternalWrapperElement(Element saaj, boolean moveReferenceList) { if (moveReferenceList) { moveReferenceList(saaj);//from w w w . j a v a2s . c o m } Element body = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"), true); Element encData = getFirstChildElement(body, new QName("http://www.w3.org/2001/04/xmlenc#", "EncryptedData"), true); Element newEncData = createNewEncryptedData(encData); Element sh = getFirstChildElement(saaj, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Header"), true); Element wsseHeader = getFirstChildElement(sh, new QName("http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd", "Security"), true); Node newWsseHeader = wsseHeader.cloneNode(false); Node cur = wsseHeader.getFirstChild(); String newId = newEncData.getAttributeNS(null, "Id"); while (cur != null) { cur = copyHeadersAndUpdateRefList(cur, newWsseHeader, newId); } sh.removeChild(wsseHeader); sh.appendChild(newWsseHeader); if (!moveReferenceList) { updateEncryptedKeyRefList(newWsseHeader, newId); } Element wrapper = encData.getOwnerDocument().createElementNS(null, "a"); wrapper.setAttributeNS("http://schemas.xmlsoap.org/soap/envelope/", "mustUnderstand", "0"); wrapper.setAttributeNS("http://schemas.xmlsoap.org/soap/envelope/", "actor", "foo"); wrapper.appendChild(newEncData); sh.appendChild(wrapper); print(saaj.getOwnerDocument()); return newEncData; }