本文整理汇总了Java中org.apache.xml.security.utils.Constants类的典型用法代码示例。如果您正苦于以下问题:Java Constants类的具体用法?Java Constants怎么用?Java Constants使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Constants类属于org.apache.xml.security.utils包,在下文中一共展示了Constants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testBug
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
@org.junit.Test
public void testBug() throws Exception {
Document document = getSignedDocument();
NodeList list =
document.getElementsByTagNameNS(Constants.SignatureSpecNS, Constants._TAG_SIGNATURE);
Element element = (Element) list.item(0);
XMLSignature signature = new XMLSignature(element, null);
KeyInfo keyInfo = signature.getKeyInfo();
X509Certificate certificate = keyInfo.getX509Certificate();
assertNotNull(certificate);
try {
signature.checkSignatureValue(certificate);
} catch (XMLSignatureException e) {
fail(e.getMessage());
}
}
示例2: lengthUnknownElement
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Method lengthUnknownElement
* NOTE possibly buggy.
* @return the number of the UnknownElement tags
*/
public int lengthUnknownElement() {
int res = 0;
Node childNode = getElement().getFirstChild();
while (childNode != null) {
/**
* $todo$ using this method, we don't see unknown Elements
* from Signature NS; revisit
*/
if (childNode.getNodeType() == Node.ELEMENT_NODE
&& childNode.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
res++;
}
childNode = childNode.getNextSibling();
}
return res;
}
示例3: searchSignatureElement
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* @param signatureElement
* @return the node that is the signature
* @throws TransformationException
*/
private static Node searchSignatureElement(Node signatureElement)
throws TransformationException {
boolean found = false;
while (true) {
if (signatureElement == null
|| signatureElement.getNodeType() == Node.DOCUMENT_NODE) {
break;
}
Element el = (Element) signatureElement;
if (el.getNamespaceURI().equals(Constants.SignatureSpecNS)
&& el.getLocalName().equals(Constants._TAG_SIGNATURE)) {
found = true;
break;
}
signatureElement = signatureElement.getParentNode();
}
if (!found) {
throw new TransformationException(
"transform.envelopedSignatureTransformNotInSignatureElement");
}
return signatureElement;
}
示例4: testWrongReferentType
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
@org.junit.Test
public void testWrongReferentType() throws Exception {
Document doc = loadXML("KeyInfoReference-WrongReferentType.xml");
markKeyInfoIdAttrs(doc);
// Mark the ID-ness of the bogus element so can be resolved
NodeList nl = doc.getElementsByTagNameNS("http://www.example.org/test", "KeyInfo");
for (int i = 0; i < nl.getLength(); i++) {
Element keyInfoElement = (Element) nl.item(i);
keyInfoElement.setIdAttributeNS(null, Constants._ATT_ID, true);
}
Element referenceElement = doc.getElementById("theReference");
assertNotNull(referenceElement);
KeyInfo keyInfo = new KeyInfo(referenceElement, "");
assertNull(keyInfo.getPublicKey());
}
示例5: testDSAPublicKey
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
@org.junit.Test
public void testDSAPublicKey() throws Exception {
File f = null;
String filename =
"src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/signature-enveloping-dsa.xml";
if (BASEDIR != null && !"".equals(BASEDIR)) {
f = new File(BASEDIR + SEP + filename);
} else {
f = new File(filename);
}
Document doc = db.parse(new FileInputStream(f));
NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
XMLSignature sig = new XMLSignature
((Element) nl.item(0), f.toURI().toURL().toString());
KeyInfo ki = sig.getKeyInfo();
KeyValue kv = ki.itemKeyValue(0);
PublicKey pk = kv.getPublicKey();
assertNotNull(pk);
}
示例6: readAndVerifyManifest
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
private boolean readAndVerifyManifest(
String directory, String file, boolean secValidation
) throws Exception {
String basedir = System.getProperty("basedir");
if (basedir != null && !"".equals(basedir)) {
directory = basedir + "/" + directory;
}
File f = new File(directory + "/" + file);
javax.xml.parsers.DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
org.w3c.dom.Document doc = db.parse(f);
Element manifestElement =
(Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS,
Constants._TAG_SIGNEDINFO).item(0);
Manifest manifest = new Manifest(manifestElement, f.toURI().toURL().toString(), secValidation);
return manifest.verifyReferences();
}
示例7: Reference
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Build a {@link Reference} from an {@link Element}
*
* @param element <code>Reference</code> element
* @param baseURI the URI of the resource where the XML instance was stored
* @param manifest is the {@link Manifest} of {@link SignedInfo} in which the Reference occurs.
* @param secureValidation whether secure validation is enabled or not
* We need this because the Manifest has the individual {@link ResourceResolver}s which have
* been set by the user
* @throws XMLSecurityException
*/
protected Reference(Element element, String baseURI, Manifest manifest, boolean secureValidation)
throws XMLSecurityException {
super(element, baseURI);
this.secureValidation = secureValidation;
this.baseURI = baseURI;
Element el = XMLUtils.getNextElement(element.getFirstChild());
if (Constants._TAG_TRANSFORMS.equals(el.getLocalName())
&& Constants.SignatureSpecNS.equals(el.getNamespaceURI())) {
transforms = new Transforms(el, this.baseURI);
transforms.setSecureValidation(secureValidation);
if (secureValidation && transforms.getLength() > MAXIMUM_TRANSFORM_COUNT) {
Object exArgs[] = { transforms.getLength(), MAXIMUM_TRANSFORM_COUNT };
throw new XMLSecurityException("signature.tooManyTransforms", exArgs);
}
el = XMLUtils.getNextElement(el.getNextSibling());
}
digestMethodElem = el;
digestValueElement = XMLUtils.getNextElement(digestMethodElem.getNextSibling());
this.manifest = manifest;
}
示例8: itemUnknownElement
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Method itemUnknownElement
*
* @param i index
* @return the element number of the unknown elements
*/
public Element itemUnknownElement(int i) {
int res = 0;
Node childNode = getElement().getFirstChild();
while (childNode != null) {
/**
* $todo$ using this method, we don't see unknown Elements
* from Signature NS; revisit
*/
if (childNode.getNodeType() == Node.ELEMENT_NODE
&& childNode.getNamespaceURI().equals(Constants.SignatureSpecNS)) {
res++;
if (res == i) {
return (Element) childNode;
}
}
childNode = childNode.getNextSibling();
}
return null;
}
示例9: getContentsBeforeTransformation
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Returns the XMLSignatureInput which is created by de-referencing the URI attribute.
* @return the XMLSignatureInput of the source of this reference
* @throws ReferenceNotInitializedException If the resolver found any
* problem resolving the reference
*/
public XMLSignatureInput getContentsBeforeTransformation()
throws ReferenceNotInitializedException {
try {
Attr uriAttr =
getElement().getAttributeNodeNS(null, Constants._ATT_URI);
ResourceResolver resolver =
ResourceResolver.getInstance(
uriAttr, this.baseURI, this.manifest.getPerManifestResolvers(), secureValidation
);
resolver.addProperties(this.manifest.getResolverProperties());
return resolver.resolve(uriAttr, this.baseURI, secureValidation);
} catch (ResourceResolverException ex) {
throw new ReferenceNotInitializedException(ex);
}
}
示例10: engineCanResolve
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Method engineCanResolve
*
* @param element
* @param BaseURI
* @param storage
*
*/
public boolean engineCanResolve(Element element, String BaseURI, StorageResolver storage) {
if (element == null) {
return false;
}
log.debug("Can I resolve " + element.getTagName());
boolean isKeyName = XMLUtils.elementIsInSignatureSpace(element, Constants._TAG_KEYNAME);
try {
if (isKeyName) {
_kn = new KeyName(element, "");
if (_kn.getKeyName().equals("bob")) {
return true;
}
}
} catch (Exception e) {
// Do nothing
}
return false;
}
示例11: testNullKeyInfo
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
@org.junit.Test
public void testNullKeyInfo() throws Exception {
File f = null;
String filename =
"src/test/resources/ie/baltimore/merlin-examples/merlin-xmldsig-twenty-three/signature-enveloping-hmac-sha1.xml";
if (BASEDIR != null && !"".equals(BASEDIR)) {
f = new File(BASEDIR + SEP + filename);
} else {
f = new File(filename);
}
Document doc = db.parse(new FileInputStream(f));
NodeList nl = doc.getElementsByTagNameNS(Constants.SignatureSpecNS, "Signature");
XMLSignature sig = new XMLSignature
((Element) nl.item(0), f.toURI().toURL().toString());
KeyInfo ki = sig.getKeyInfo();
assertNull(ki);
}
示例12: SignatureProperties
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Constructs {@link SignatureProperties} from {@link Element}
* @param element <code>SignatureProperties</code> element
* @param baseURI the URI of the resource where the XML instance was stored
* @throws XMLSecurityException
*/
public SignatureProperties(Element element, String baseURI) throws XMLSecurityException {
super(element, baseURI);
Attr attr = element.getAttributeNodeNS(null, "Id");
if (attr != null) {
element.setIdAttributeNode(attr, true);
}
int length = getLength();
for (int i = 0; i < length; i++) {
Element propertyElem =
XMLUtils.selectDsNode(getElement(), Constants._TAG_SIGNATUREPROPERTY, i);
Attr propertyAttr = propertyElem.getAttributeNodeNS(null, "Id");
if (propertyAttr != null) {
propertyElem.setIdAttributeNode(propertyAttr, true);
}
}
}
示例13: SignedInfo
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Constructor SignedInfo
*
* @param doc <code>SignedInfo</code> is placed in this document
* @param signatureMethodURI URI representation of the Digest and
* Signature algorithm
* @param hMACOutputLength
* @param canonicalizationMethodURI URI representation of the
* Canonicalization method
* @throws XMLSecurityException
*/
public SignedInfo(
Document doc, String signatureMethodURI,
int hMACOutputLength, String canonicalizationMethodURI
) throws XMLSecurityException {
super(doc);
c14nMethod =
XMLUtils.createElementInSignatureSpace(getDocument(), Constants._TAG_CANONICALIZATIONMETHOD);
c14nMethod.setAttributeNS(null, Constants._ATT_ALGORITHM, canonicalizationMethodURI);
appendSelf(c14nMethod);
addReturnToSelf();
if (hMACOutputLength > 0) {
this.signatureAlgorithm =
new SignatureAlgorithm(getDocument(), signatureMethodURI, hMACOutputLength);
} else {
this.signatureAlgorithm = new SignatureAlgorithm(getDocument(), signatureMethodURI);
}
signatureMethod = this.signatureAlgorithm.getElement();
appendSelf(signatureMethod);
addReturnToSelf();
}
示例14: readAndVerifySignature
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
private boolean readAndVerifySignature(
String directory, String file
) throws Exception {
String basedir = System.getProperty("basedir");
if (basedir != null && !"".equals(basedir)) {
directory = basedir + "/" + directory;
}
File f = new File(directory + "/" + file);
javax.xml.parsers.DocumentBuilder db = XMLUtils.createDocumentBuilder(false, false);
org.w3c.dom.Document doc = db.parse(f);
Element sigElement =
(Element) doc.getElementsByTagNameNS(Constants.SignatureSpecNS,
Constants._TAG_SIGNATURE).item(0);
XMLSignature signature = new XMLSignature(sigElement, f.toURI().toURL().toString());
return signature.checkSignatureValue(signature.getKeyInfo().getPublicKey());
}
示例15: engineGetContextFromElement
import org.apache.xml.security.utils.Constants; //导入依赖的package包/类
/**
* Method engineGetContextFromElement
*
* @param element
*/
protected void engineGetContextFromElement(Element element) {
super.engineGetContextFromElement(element);
if (element == null) {
throw new IllegalArgumentException("element null");
}
Text hmaclength =
XMLUtils.selectDsNodeText(element.getFirstChild(), Constants._TAG_HMACOUTPUTLENGTH, 0);
if (hmaclength != null) {
this.HMACOutputLength = Integer.parseInt(hmaclength.getData());
this.HMACOutputLengthSet = true;
}
}