List of usage examples for org.w3c.dom Node getLocalName
public String getLocalName();
From source file:com.centeractive.ws.builder.soap.XmlUtils.java
public static NodeList getChildElementsByTagNameNS(Element elm, String namespaceUri, String localName) { List<Element> list = new ArrayList<Element>(); NodeList nl = elm.getChildNodes(); for (int c = 0; c < nl.getLength(); c++) { Node item = nl.item(c); if (item.getParentNode() == elm && item.getNodeType() == Node.ELEMENT_NODE && localName.equals(item.getLocalName()) && namespaceUri.equals(item.getNamespaceURI())) list.add((Element) item); }/*from w ww . ja v a 2s . c o m*/ return new ElementNodeList(list); }
From source file:de.openali.odysseus.chart.factory.config.ChartLayerFactory.java
private IChartLayer parse(final Node node, final ParametersType cascading, final ReferencableType... baseTypes) throws CoreException, ConfigurationException, XmlException { final String name = node.getLocalName(); switch (name) { case "Layer"://$NON-NLS-1$ {/*from ww w . j a va 2 s. c o m*/ final LayerDocument document = LayerDocument.Factory.parse(node); final LayerType layerType = document.getLayer(); final ILayerProvider layerTypeProvider = LayerTypeHelper.getLayerTypeProvider(getLoader(), layerType); return buildLayer(layerType, cascading, layerTypeProvider, baseTypes); } case "LayerReference": //$NON-NLS-1$ { final LayerReferenceDocument document = LayerReferenceDocument.Factory.parse(node); final LayerRefernceType reference = document.getLayerReference(); return buildLayerReferenceType(reference, cascading, baseTypes); } case "DerivedLayer": //$NON-NLS-1$ { final DerivedLayerDocument document = DerivedLayerDocument.Factory.parse(node); final DerivedLayerType derivedLayerType = document.getDerivedLayer(); return buildDerivedLayerTypes(derivedLayerType, cascading, baseTypes); } case "CascadingParameters": //$NON-NLS-1$ return null; } throw new UnsupportedOperationException(); }
From source file:hudson.plugins.plot.XMLSeries.java
private void addNodeToList(List<PlotPoint> ret, Node n, int buildNumber) { NamedNodeMap nodeMap = n.getAttributes(); if ((null != nodeMap) && (null != nodeMap.getNamedItem("name"))) { addValueToList(ret, nodeMap.getNamedItem("name").getTextContent().trim(), n, buildNumber); } else {/*from w ww . j av a2 s . com*/ addValueToList(ret, n.getLocalName().trim(), n, buildNumber); } }
From source file:org.guanxi.sp.engine.service.saml2.WebBrowserSSOAuthConsumerService.java
/** * Extracts the Assertions from a decrypted SAML2 Response * * @param decryptedResponse the Response which contains the Assertions * @return array of AssertionType objects or null *///from w ww .j a v a 2s .com private AssertionType[] getAssertionsFromDecryptedResponse(ResponseDocument decryptedResponse) { try { ArrayList<AssertionType> assertions = new ArrayList<AssertionType>(); EncryptedElementType[] encryptedElements = decryptedResponse.getResponse().getEncryptedAssertionArray(); for (EncryptedElementType encryptedElement : encryptedElements) { NodeList nodes = encryptedElement.getDomNode().getChildNodes(); Node assertionNode = null; for (int c = 0; c < nodes.getLength(); c++) { assertionNode = nodes.item(c); if (assertionNode.getLocalName() != null) { if (assertionNode.getLocalName().equals("Assertion")) { assertions.add(AssertionDocument.Factory.parse(assertionNode).getAssertion()); } } } if (assertionNode == null) { continue; } } return assertions.toArray(new AssertionType[assertions.size()]); } catch (XmlException xe) { return null; } }
From source file:org.guanxi.sp.engine.service.saml2.WebBrowserSSOAuthConsumerService.java
/** * Decrypts a SAML2 Web Browser SSO Response from an IdP * * @param encryptedResponse The encrypted Response * @param xmlOptions XmlOptions describing namesapces in the Response * @param privateKey the Guard's private key used to decrypt the Response * @return decrypted Response//from w w w . ja va 2s. c o m */ private ResponseDocument decryptResponse(ResponseDocument encryptedResponse, XmlOptions xmlOptions, PrivateKey privateKey) throws GuanxiException { try { // For decryption, we need to be in DOM land Document rawSAMLResponseDoc = (Document) encryptedResponse.newDomNode(xmlOptions); /* XMLBeans doesn't give us access to the embedded encryption key for some reason * so we need to break out to DOM and back again. */ NodeList nodes = encryptedResponse.getResponse().getEncryptedAssertionArray(0).getEncryptedData() .getKeyInfo().getDomNode().getChildNodes(); Node node = null; for (int c = 0; c < nodes.getLength(); c++) { node = nodes.item(c); if (node.getLocalName() != null) { if (node.getLocalName().equals("EncryptedKey")) break; } } EncryptedKeyDocument encKeyDoc = EncryptedKeyDocument.Factory.parse(node, xmlOptions); // Get a handle on the encypted data in DOM land String namespaceURI = EncryptionConstants.EncryptionSpecNS; String localName = EncryptionConstants._TAG_ENCRYPTEDDATA; // Recurse through the decryption process NodeList encyptedDataNodes = rawSAMLResponseDoc.getElementsByTagNameNS(namespaceURI, localName); while (encyptedDataNodes.getLength() > 0) { Element encryptedDataElement = (Element) encyptedDataNodes.item(0); /* This block unwraps and decrypts the secret key. The IdP first encrypts the attributes * using a secret key. It then encrypts that secret key using the public key of the Guard. * So the first step is to use the Guard's private key to decrypt the secret key. */ String algorithm = encKeyDoc.getEncryptedKey().getEncryptionMethod().getAlgorithm(); XMLCipher xmlCipher = XMLCipher.getInstance(); xmlCipher.init(XMLCipher.UNWRAP_MODE, privateKey); EncryptedData encryptedData = xmlCipher.loadEncryptedData(rawSAMLResponseDoc, encryptedDataElement); EncryptedKey encryptedKey = encryptedData.getKeyInfo().itemEncryptedKey(0); Key decryptedSecretKey = xmlCipher.decryptKey(encryptedKey, algorithm); // This block uses the decrypted secret key to decrypt the attributes Key secretKey = new SecretKeySpec(decryptedSecretKey.getEncoded(), "AES"); XMLCipher xmlDecryptCipher = XMLCipher.getInstance(); xmlDecryptCipher.init(XMLCipher.DECRYPT_MODE, secretKey); xmlDecryptCipher.doFinal(rawSAMLResponseDoc, encryptedDataElement); // Any more encryption to handle? encyptedDataNodes = rawSAMLResponseDoc.getElementsByTagNameNS(namespaceURI, localName); } // And back to XMLBeans for that nice API! return ResponseDocument.Factory.parse(rawSAMLResponseDoc); } catch (XmlException xe) { logger.error("XML problem decrypting the response", xe); throw new GuanxiException(xe); } catch (XMLEncryptionException xee) { logger.error("XML problem decrypting the response", xee); throw new GuanxiException(xee); } catch (Exception e) { logger.error("Problem decrypting the response", e); throw new GuanxiException(e); } }
From source file:org.escidoc.browser.elabsmodul.service.ELabsService.java
private RigBean resolveRig(final ItemProxy itemProxy) throws EscidocBrowserException { Preconditions.checkNotNull(itemProxy, "Resource is null"); final RigBean rigBean = new RigBean(); final String URI_DC = "http://purl.org/dc/elements/1.1/"; final String URI_EL = "http://escidoc.org/ontologies/bw-elabs/re#"; final String URI_RDF = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"; final NodeList nodeList = itemProxy.getMetadataRecords().get("escidoc").getContent().getChildNodes(); rigBean.setObjectId(itemProxy.getId()); for (int i = 0; i < nodeList.getLength(); i++) { final Node node = nodeList.item(i); final String nodeName = node.getLocalName(); final String nsUri = node.getNamespaceURI(); if ("title".equals(nodeName) && URI_DC.equals(nsUri)) { rigBean.setName((node.getFirstChild() != null) ? node.getFirstChild().getNodeValue() : null); } else if ("description".equals(nodeName) && URI_DC.equals(nsUri)) { rigBean.setDescription((node.getFirstChild() != null) ? node.getFirstChild().getNodeValue() : null); } else if ("instrument".equals(nodeName) && URI_EL.equals(nsUri)) { if (node.getAttributes() != null && node.getAttributes().getNamedItemNS(URI_RDF, "resource") != null) { final Node attributeNode = node.getAttributes().getNamedItemNS(URI_RDF, "resource"); final String instrumentID = attributeNode.getNodeValue(); try { final ItemProxy instrumentProxy = (ItemProxy) repositories.item().findById(instrumentID); rigBean.getContentList().add(resolveInstrument(instrumentProxy)); } catch (final EscidocClientException e) { LOG.error(e.getLocalizedMessage()); }//from w ww . j a va2 s . c o m } } } return rigBean; }
From source file:edu.duke.cabig.c3pr.webservice.studyimportexport.impl.StudyImportExportImpl.java
/** * Gets the first child.//from ww w . ja v a2 s . co m * * @param node the node * @param name the name * @param ns the ns * @return the first child */ private Node getFirstChild(Node node, String name, String ns) { NodeList children = node.getChildNodes(); for (int i = 0; i < children.getLength(); i++) { Node child = children.item(i); if (name.equals(child.getLocalName()) && ns.equals(child.getNamespaceURI())) { return child; } } return null; }
From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java
@SuppressWarnings("unchecked") protected SOAPElement createXteeMessageStructure(SOAPMessage requestMessage, SOAPMessage responseMessage) throws Exception { SOAPUtil.addBaseMimeHeaders(responseMessage); SOAPUtil.addBaseNamespaces(responseMessage); if (!metaService) { // Assign xroad namespaces according to request List<String> xteeNamespaces = new ArrayList<String>(); xteeNamespaces.add(version.getNamespaceUri()); if (XRoadProtocolVersion.V4_0 == version) { xteeNamespaces.add(XTeeWsdlDefinition.XROAD_IDEN_NAMESPACE); }// w w w . j a v a 2 s . co m Iterator<String> prefixes = requestMessage.getSOAPPart().getEnvelope().getNamespacePrefixes(); while (prefixes.hasNext()) { String nsPrefix = (String) prefixes.next(); String nsURI = requestMessage.getSOAPPart().getEnvelope().getNamespaceURI(nsPrefix).toLowerCase(); if (xteeNamespaces.contains(nsURI)) { SOAPUtil.addNamespace(responseMessage, nsPrefix, nsURI); } } // Copy headers from request NodeList reqHeaders = requestMessage.getSOAPHeader().getChildNodes(); for (int i = 0; i < reqHeaders.getLength(); i++) { Node reqHeader = reqHeaders.item(i); if (reqHeader.getNodeType() != Node.ELEMENT_NODE) { continue; } Node rspHeader = responseMessage.getSOAPPart().importNode(reqHeader, true); responseMessage.getSOAPHeader().appendChild(rspHeader); } } responseMessage.getSOAPPart().getEnvelope().setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding/"); Node teenusElement = SOAPUtil.getFirstNonTextChild(requestMessage.getSOAPBody()); if (teenusElement.getPrefix() == null || teenusElement.getNamespaceURI() == null) { throw new IllegalStateException("Service request is missing namespace."); } SOAPUtil.addNamespace(responseMessage, teenusElement.getPrefix(), teenusElement.getNamespaceURI()); String teenusElementName = teenusElement.getLocalName(); if (teenusElementName.endsWith(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX)) { teenusElementName = teenusElementName.substring(0, teenusElementName.lastIndexOf(SuffixBasedMessagesProvider.DEFAULT_REQUEST_SUFFIX)); } teenusElementName += SuffixBasedMessagesProvider.DEFAULT_RESPONSE_SUFFIX; return responseMessage.getSOAPBody().addChildElement(teenusElementName, teenusElement.getPrefix(), teenusElement.getNamespaceURI()); }
From source file:org.guanxi.idp.service.SSOBase.java
/** * Adds encrypted assertions to a SAML2 Response * * @param encryptionCert the X509 certificate to use for encrypting the assertions * @param assertionDoc the assertions to encrypt * @param responseDoc the SAML2 Response to add the encrypted assertions to * @throws GuanxiException if an error occurs *//* w w w .j a v a 2s . c om*/ protected void addEncryptedAssertionsToResponse(X509Certificate encryptionCert, AssertionDocument assertionDoc, ResponseDocument responseDoc) throws GuanxiException { try { PublicKey keyEncryptKey = encryptionCert.getPublicKey(); // Generate a secret key KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); keyGenerator.init(128); SecretKey secretKey = keyGenerator.generateKey(); XMLCipher keyCipher = XMLCipher.getInstance(XMLCipher.RSA_OAEP); keyCipher.init(XMLCipher.WRAP_MODE, keyEncryptKey); Document domAssertionDoc = (Document) assertionDoc.newDomNode(xmlOptions); EncryptedKey encryptedKey = keyCipher.encryptKey(domAssertionDoc, secretKey); Element elementToEncrypt = domAssertionDoc.getDocumentElement(); XMLCipher xmlCipher = XMLCipher.getInstance(XMLCipher.AES_128); xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey); // Add KeyInfo to the EncryptedData element EncryptedData encryptedDataElement = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(domAssertionDoc); keyInfo.add(encryptedKey); encryptedDataElement.setKeyInfo(keyInfo); // Encrypt the assertion xmlCipher.doFinal(domAssertionDoc, elementToEncrypt, false); // Go back into XMLBeans land... EncryptedDataDocument encryptedDataDoc = EncryptedDataDocument.Factory.parse(domAssertionDoc); // ...and add the encrypted assertion to the response responseDoc.getResponse().addNewEncryptedAssertion() .setEncryptedData(encryptedDataDoc.getEncryptedData()); // Look for the Response/EncryptedAssertion/EncryptedData/KeyInfo/EncryptedKey node... EncryptedDataType encryptedData = responseDoc.getResponse().getEncryptedAssertionArray(0) .getEncryptedData(); NodeList nodes = encryptedData.getKeyInfo().getDomNode().getChildNodes(); Node encryptedKeyNode = null; for (int c = 0; c < nodes.getLength(); c++) { encryptedKeyNode = nodes.item(c); if (encryptedKeyNode.getLocalName() != null) { if (encryptedKeyNode.getLocalName().equals("EncryptedKey")) break; } } // ...get a new KeyInfo ready... KeyInfoDocument keyInfoDoc = KeyInfoDocument.Factory.newInstance(); X509DataType x509Data = keyInfoDoc.addNewKeyInfo().addNewX509Data(); // ...and a useable version of the SP's encryption certificate... StringWriter sw = new StringWriter(); PEMWriter pemWriter = new PEMWriter(sw); pemWriter.writeObject(encryptionCert); pemWriter.close(); String x509 = sw.toString(); x509 = x509.replaceAll("-----BEGIN CERTIFICATE-----", ""); x509 = x509.replaceAll("-----END CERTIFICATE-----", ""); // ...add the encryption cert to the new KeyInfo... x509Data.addNewX509Certificate().setStringValue(x509); // ...and insert it into Response/EncryptedAssertion/EncryptedData/KeyInfo/EncryptedKey encryptedKeyNode.appendChild( encryptedKeyNode.getOwnerDocument().importNode(keyInfoDoc.getKeyInfo().getDomNode(), true)); } catch (NoSuchAlgorithmException nsae) { logger.error("AES encryption not available"); throw new GuanxiException(nsae); } catch (XMLEncryptionException xea) { logger.error("RSA_OAEP error with WRAP_MODE"); throw new GuanxiException(xea); } catch (Exception e) { logger.error("Error encyrpting the assertion"); throw new GuanxiException(e); } }