List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:org.chiba.xml.xforms.xpath.test.InstanceFactoryTest.java
private void assertElement(Node node, String localName, String namespaceURI, int children) { assertNotNull(node);/*from w ww . ja v a2 s. c om*/ assertEquals(Node.ELEMENT_NODE, node.getNodeType()); assertEquals(localName, node.getLocalName()); assertEquals(namespaceURI, node.getNamespaceURI()); assertEquals(children, node.getChildNodes().getLength()); }
From source file:org.codice.ddf.security.filter.login.LoginFilter.java
private void validateHolderOfKeyConfirmation(SamlAssertionWrapper assertion, X509Certificate[] x509Certs) throws SecurityServiceException { List<String> confirmationMethods = assertion.getConfirmationMethods(); boolean hasHokMethod = false; for (String method : confirmationMethods) { if (OpenSAMLUtil.isMethodHolderOfKey(method)) { hasHokMethod = true;/*from w ww.j a va 2 s. c om*/ } } if (hasHokMethod) { if (x509Certs != null && x509Certs.length > 0) { List<SubjectConfirmation> subjectConfirmations = assertion.getSaml2().getSubject() .getSubjectConfirmations(); for (SubjectConfirmation subjectConfirmation : subjectConfirmations) { if (OpenSAMLUtil.isMethodHolderOfKey(subjectConfirmation.getMethod())) { Element dom = subjectConfirmation.getSubjectConfirmationData().getDOM(); Node keyInfo = dom.getFirstChild(); Node x509Data = keyInfo.getFirstChild(); Node dataNode = x509Data.getFirstChild(); Node dataText = dataNode.getFirstChild(); X509Certificate tlsCertificate = x509Certs[0]; if (dataNode.getLocalName().equals("X509Certificate")) { String textContent = dataText.getTextContent(); byte[] byteValue = Base64.getMimeDecoder().decode(textContent); try { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf .generateCertificate(new ByteArrayInputStream(byteValue)); //check that the certificate is still valid cert.checkValidity(); //HoK spec section 2.5: //relying party MUST ensure that the certificate bound to the assertion matches the X.509 certificate in its possession. //Matching is done by comparing the base64-decoded certificates, or the hash values of the base64-decoded certificates, byte-for-byte. //if the certs aren't the same, verify if (!tlsCertificate.equals(cert)) { //verify that the cert was signed by the same private key as the TLS cert cert.verify(tlsCertificate.getPublicKey()); } } catch (CertificateException | NoSuchAlgorithmException | InvalidKeyException | SignatureException | NoSuchProviderException e) { throw new SecurityServiceException( "Unable to validate Holder of Key assertion with certificate."); } } else if (dataNode.getLocalName().equals("X509SubjectName")) { String textContent = dataText.getTextContent(); //HoK spec section 2.5: //relying party MUST ensure that the subject distinguished name (DN) bound to the assertion matches the DN bound to the X.509 certificate. //If, however, the relying party does not trust the certificate issuer to issue such a DN, the attesting entity is not confirmed and the relying party SHOULD disregard the assertion. if (!tlsCertificate.getSubjectDN().getName().equals(textContent)) { throw new SecurityServiceException( "Unable to validate Holder of Key assertion with subject DN."); } } else if (dataNode.getLocalName().equals("X509IssuerSerial")) { //we have no way to support this confirmation type so we have to throw an error throw new SecurityServiceException( "Unable to validate Holder of Key assertion with issuer serial. NOT SUPPORTED"); } else if (dataNode.getLocalName().equals("X509SKI")) { String textContent = dataText.getTextContent(); byte[] tlsSKI = tlsCertificate.getExtensionValue("2.5.29.14"); byte[] assertionSKI = Base64.getMimeDecoder().decode(textContent); if (tlsSKI != null && tlsSKI.length > 0) { ASN1OctetString tlsOs = ASN1OctetString.getInstance(tlsSKI); ASN1OctetString assertionOs = ASN1OctetString.getInstance(assertionSKI); SubjectKeyIdentifier tlsSubjectKeyIdentifier = SubjectKeyIdentifier .getInstance(tlsOs.getOctets()); SubjectKeyIdentifier assertSubjectKeyIdentifier = SubjectKeyIdentifier .getInstance(assertionOs.getOctets()); //HoK spec section 2.5: //relying party MUST ensure that the value bound to the assertion matches the Subject Key Identifier (SKI) extension bound to the X.509 certificate. //Matching is done by comparing the base64-decoded SKI values byte-for-byte. If the X.509 certificate does not contain an SKI extension, //the attesting entity is not confirmed and the relying party SHOULD disregard the assertion. if (!Arrays.equals(tlsSubjectKeyIdentifier.getKeyIdentifier(), assertSubjectKeyIdentifier.getKeyIdentifier())) { throw new SecurityServiceException( "Unable to validate Holder of Key assertion with subject key identifier."); } } else { throw new SecurityServiceException( "Unable to validate Holder of Key assertion with subject key identifier."); } } } } } else { throw new SecurityServiceException("Holder of Key assertion, must be used with 2-way TLS."); } } }
From source file:org.corpus_tools.pepper.cli.PepperStarter.java
/** * This method writes a module configuration of GroupId, ArtifactId and * Maven repository back to the modules.xml file */// w w w. j a v a2 s. c o m private boolean write2ConfigFile(String groupId, String artifactId, String repository) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); try { boolean changes = false; File configFile = new File(MODULES_XML_PATH); DocumentBuilder docBuilder = dbFactory.newDocumentBuilder(); Document doc = docBuilder.parse(configFile); NodeList configuredModules = doc.getElementsByTagName(ModuleTableReader.TAG_ARTIFACTID); if (configuredModules.getLength() == 0) { return false; } /* check, if the module is already in the modules.xml file */ Node item = configuredModules.item(0); int j = 0; while (j + 1 < configuredModules.getLength() && !artifactId.equals(item.getTextContent())) { item = configuredModules.item(++j); } if (artifactId.equals(item.getTextContent())) {// already contained // -> edit Node itemGroupId = null; Node itemRepo = null; Node node = null; for (int i = 0; i < item.getParentNode().getChildNodes().getLength() && (itemGroupId == null || itemRepo == null); i++) { node = item.getParentNode().getChildNodes().item(i); if (ModuleTableReader.TAG_GROUPID.equals(node.getLocalName())) { itemGroupId = node; } if (ModuleTableReader.TAG_REPO.equals(node.getLocalName())) { itemRepo = node; } } if (itemGroupId != null) { itemGroupId.setTextContent(groupId); changes = true; } else { if (!groupId.equals(doc.getElementsByTagName(ModuleTableReader.ATT_DEFAULTGROUPID).item(0) .getTextContent())) { itemGroupId = doc.createElement(ModuleTableReader.TAG_GROUPID); itemGroupId.setTextContent(groupId); item.getParentNode().appendChild(itemGroupId); changes = true; } } if (itemRepo != null) { itemRepo.setTextContent(repository); changes = true; } else { // if // (!repository.equals(doc.getElementsByTagName(ModuleTableReader.ATT_DEFAULTREPO).item(0).getTextContent())) // { // itemRepo = doc.createElement(ModuleTableReader.TAG_REPO); // itemRepo.setTextContent(repository); // item.getParentNode().appendChild(itemRepo); // changes = true; // } } itemGroupId = null; itemRepo = null; node = null; } else {// not contained yet -> insert changes = true; Node listNode = doc.getElementsByTagName(ModuleTableReader.TAG_LIST).item(0); Node newModule = doc.createElement(ModuleTableReader.TAG_ITEM); Node groupIdNode = doc.createElement(ModuleTableReader.TAG_GROUPID); groupIdNode.appendChild(doc.createTextNode(groupId)); Node artifactIdNode = doc.createElement(ModuleTableReader.TAG_ARTIFACTID); artifactIdNode.appendChild(doc.createTextNode(artifactId)); Node repositoryNode = doc.createElement(ModuleTableReader.TAG_REPO); repositoryNode.appendChild(doc.createTextNode(repository)); newModule.appendChild(groupIdNode); newModule.appendChild(artifactIdNode); newModule.appendChild(repositoryNode); listNode.appendChild(newModule); listNode = null; newModule = null; groupIdNode = null; artifactIdNode = null; repository = null; } if (changes) { // write back to file TransformerFactory trFactory = TransformerFactory.newInstance(); // trFactory.setAttribute("indent-number", 2); Transformer transformer = trFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); DOMSource src = new DOMSource(doc); StreamResult result = new StreamResult(configFile); transformer.transform(src, result); trFactory = null; transformer = null; src = null; result = null; } docBuilder = null; doc = null; configuredModules = null; item = null; } catch (ParserConfigurationException | SAXException | IOException | FactoryConfigurationError | TransformerFactoryConfigurationError | TransformerException e) { logger.error("Could not read module table."); logger.trace(" ", e); return false; } return true; }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * @param cruxPageBodyElement//from ww w. ja va2s .c o m * @param cruxArrayMetaData * @throws ViewParserException */ private void generateCruxMetaData(Node cruxPageBodyElement, StringBuilder cruxArrayMetaData) throws ViewParserException { NodeList childNodes = cruxPageBodyElement.getChildNodes(); if (childNodes != null) { boolean needsComma = false; for (int i = 0; i < childNodes.getLength(); i++) { Node child = childNodes.item(i); String namespaceURI = child.getNamespaceURI(); String nodeName = child.getLocalName(); if (namespaceURI != null && namespaceURI.equals(CRUX_CORE_NAMESPACE) && !nodeName.equals(CRUX_CORE_SPLASH_SCREEN)) { if (needsComma) { cruxArrayMetaData.append(","); } if (nodeName.equals(CRUX_CORE_SCREEN)) { generateCruxScreenMetaData((Element) child, cruxArrayMetaData); } needsComma = true; } else if (namespaceURI != null && namespaceURI.startsWith(WIDGETS_NAMESPACE_PREFIX)) { if (needsComma) { cruxArrayMetaData.append(","); } String widgetType = getCurrentWidgetTag(); updateCurrentWidgetTag((Element) child); generateCruxInnerMetaData((Element) child, cruxArrayMetaData); setCurrentWidgetTag(widgetType); needsComma = true; } else { StringBuilder childrenMetaData = new StringBuilder(); generateCruxMetaData(child, childrenMetaData); if (childrenMetaData.length() > 0) { if (needsComma) { cruxArrayMetaData.append(","); } cruxArrayMetaData.append(childrenMetaData); needsComma = true; } } } } }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * @param cruxPageMetaData/*from w w w.j av a 2 s. co m*/ * @param cruxArrayMetaData */ private void generateCruxMetaDataAttributes(Element cruxPageMetaData, StringBuilder cruxArrayMetaData) { NamedNodeMap attributes = cruxPageMetaData.getAttributes(); if (attributes != null) { for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); String attrName = attribute.getLocalName(); if (attrName == null) { attrName = attribute.getNodeName(); } String attrValue = attribute.getNodeValue(); String namespaceURI = attribute.getNamespaceURI(); if (!StringUtils.isEmpty(attrValue) && (namespaceURI == null || !namespaceURI.endsWith("/xmlns/"))) { cruxArrayMetaData.append(","); cruxArrayMetaData.append("\"" + attrName + "\":"); cruxArrayMetaData.append("\"" + HTMLUtils.escapeJavascriptString(attrValue, escapeXML) + "\""); } } } }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * Check if the target node is child from a rootDocument element or from a native XHTML element. * /* w w w . jav a 2 s .c o m*/ * @param node * @return */ private boolean isHTMLChild(Node node) { Node parentNode = node.getParentNode(); String namespaceURI = parentNode.getNamespaceURI(); if (namespaceURI == null) { log.warn("The view [" + this.viewId + "] contains elements that is not bound to any namespace. It can cause errors while translating to an HTML page."); } if (node.getOwnerDocument().getDocumentElement().equals(parentNode)) { return true; } if (namespaceURI != null && namespaceURI.equals(XHTML_NAMESPACE) || isHtmlContainerWidget(parentNode)) { return true; } if (parentNode instanceof Element && namespaceURI != null && namespaceURI.equals(CRUX_CORE_NAMESPACE) && parentNode.getLocalName().equals(CRUX_CORE_SCREEN)) { return isHTMLChild(parentNode); } return false; }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * @param node//ww w . j ava2 s . c o m * @return */ private boolean isHtmlContainerWidget(Node node) { if (node instanceof Element) { return isHtmlContainerWidget(node.getLocalName(), getLibraryName(node)); } return false; }
From source file:org.cruxframework.crux.core.declarativeui.ViewParser.java
/** * @param node//from w w w. jav a2s.co m * @return */ private boolean isAttachableWidget(Node node) { if (node instanceof Element) { return isAttachableWidget(node.getLocalName(), getLibraryName(node)); } return false; }
From source file:org.culturegraph.mf.morph.MorphVisualizer.java
@Override protected void enterCollect(final Node node) { incrementChildCount();//w w w. j a va 2s .c o m pushChildCount(); final String identifier = getNewId(); lastProcessorStack.push(identifier); idStack.push(identifier); final Map<String, String> attributes = resolvedAttributeMap(node); attributes.remove(ATTRITBUTE.NAME.getString()); writer.println(buildRecord(identifier, node.getLocalName(), "lightgray", attributes)); }
From source file:org.culturegraph.mf.morph.MorphVisualizer.java
@Override protected void handleFunction(final Node functionNode) { final String identifier = getNewId(); final Map<String, String> attributes = resolvedAttributeMap(functionNode); //for lookups TODO: find generic solution and get rid of the ifs. attributes.remove("default"); String inAttr = attributes.remove("in"); if (inAttr == null) { inAttr = attributes.remove("map"); }/* w w w. ja v a 2 s . c om*/ if (inAttr != null) { addIncludeEdge(inAttr, identifier); } writer.println(buildRecord(identifier, functionNode.getLocalName(), "white", attributes)); if (functionNode.hasChildNodes()) { final Map<String, String> map = getMap(functionNode); final String mapId = identifier + "M"; addIncludeEdge(mapId, identifier); writer.println(buildMap(mapId, null, map)); } addEdge(lastProcessorStack.pop(), identifier); lastProcessorStack.push(identifier); }