本文整理匯總了Java中org.apache.xml.security.utils.resolver.implementations.ResolverAnonymous類的典型用法代碼示例。如果您正苦於以下問題:Java ResolverAnonymous類的具體用法?Java ResolverAnonymous怎麽用?Java ResolverAnonymous使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResolverAnonymous類屬於org.apache.xml.security.utils.resolver.implementations包,在下文中一共展示了ResolverAnonymous類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test_coreFeatures_signatures_anonymousReferenceSignature
import org.apache.xml.security.utils.resolver.implementations.ResolverAnonymous; //導入依賴的package包/類
/**
* Method test_coreFeatures_signatures_anonymousReferenceSignature
*
* @throws Exception
*/
@org.junit.Test
public void test_coreFeatures_signatures_anonymousReferenceSignature()
throws Exception {
String filename =
gregorsDir + "coreFeatures/signatures/anonymousReferenceSignature.xml";
String anonymousRef =
gregorsDir + "coreFeatures/samples/anonymousReferenceContent.xml";
ResourceResolverSpi resolver = new ResolverAnonymous(anonymousRef);
boolean followManifests = false;
boolean verify = false;
try {
verify = this.verify(filename, resolver, followManifests);
} catch (RuntimeException ex) {
log.error("Verification crashed for " + filename);
throw ex;
}
if (!verify) {
log.error("Verification failed for " + filename);
}
assertTrue(filename, verify);
}
示例2: verifyAnonymous
import org.apache.xml.security.utils.resolver.implementations.ResolverAnonymous; //導入依賴的package包/類
public static void verifyAnonymous(String gregorsDir, DocumentBuilderFactory dbf) {
String filename =
gregorsDir + "coreFeatures/signatures/anonymousReferenceSignature.xml";
try {
String anonymousRef =
gregorsDir + "coreFeatures/samples/anonymousReferenceContent.xml";
ResourceResolverSpi resolver = new ResolverAnonymous(anonymousRef);
File f = new File(filename);
System.out.println("Try to verify " + f.toURI().toURL().toString());
javax.xml.parsers.DocumentBuilder db = dbf.newDocumentBuilder();
org.w3c.dom.Document doc = db.parse(new java.io.FileInputStream(f));
XPathFactory xpf = XPathFactory.newInstance();
XPath xpath = xpf.newXPath();
xpath.setNamespaceContext(new DSNamespaceContext());
String expression = "//ds:Signature[1]";
Element sigElement =
(Element) xpath.evaluate(expression, doc, XPathConstants.NODE);
XMLSignature signature = new XMLSignature(sigElement, f.toURI().toURL().toString());
signature.setFollowNestedManifests(false);
signature.addResourceResolver(resolver);
KeyInfo ki = signature.getKeyInfo();
if (ki != null) {
X509Certificate cert = signature.getKeyInfo().getX509Certificate();
if (cert != null) {
System.out.println(
"The XML signature in file " + f.toURI().toURL().toString() + " is "
+ (signature.checkSignatureValue(cert) ? "valid (good)"
: "invalid !!!!! (bad)")
);
} else {
PublicKey pk = signature.getKeyInfo().getPublicKey();
if (pk != null) {
System.out.println(
"The XML signature in file " + f.toURI().toURL().toString() + " is "
+ (signature.checkSignatureValue(pk) ? "valid (good)"
: "invalid !!!!! (bad)")
);
} else {
System.out.println("Did not find a public key, so I can't check the signature");
}
}
} else {
System.out.println("Did not find a KeyInfo");
}
} catch (Exception ex) {
System.out.println("The XML signature in file "
+ filename + " crashed the application (bad)");
ex.printStackTrace();
System.out.println();
}
}