List of usage examples for org.w3c.dom Document importNode
public Node importNode(Node importedNode, boolean deep) throws DOMException;
From source file:org.wso2.carbon.identity.sts.OpenIDTokenIssuer.java
/** * Overrides the base functionality to cater OpenID related functionality. *//*from w w w . j ava 2 s .c o m*/ protected OMElement createRSTR(RahasData data, Date notBefore, Date notAfter, SOAPEnvelope env, Document doc, Node assertionElem, String assertionId, WSSecEncryptedKey encryptedKey) throws TrustException, SAMLException, IdentityProviderException { OMElement rstrElem = null; int wstVersion; OMElement appliesToEpr = null; DateFormat zulu = null; OMElement reqSecTokenElem = null; wstVersion = data.getVersion(); rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(wstVersion, env.getBody()); TrustUtil.createTokenTypeElement(wstVersion, rstrElem).setText(data.getTokenType()); createDisplayToken(rstrElem, ipData); if (log.isDebugEnabled()) { log.debug("Display token for OpenID Information card, created successfully"); } if (encryptedKey != null) { OMElement incomingAppliesToEpr = null; OMElement appliesToElem = null; int keysize = data.getKeysize(); if (keysize == -1) { keysize = encryptedKey.getEphemeralKey().length * 8; } TrustUtil.createKeySizeElement(wstVersion, rstrElem, keysize); incomingAppliesToEpr = data.getAppliesToEpr(); try { Document eprDoc = null; eprDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder() .parse(new ByteArrayInputStream(incomingAppliesToEpr.toString().getBytes())); appliesToEpr = (OMElement) doc.importNode(eprDoc.getDocumentElement(), true); } catch (Exception e) { throw new TrustException(TrustException.REQUEST_FAILED, e); } appliesToElem = rstrElem.getOMFactory() .createOMElement(new QName(RahasConstants.WSP_NS, RahasConstants.IssuanceBindingLocalNames.APPLIES_TO, RahasConstants.WSP_PREFIX), rstrElem); appliesToElem.addChild(appliesToEpr); } // Use GMT time in milliseconds zulu = new XmlSchemaDateFormat(); // Add the Lifetime element TrustUtil.createLifetimeElement(wstVersion, rstrElem, zulu.format(notBefore), zulu.format(notAfter)); reqSecTokenElem = TrustUtil.createRequestedSecurityTokenElement(wstVersion, rstrElem); createOpenIdToken(reqSecTokenElem); createAttachedRef(rstrElem, assertionId); createUnattachedRef(rstrElem, assertionId); if (log.isDebugEnabled()) log.debug("RSTR for OpenID Information card, created successfully"); return rstrElem; }
From source file:pl.psnc.ep.rt.web.servlets.CollXMLServlet.java
private static Node createLearningObjectives(List<? extends AbstractAttributeValue> learningObjectivesAV, Document targetDocument) { if (learningObjectives == null) { HashMap<String, Node> lo = new HashMap<String, Node>(); try {// w w w .j a v a 2 s.co m InputStream xmlStream = CollXMLServlet.class.getResourceAsStream("/cele_ksztalcenia-opcje.xml"); try { Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(xmlStream); NodeList optionsList = document.getElementsByTagName("option"); for (int i = 0; i < optionsList.getLength(); i++) { Node option = optionsList.item(i); String key = findChild(option, "key").getTextContent(); Node value = findChild(findChild(option, "value"), "ep:learning-objectives"); lo.put(key, value); } } finally { xmlStream.close(); } learningObjectives = lo; } catch (Exception e) { logger.error("Could not parse learning objectives description", e); } } String objective = learningObjectivesAV.get(0).getValue(); Node objectivesNode = learningObjectives.get(objective); if (objectivesNode == null) { logger.error("No learning objective description for " + objective); return element(targetDocument, Namespace.EP, "learning-objectives", null); } Node imported = targetDocument.importNode(objectivesNode, true); return imported; }
From source file:ru.codeinside.gws.crypto.cryptopro.CryptoProvider.java
@Override public String signElement(String sourceXML, String elementName, String namespace, boolean removeIdAttribute, boolean signatureAfterElement, boolean inclusive) throws Exception { loadCertificate();/*from w ww .j a v a 2s . c o m*/ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setIgnoringElementContentWhitespace(true); dbf.setCoalescing(true); dbf.setNamespaceAware(true); DocumentBuilder documentBuilder = dbf.newDocumentBuilder(); InputSource is = new InputSource(new StringReader(sourceXML)); Document doc = documentBuilder.parse(is); Element elementForSign = (Element) doc.getElementsByTagNameNS(namespace, elementName).item(0); Node parentNode = null; Element detachedElementForSign; Document detachedDocument; if (!elementForSign.isSameNode(doc.getDocumentElement())) { parentNode = elementForSign.getParentNode(); parentNode.removeChild(elementForSign); detachedDocument = documentBuilder.newDocument(); Node importedElementForSign = detachedDocument.importNode(elementForSign, true); detachedDocument.appendChild(importedElementForSign); detachedElementForSign = detachedDocument.getDocumentElement(); } else { detachedElementForSign = elementForSign; detachedDocument = doc; } String signatureMethodUri = inclusive ? "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102001-gostr3411" : "http://www.w3.org/2001/04/xmldsig-more#gostr34102001-gostr3411"; String canonicalizationMethodUri = inclusive ? "http://www.w3.org/TR/2001/REC-xml-c14n-20010315" : "http://www.w3.org/2001/10/xml-exc-c14n#"; XMLSignature sig = new XMLSignature(detachedDocument, "", signatureMethodUri, canonicalizationMethodUri); if (!removeIdAttribute) { detachedElementForSign.setAttribute("Id", detachedElementForSign.getTagName()); } if (signatureAfterElement) detachedElementForSign.insertBefore(sig.getElement(), detachedElementForSign.getLastChild().getNextSibling()); else { detachedElementForSign.insertBefore(sig.getElement(), detachedElementForSign.getFirstChild()); } Transforms transforms = new Transforms(detachedDocument); transforms.addTransform("http://www.w3.org/2000/09/xmldsig#enveloped-signature"); transforms.addTransform(inclusive ? "http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments" : "http://www.w3.org/2001/10/xml-exc-c14n#"); String digestURI = inclusive ? "urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr3411" : "http://www.w3.org/2001/04/xmldsig-more#gostr3411"; sig.addDocument(removeIdAttribute ? "" : "#" + detachedElementForSign.getTagName(), transforms, digestURI); sig.addKeyInfo(cert); sig.sign(privateKey); if ((!elementForSign.isSameNode(doc.getDocumentElement())) && (parentNode != null)) { Node signedNode = doc.importNode(detachedElementForSign, true); parentNode.appendChild(signedNode); } TransformerFactory tf = TransformerFactory.newInstance(); Transformer trans = tf.newTransformer(); trans.setOutputProperty("omit-xml-declaration", "yes"); StringWriter stringWriter = new StringWriter(); StreamResult streamResult = new StreamResult(stringWriter); trans.transform(new DOMSource(doc), streamResult); return stringWriter.toString(); }
From source file:ru.codeinside.gws3572c.GMPClientSignTest.java
@Test public void testSignForEntity() throws Exception { ClientRequest request = client.createClientRequest(createContext()); InputSource is = new InputSource(new StringReader(request.appData)); Document doc = documentBuilder.parse(is); Element elementForSign = (Element) doc.getElementsByTagNameNS(null, "Charge").item(0); Node parentNode;//from w ww .j a v a2s . c o m Document detachedDocument; if (!elementForSign.isSameNode(doc.getDocumentElement())) { parentNode = elementForSign.getParentNode(); parentNode.removeChild(elementForSign); detachedDocument = documentBuilder.newDocument(); Node importedElementForSign = detachedDocument.importNode(elementForSign, true); detachedDocument.appendChild(importedElementForSign); } else { detachedDocument = doc; } Element nscontext = detachedDocument.createElementNS(null, "namespaceContext"); nscontext.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:" + "ds".trim(), "http://www.w3.org/2000/09/xmldsig#"); Element certificateElement = (Element) XPathAPI.selectSingleNode(detachedDocument, "//ds:X509Certificate[1]", nscontext); Element sigElement = (Element) certificateElement.getParentNode().getParentNode().getParentNode(); XMLSignature signature = new XMLSignature(sigElement, ""); CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate certKey = (X509Certificate) cf.generateCertificate( new ByteArrayInputStream(Base64.decode(certificateElement.getTextContent().trim().getBytes()))); Assert.assertNotNull("There are no information about public key. Verification couldn't be implemented", certKey); Assert.assertTrue("Signature is not valid", signature.checkSignatureValue(certKey)); }
From source file:se.unlogic.hierarchy.core.servlets.CoreServlet.java
private void addBackgroundModuleResponses(List<BackgroundModuleResponse> backgroundModuleResponses, Document doc, User user, HttpServletRequest req) { if (backgroundModuleResponses != null) { Element backgroundsModuleResponsesElement = doc.createElement("backgroundsModuleResponses"); doc.getFirstChild().appendChild(backgroundsModuleResponsesElement); Document debugDoc; // Write xml to file if debug enabled if (backgroundModuleXMLDebug && !StringUtils.isEmpty(this.backgroundModuleXMLDebugFile)) { debugDoc = XMLUtils.createDomDocument(); debugDoc.appendChild(debugDoc.createElement("BackgroundModuleDebug")); } else {// www. j av a 2s. co m debugDoc = null; } for (BackgroundModuleResponse moduleResponse : backgroundModuleResponses) { if (isValidResponse(moduleResponse)) { if (moduleResponse.getResponseType() == ResponseType.HTML) { // Append module html response Element responseElement = doc.createElement("response"); backgroundsModuleResponsesElement.appendChild(responseElement); Element htmlElement = doc.createElement("HTML"); responseElement.appendChild(htmlElement); htmlElement.appendChild(doc.createCDATASection(moduleResponse.getHtml())); this.appendSlots(moduleResponse, doc, responseElement); } else if (moduleResponse.getResponseType() == ResponseType.XML_FOR_CORE_TRANSFORMATION) { // Append module response Element responseElement = doc.createElement("response"); backgroundsModuleResponsesElement.appendChild(responseElement); Element xmlElement = doc.createElement("XML"); responseElement.appendChild(xmlElement); xmlElement.appendChild(doc.adoptNode(moduleResponse.getElement())); this.appendSlots(moduleResponse, doc, responseElement); } else if (moduleResponse.getResponseType() == ResponseType.XML_FOR_SEPARATE_TRANSFORMATION) { if (moduleResponse.getTransformer() != null) { //Append XML to debug document if (debugDoc != null) { this.log.debug("Background XML debug mode enabled, appending XML from module " + moduleResponse.getModuleDescriptor() + " to XML debug document"); try { Element documentElement = (Element) debugDoc .importNode(moduleResponse.getDocument().getDocumentElement(), true); if (moduleResponse.getModuleDescriptor() != null) { documentElement.setAttribute("moduleID", moduleResponse.getModuleDescriptor().getModuleID() + ""); documentElement.setAttribute("name", moduleResponse.getModuleDescriptor().getName()); } debugDoc.getDocumentElement().appendChild(documentElement); } catch (Exception e) { this.log.error("Error appending XML from module " + moduleResponse.getModuleDescriptor() + " to XML debug document", e); } } // Transform output try { StringWriter stringWriter = new StringWriter(); this.log.debug("Background module XML transformation starting"); XMLTransformer.transformToWriter(moduleResponse.getTransformer(), moduleResponse.getDocument(), stringWriter, encoding); this.log.debug( "Background module XML transformation finished, appending result..."); // Append module response Element responseElement = doc.createElement("response"); backgroundsModuleResponsesElement.appendChild(responseElement); Element htmlElement = doc.createElement("HTML"); responseElement.appendChild(htmlElement); htmlElement.appendChild(doc.createCDATASection(stringWriter.toString())); this.appendSlots(moduleResponse, doc, responseElement); this.log.debug("Result appended"); } catch (Exception e) { this.log.error("Tranformation of background module response from module" + moduleResponse.getModuleDescriptor() + " failed while processing request from user " + user + " accessing from " + req.getRemoteAddr(), e); } } else { this.log.error( "Background module response for separate transformation without attached stylesheet returned by module " + moduleResponse.getModuleDescriptor() + " while processing request from user " + user + " accessing from " + req.getRemoteAddr()); } } } } //Write background module XML debug to file if (debugDoc != null && debugDoc.getDocumentElement().hasChildNodes()) { log.debug("Writing background module XML debug to file " + backgroundModuleXMLDebugFile); try { XMLUtils.writeXMLFile(debugDoc, this.applicationFileSystemPath + "WEB-INF/" + backgroundModuleXMLDebugFile, true, encoding); } catch (Exception e) { log.error("Error writing background module XML debug to file " + backgroundModuleXMLDebugFile, e); } } } }
From source file:sos.scheduler.cron.CronConverter.java
/** * Converts a crontab to a Scheduler XML as DOM document and * provides easy access to the job elements by putting them to the vector * jobs//from ww w . j ava 2 s. c o m * @param cronFile crontab file * @param cron2jobMapping empty vector which will be filled with cron lines mapped to job DOM Elements * @return DOM Document with scheduler configuration * @throws Exception */ public Document cronFile2SchedulerXML(final File cronFile, final HashMap<String, Element> cron2jobMapping) throws Exception { try { HashSet<String> jobNames = new HashSet<String>(); if (reservedJobNames != null) { jobNames.addAll(reservedJobNames); } HashMap<String, String> environmentVariables = new HashMap<String, String>(); Document configurationDoc = docBuilder.newDocument(); Element spoolerElement = configurationDoc.createElement(conTagSPOOLER); configurationDoc.appendChild(spoolerElement); Element configElement = configurationDoc.createElement("config"); spoolerElement.appendChild(configElement); Element jobsElement = configurationDoc.createElement("jobs"); configElement.appendChild(jobsElement); BufferedReader in = new BufferedReader(new FileReader(cronFile)); Vector<Element> vecJobs = new Vector<Element>(); Vector<String> vecCronRecords = new Vector<String>(); lastComment = ""; String lastCommentJobName = ""; String lastCommentJobTitle = ""; String lastCommentJobTimeout = ""; while ((strCronLine = in.readLine()) != null) { if (strCronLine.trim().length() == 0) { lastComment = ""; continue; } if (skipLines != null && skipLines.contains(strCronLine)) { logger.debug("Skipping line " + strCronLine); lastComment = ""; lastCommentJobName = ""; lastCommentJobTitle = ""; lastCommentJobTimeout = ""; continue; } Matcher commentMatcher = cronRegExCommentPattern.matcher(strCronLine); if (commentMatcher.matches()) { Matcher jobNameMatcher = cronRegExJobNamePattern.matcher(commentMatcher.group(1)); Matcher jobTitleMatcher = cronRegExJobTitlePattern.matcher(commentMatcher.group(1)); Matcher jobTimeoutMatcher = cronRegExJobTimeoutPattern.matcher(commentMatcher.group(1)); if (jobNameMatcher.matches()) { lastCommentJobName = jobNameMatcher.group(1); logger.debug("Found job name in comment: " + lastCommentJobName); continue; } if (jobTitleMatcher.matches()) { lastCommentJobTitle = jobTitleMatcher.group(1); logger.debug("Found job title in comment: " + lastCommentJobTitle); continue; } if (jobTimeoutMatcher.matches()) { lastCommentJobTimeout = jobTimeoutMatcher.group(1); logger.debug("Found job timeout in comment: " + lastCommentJobTimeout); continue; } if (lastComment.length() > 0) { lastComment += conNewline; } lastComment += commentMatcher.group(1); continue; } Matcher environmentMatcher = cronRegExEnvironmentPattern.matcher(strCronLine); if (environmentMatcher.matches()) { String envName = environmentMatcher.group(1); String envValue = environmentMatcher.group(2); logger.debug("Found environment variable [" + envName + "]: " + envValue); if (envValue.startsWith("\"") && envValue.endsWith("\"")) { envValue = envValue.substring(1, envValue.length() - 1); } environmentVariables.put(envName, envValue); lastComment = ""; } Matcher cronMatcher = currentCronPattern.matcher(strCronLine); Matcher cronAliasMatcher = cronRegExAliasPattern.matcher(strCronLine); if (cronMatcher.matches() || cronAliasMatcher.matches()) { vecCronRecords.add(strCronLine); Document jobDocument = createJobElement(strCronLine, environmentVariables); Element jobElement = jobDocument.getDocumentElement(); //NodeList jobChildren = jobElement.getChildNodes(); //Element paramsElement = null; /*for (int i=0; i<jobChildren.getLength() && paramsElement==null;i++){ Node currentNode = jobChildren.item(i); if (currentNode.getNodeName().equals("params")) paramsElement = (Element) currentNode; }*/ boolean jobNameChanged = false; if (lastCommentJobName.length() > 0) { jobElement.setAttribute(conAttributeNAME, lastCommentJobName.replaceAll("/", "_")); lastCommentJobName = ""; } if (lastCommentJobTitle.length() > 0) { jobElement.setAttribute(conAttributeTITLE, lastCommentJobTitle); lastCommentJobTitle = ""; } if (lastCommentJobTimeout.length() > 0) { jobElement.setAttribute(conOptionTIMEOUT, lastCommentJobTimeout); lastCommentJobTimeout = ""; } String jobName = jobElement.getAttribute(conAttributeNAME); while (jobNames.contains(jobName)) { // logger.debug("Configuration already contains a job named \"" + jobName + "\". Looking for new name."); jobName = incrementJobName(jobName); jobNameChanged = true; } if (jobNameChanged) { logger.debug("Setting new job name \"" + jobName + "\""); jobElement.setAttribute(conAttributeNAME, jobName); } jobNames.add(jobName); Node importedJob = configurationDoc.importNode(jobElement, true); cron2jobMapping.put(strCronLine, jobElement); if (lastComment.length() > 0) { // change "--" to "__" due to problems with xml-comment parser lastComment = lastComment.replaceAll("--", "__"); Comment jobComment = configurationDoc.createComment(lastComment); jobsElement.appendChild(jobComment); } jobsElement.appendChild(importedJob); lastComment = ""; vecJobs.add(jobElement); } } if (isCreateJobChainJobs()) { Element jobChainsElement = configurationDoc.createElement("job_chains"); configElement.appendChild(jobChainsElement); int i = 0; for (Element objJobElement : vecJobs) { strCronLine = vecCronRecords.get(i++); Document objJCD = createJobChainElement(objJobElement); Element objJC = objJCD.getDocumentElement(); jobChainsElement.appendChild(configurationDoc.importNode(objJC, true)); } Element commandsElement = configurationDoc.createElement("commands"); configElement.appendChild(commandsElement); i = 0; for (Element objJobElement : vecJobs) { strCronLine = vecCronRecords.get(i++); Document objJCD = createOrderElement(objJobElement); Element objJC = objJCD.getDocumentElement(); commandsElement.appendChild(configurationDoc.importNode(objJC, true)); } } in.close(); return configurationDoc; } catch (Exception e) { throw new JobSchedulerException( "Error converting file " + cronFile.getAbsolutePath() + " to JobScheduler XML: " + e, e); } }
From source file:sos.scheduler.cron.CronConverter.java
public Document createJobElement(String cronline, final HashMap<String, String> environmentVariables) throws Exception { try {//from w w w. j ava 2 s . c o m logger.info("processing line: " + cronline); Document eleJob = docBuilder.newDocument(); Element jobElement = eleJob.createElement(conTagJOB); Matcher cronRegExAliasMatcher = cronRegExAliasPattern.matcher(cronline); if (cronRegExAliasMatcher.matches()) { logger.debug("Current line matches pattern " + cronRegExAlias); cronline = convertAlias(cronRegExAliasMatcher); } Matcher cronRegExMatcher = cronRegExPattern.matcher(cronline); int commandIndex = 6; if (isSystemCronTab()) { commandIndex = 7; cronRegExMatcher = cronRegExSystemPattern.matcher(cronline); } if (!cronRegExMatcher.matches()) { throw new JobSchedulerException("Fail to parse cron line \"" + cronline + "\""); } String jobname = getJobName(cronRegExMatcher.group(commandIndex)); jobElement.setAttribute(conAttributeNAME, jobname); if (isCreateJobChainJobs()) { jobElement.setAttribute(conAttributeORDER, "yes"); } else { jobElement.setAttribute(conAttributeORDER, "no"); } jobElement.setAttribute(conAttributeTITLE, "Cron Job " + cronRegExMatcher.group(commandIndex).trim()); //jobElement.setAttribute("replace", "yes"); if (timeout != null && !timeout.equals("0")) { jobElement.setAttribute(conOptionTIMEOUT, timeout); } String schedulerUser = ""; String command = cronRegExMatcher.group(commandIndex); if (isSystemCronTab()) { schedulerUser = cronRegExMatcher.group(6); command = (changeUserCommand + " " + command).trim(); } jobElement.appendChild(createExtension(eleJob)); if (isCreateJobChainJobs() == false) { logger.debug("Creating params element"); Element paramsElement = eleJob.createElement("params"); logger.debug("Creating param element (command)"); Element paramCommandElement = eleJob.createElement("param"); paramCommandElement.setAttribute("name", "command"); paramCommandElement.setAttribute("value", command); paramsElement.appendChild(paramCommandElement); jobElement.appendChild(paramsElement); } logger.debug("Creating script element"); Element scriptElement = eleJob.createElement(conTagSCRIPT); scriptElement.setAttribute(conAttributeLANGUAGE, "shell"); String script = conNewline; if (schedulerUser.length() > 0) { script += "export SCHEDULER_CRONTAB_USER=" + schedulerUser + conNewline; } Iterator<String> envIter = environmentVariables.keySet().iterator(); // set environment variables on job while (envIter.hasNext()) { String envName = envIter.next().toString(); String envValue = environmentVariables.get(envName).toString(); script += envName + "=" + envValue + conNewline; script += "export " + envName; } script += "echo created by " + conClassName + ", at " + SOSDate.getCurrentTimeAsString() + conNewline; if (isCreateAMock() == true) { script += "echo mock-mode: " + command + conNewline; if (strMockCommand.length() > 0) { script += strMockCommand + conNewline; } script += "exit 0" + conNewline; } else { script += command; } Node scriptData = eleJob.createCDATASection(script); scriptElement.appendChild(scriptData); jobElement.appendChild(scriptElement); if (isCreateJobChainJobs() == false) { Element runTimeElement = eleJob.createElement(conTagRUN_TIME); createRunTime(cronRegExMatcher, runTimeElement); if (usedNewRunTime && oldRunTime) { // workaround while <month> Element is not available // can later be deleted (keep only else branch) usedNewRunTime = false; Document runTimeDocument = docBuilder.newDocument(); runTimeDocument.appendChild(runTimeDocument.importNode(runTimeElement, true)); StringWriter out = new StringWriter(); OutputFormat format = new OutputFormat(runTimeDocument); format.setIndenting(true); format.setIndent(2); format.setOmitXMLDeclaration(true); XMLSerializer serializer = new XMLSerializer(out, format); serializer.serialize(runTimeDocument); Comment runTimeComment = eleJob .createComment("This run_time is currently not supported:\n" + out.toString()); jobElement.appendChild(runTimeComment); } else { jobElement.appendChild(runTimeElement); } } eleJob.appendChild(jobElement); return eleJob; } catch (Exception e) { throw new JobSchedulerException("Error occured creating job from cron line: " + cronline, e); } }
From source file:test.integ.be.fedict.eid.idp.WSFederationTest.java
@Test public void testSAML2AssertionTokenSignature() throws Exception { InputStream documentInputStream = WSFederationTest.class .getResourceAsStream("/eid-idp-ws-fed-response.xml"); assertNotNull(documentInputStream);/* w ww . j av a 2 s. c o m*/ DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document wsFedDocument = documentBuilder.parse(documentInputStream); NodeList assertionNodeList = wsFedDocument.getElementsByTagNameNS("urn:oasis:names:tc:SAML:2.0:assertion", "Assertion"); assertEquals(1, assertionNodeList.getLength()); Element assertionElement = (Element) assertionNodeList.item(0); Document tokenDocument = documentBuilder.newDocument(); Node assertionTokenNode = tokenDocument.importNode(assertionElement, true); tokenDocument.appendChild(assertionTokenNode); LOG.debug("assertion token: " + toString(tokenDocument)); NodeList signatureNodeList = tokenDocument.getElementsByTagNameNS("http://www.w3.org/2000/09/xmldsig#", "Signature"); assertEquals(1, signatureNodeList.getLength()); Element signatureElement = (Element) signatureNodeList.item(0); XMLSignature xmlSignature = new XMLSignature(signatureElement, ""); KeyInfo keyInfo = xmlSignature.getKeyInfo(); X509Certificate certificate = keyInfo.getX509Certificate(); boolean result = xmlSignature.checkSignatureValue(certificate); assertTrue(result); }