org.jcp.xml.dsig.internal.dom.DOMXMLSignatureFactory Maven / Gradle / Ivy
The newest version!
/* */ package org.jcp.xml.dsig.internal.dom;
/* */
/* */ import java.security.AccessController;
/* */ import java.security.InvalidAlgorithmParameterException;
/* */ import java.security.NoSuchAlgorithmException;
/* */ import java.security.PrivilegedAction;
/* */ import java.security.Security;
/* */ import java.util.List;
/* */ import javax.xml.crypto.Data;
/* */ import javax.xml.crypto.MarshalException;
/* */ import javax.xml.crypto.URIDereferencer;
/* */ import javax.xml.crypto.XMLStructure;
/* */ import javax.xml.crypto.dom.DOMStructure;
/* */ import javax.xml.crypto.dsig.CanonicalizationMethod;
/* */ import javax.xml.crypto.dsig.DigestMethod;
/* */ import javax.xml.crypto.dsig.Manifest;
/* */ import javax.xml.crypto.dsig.Reference;
/* */ import javax.xml.crypto.dsig.SignatureMethod;
/* */ import javax.xml.crypto.dsig.SignatureProperties;
/* */ import javax.xml.crypto.dsig.SignatureProperty;
/* */ import javax.xml.crypto.dsig.SignedInfo;
/* */ import javax.xml.crypto.dsig.Transform;
/* */ import javax.xml.crypto.dsig.TransformService;
/* */ import javax.xml.crypto.dsig.XMLObject;
/* */ import javax.xml.crypto.dsig.XMLSignature;
/* */ import javax.xml.crypto.dsig.XMLSignatureFactory;
/* */ import javax.xml.crypto.dsig.XMLValidateContext;
/* */ import javax.xml.crypto.dsig.dom.DOMValidateContext;
/* */ import javax.xml.crypto.dsig.keyinfo.KeyInfo;
/* */ import javax.xml.crypto.dsig.spec.C14NMethodParameterSpec;
/* */ import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
/* */ import javax.xml.crypto.dsig.spec.SignatureMethodParameterSpec;
/* */ import javax.xml.crypto.dsig.spec.TransformParameterSpec;
/* */ import org.w3c.dom.Document;
/* */ import org.w3c.dom.Element;
/* */ import org.w3c.dom.Node;
/* */
/* */ public final class DOMXMLSignatureFactory extends XMLSignatureFactory
/* */ {
/* */ public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki)
/* */ {
/* 44 */ return new DOMXMLSignature(si, ki, null, null, null);
/* */ }
/* */
/* */ public XMLSignature newXMLSignature(SignedInfo si, KeyInfo ki, List objects, String id, String signatureValueId)
/* */ {
/* 49 */ return new DOMXMLSignature(si, ki, objects, id, signatureValueId);
/* */ }
/* */
/* */ public Reference newReference(String uri, DigestMethod dm) {
/* 53 */ return newReference(uri, dm, null, null, null);
/* */ }
/* */
/* */ public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id)
/* */ {
/* 58 */ return new DOMReference(uri, type, dm, transforms, id);
/* */ }
/* */
/* */ public Reference newReference(String uri, DigestMethod dm, List appliedTransforms, Data result, List transforms, String type, String id)
/* */ {
/* 64 */ if (appliedTransforms == null) {
/* 65 */ throw new NullPointerException("appliedTransforms cannot be null");
/* */ }
/* 67 */ if (appliedTransforms.isEmpty()) {
/* 68 */ throw new NullPointerException("appliedTransforms cannot be empty");
/* */ }
/* 70 */ if (result == null) {
/* 71 */ throw new NullPointerException("result cannot be null");
/* */ }
/* 73 */ return new DOMReference(uri, type, dm, appliedTransforms, result, transforms, id);
/* */ }
/* */
/* */ public Reference newReference(String uri, DigestMethod dm, List transforms, String type, String id, byte[] digestValue)
/* */ {
/* 79 */ if (digestValue == null) {
/* 80 */ throw new NullPointerException("digestValue cannot be null");
/* */ }
/* 82 */ return new DOMReference(uri, type, dm, null, null, transforms, id, digestValue);
/* */ }
/* */
/* */ public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references)
/* */ {
/* 88 */ return newSignedInfo(cm, sm, references, null);
/* */ }
/* */
/* */ public SignedInfo newSignedInfo(CanonicalizationMethod cm, SignatureMethod sm, List references, String id)
/* */ {
/* 93 */ return new DOMSignedInfo(cm, sm, references, id);
/* */ }
/* */
/* */ public XMLObject newXMLObject(List content, String id, String mimeType, String encoding)
/* */ {
/* 99 */ return new DOMXMLObject(content, id, mimeType, encoding);
/* */ }
/* */
/* */ public Manifest newManifest(List references) {
/* 103 */ return newManifest(references, null);
/* */ }
/* */
/* */ public Manifest newManifest(List references, String id) {
/* 107 */ return new DOMManifest(references, id);
/* */ }
/* */
/* */ public SignatureProperties newSignatureProperties(List props, String id) {
/* 111 */ return new DOMSignatureProperties(props, id);
/* */ }
/* */
/* */ public SignatureProperty newSignatureProperty(List info, String target, String id)
/* */ {
/* 116 */ return new DOMSignatureProperty(info, target, id);
/* */ }
/* */
/* */ public XMLSignature unmarshalXMLSignature(XMLValidateContext context)
/* */ throws MarshalException
/* */ {
/* 122 */ if (context == null) {
/* 123 */ throw new NullPointerException("context cannot be null");
/* */ }
/* 125 */ return unmarshal(((DOMValidateContext)context).getNode(), context);
/* */ }
/* */
/* */ public XMLSignature unmarshalXMLSignature(XMLStructure xmlStructure)
/* */ throws MarshalException
/* */ {
/* 131 */ if (xmlStructure == null) {
/* 132 */ throw new NullPointerException("xmlStructure cannot be null");
/* */ }
/* 134 */ return unmarshal(((DOMStructure)xmlStructure).getNode(), null);
/* */ }
/* */
/* */ private XMLSignature unmarshal(Node node, XMLValidateContext context)
/* */ throws MarshalException
/* */ {
/* 142 */ node.normalize();
/* */
/* 144 */ Element element = null;
/* 145 */ if (node.getNodeType() == 9)
/* 146 */ element = ((Document)node).getDocumentElement();
/* 147 */ else if (node.getNodeType() == 1)
/* 148 */ element = (Element)node;
/* */ else {
/* 150 */ throw new MarshalException("Signature element is not a proper Node");
/* */ }
/* */
/* 155 */ String tag = element.getLocalName();
/* 156 */ if (tag == null) {
/* 157 */ throw new MarshalException("Document implementation must support DOM Level 2 and be namespace aware");
/* */ }
/* */
/* 160 */ if (tag.equals("Signature")) {
/* 161 */ return new DOMXMLSignature(element, context);
/* */ }
/* 163 */ throw new MarshalException("invalid Signature tag: " + tag);
/* */ }
/* */
/* */ public boolean isFeatureSupported(String feature)
/* */ {
/* 168 */ if (feature == null) {
/* 169 */ throw new NullPointerException();
/* */ }
/* 171 */ return false;
/* */ }
/* */
/* */ public DigestMethod newDigestMethod(String algorithm, DigestMethodParameterSpec params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 178 */ if (algorithm == null) {
/* 179 */ throw new NullPointerException();
/* */ }
/* 181 */ if (algorithm.equals("http://www.w3.org/2000/09/xmldsig#sha1")) {
/* 182 */ return new DOMSHA1DigestMethod(params);
/* */ }
/* 184 */ throw new NoSuchAlgorithmException("unsupported algorithm");
/* */ }
/* */
/* */ public SignatureMethod newSignatureMethod(String algorithm, SignatureMethodParameterSpec params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 191 */ if (algorithm == null) {
/* 192 */ throw new NullPointerException();
/* */ }
/* 194 */ if (algorithm.equals("http://www.w3.org/2000/09/xmldsig#hmac-sha1"))
/* 195 */ return new DOMHMACSignatureMethod(params);
/* 196 */ if (algorithm.equals("http://www.w3.org/2000/09/xmldsig#rsa-sha1"))
/* 197 */ return new DOMRSASignatureMethod(params);
/* 198 */ if (algorithm.equals("http://www.w3.org/2000/09/xmldsig#dsa-sha1")) {
/* 199 */ return new DOMDSASignatureMethod(params);
/* */ }
/* 201 */ throw new NoSuchAlgorithmException("unsupported algorithm");
/* */ }
/* */
/* */ public Transform newTransform(String algorithm, TransformParameterSpec params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 208 */ TransformService spi = TransformService.getInstance(algorithm, "DOM");
/* 209 */ spi.init(params);
/* 210 */ return new DOMTransform(spi);
/* */ }
/* */
/* */ public Transform newTransform(String algorithm, XMLStructure params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 216 */ TransformService spi = TransformService.getInstance(algorithm, "DOM");
/* 217 */ if (params == null)
/* 218 */ spi.init(null);
/* */ else {
/* 220 */ spi.init(params, null);
/* */ }
/* 222 */ return new DOMTransform(spi);
/* */ }
/* */
/* */ public CanonicalizationMethod newCanonicalizationMethod(String algorithm, C14NMethodParameterSpec params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 228 */ TransformService spi = TransformService.getInstance(algorithm, "DOM");
/* 229 */ spi.init(params);
/* 230 */ return new DOMCanonicalizationMethod(spi);
/* */ }
/* */
/* */ public CanonicalizationMethod newCanonicalizationMethod(String algorithm, XMLStructure params)
/* */ throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
/* */ {
/* 236 */ TransformService spi = TransformService.getInstance(algorithm, "DOM");
/* 237 */ if (params == null)
/* 238 */ spi.init(null);
/* */ else {
/* 240 */ spi.init(params, null);
/* */ }
/* 242 */ return new DOMCanonicalizationMethod(spi);
/* */ }
/* */
/* */ public URIDereferencer getURIDereferencer() {
/* 246 */ return DOMURIDereferencer.INSTANCE;
/* */ }
/* */
/* */ static
/* */ {
/* 30 */ AccessController.doPrivileged(new PrivilegedAction() {
/* */ public Object run() {
/* 32 */ Security.addProvider(new XMLDSigRI());
/* 33 */ return null;
/* */ }
/* */ });
/* */ }
/* */ }
/* Location: E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
* Qualified Name: org.jcp.xml.dsig.internal.dom.DOMXMLSignatureFactory
* JD-Core Version: 0.6.2
*/