Example usage for javax.xml.crypto MarshalException MarshalException

List of usage examples for javax.xml.crypto MarshalException MarshalException

Introduction

In this page you can find the example usage for javax.xml.crypto MarshalException MarshalException.

Prototype

public MarshalException(Throwable cause) 

Source Link

Document

Constructs a new MarshalException with the specified cause and a detail message of (cause==null ?

Usage

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMHMACSignatureMethod.java

/**
 * Creates a <code>DOMHMACSignatureMethod</code> from an element.
 *
 * @param smElem a SignatureMethod element
 *///from w w w.  ja va2s.  c  om
DOMHMACSignatureMethod(Element smElem) throws MarshalException {
    Element paramsElem = DOMUtils.getFirstChildElement(smElem);
    if (paramsElem != null) {
        params = unmarshalParams(paramsElem);
    }
    try {
        checkParams(params);
    } catch (InvalidAlgorithmParameterException iape) {
        throw new MarshalException(iape);
    }
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMReference.java

/**
 * Creates a <code>DOMReference</code> from an element.
 *
 * @param refElem a Reference element//from w  w w . j a  v  a  2s.co m
 */
public DOMReference(Element refElem, XMLCryptoContext context, Provider provider) throws MarshalException {
    Boolean secureValidation = (Boolean) context.getProperty("org.apache.jcp.xml.dsig.secureValidation");
    boolean secVal = false;
    if (secureValidation != null && secureValidation.booleanValue()) {
        secVal = true;
    }

    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List<Transform> transforms = new ArrayList<Transform>(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
        Element transformElem = DOMUtils.getFirstChildElement(nextSibling);

        int transformCount = 0;
        while (transformElem != null) {
            transforms.add(new DOMTransform(transformElem, context, provider));
            transformElem = DOMUtils.getNextSiblingElement(transformElem);

            transformCount++;
            if (secVal && (transformCount > MAXIMUM_TRANSFORM_COUNT)) {
                String error = "A maxiumum of " + MAXIMUM_TRANSFORM_COUNT + " "
                        + "transforms per Reference are allowed with secure validation";
                throw new MarshalException(error);
            }
        }
        nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);
    String digestMethodAlgorithm = this.digestMethod.getAlgorithm();
    if (secVal && MessageDigestAlgorithm.ALGO_ID_DIGEST_NOT_RECOMMENDED_MD5.equals(digestMethodAlgorithm)) {
        throw new MarshalException(
                "It is forbidden to use algorithm " + digestMethod + " when secure validation is enabled");
    }

    // unmarshal DigestValue
    try {
        Element dvElem = DOMUtils.getNextSiblingElement(dmElem);
        this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");

    Attr attr = refElem.getAttributeNodeNS(null, "Id");
    if (attr != null) {
        this.id = attr.getValue();
        refElem.setIdAttributeNode(attr, true);
    } else {
        this.id = null;
    }

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;
    this.transforms = transforms;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
    this.provider = provider;
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMSignatureMethod.java

/**
 * Creates a <code>DOMSignatureMethod</code> from an element. This ctor
 * invokes the {@link #unmarshalParams unmarshalParams} method to
 * unmarshal any algorithm-specific input parameters.
 *
 * @param smElem a SignatureMethod element
 *///from ww w. j  a  va  2  s .c o m
DOMSignatureMethod(Element smElem) throws MarshalException {
    Element paramsElem = DOMUtils.getFirstChildElement(smElem);
    if (paramsElem != null) {
        params = unmarshalParams(paramsElem);
    }
    try {
        checkParams(params);
    } catch (InvalidAlgorithmParameterException iape) {
        throw new MarshalException(iape);
    }
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMSignatureMethod.java

static SignatureMethod unmarshal(Element smElem) throws MarshalException {
    String alg = DOMUtils.getAttributeValue(smElem, "Algorithm");
    if (alg.equals(SignatureMethod.RSA_SHA1)) {
        return new SHA1withRSA(smElem);
    } else if (alg.equals(RSA_SHA256)) {
        return new SHA256withRSA(smElem);
    } else if (alg.equals(RSA_SHA384)) {
        return new SHA384withRSA(smElem);
    } else if (alg.equals(RSA_SHA512)) {
        return new SHA512withRSA(smElem);
    } else if (alg.equals(SignatureMethod.DSA_SHA1)) {
        return new SHA1withDSA(smElem);
    } else if (alg.equals(ECDSA_SHA1)) {
        return new SHA1withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA256)) {
        return new SHA256withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA384)) {
        return new SHA384withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA512)) {
        return new SHA512withECDSA(smElem);
    } else if (alg.equals(SignatureMethod.HMAC_SHA1)) {
        return new DOMHMACSignatureMethod.SHA1(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA256)) {
        return new DOMHMACSignatureMethod.SHA256(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA384)) {
        return new DOMHMACSignatureMethod.SHA384(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA512)) {
        return new DOMHMACSignatureMethod.SHA512(smElem);
    } else if (alg.equals(GOSTR34102001_GOSTR3411)) {
        return new GOST3411withGOST3410(smElem);
    } else if (alg.equals(GOSTR34102001_GOSTR3411URN)) {
        return new GOST3411withGOST3410URN(smElem);
    } else {/*from w ww  .  j  av  a2  s .  c om*/
        throw new MarshalException("unsupported SignatureMethod algorithm: " + alg);
    }
}

From source file:org.apache.jcp.xml.dsig.internal.dom.DOMSignedInfo.java

/**
 * Creates a <code>DOMSignedInfo</code> from an element.
 *
 * @param siElem a SignedInfo element//w w w  .  j a  va  2 s. co m
 */
public DOMSignedInfo(Element siElem, XMLCryptoContext context, Provider provider) throws MarshalException {
    localSiElem = siElem;
    ownerDoc = siElem.getOwnerDocument();

    // get Id attribute, if specified
    id = DOMUtils.getAttributeValue(siElem, "Id");

    // unmarshal CanonicalizationMethod
    Element cmElem = DOMUtils.getFirstChildElement(siElem);
    canonicalizationMethod = new DOMCanonicalizationMethod(cmElem, context, provider);

    // unmarshal SignatureMethod
    Element smElem = DOMUtils.getNextSiblingElement(cmElem);
    signatureMethod = DOMSignatureMethod.unmarshal(smElem);

    Boolean secureValidation = (Boolean) context.getProperty("org.apache.jcp.xml.dsig.secureValidation");
    boolean secVal = false;
    if (secureValidation != null && secureValidation.booleanValue()) {
        secVal = true;
    }

    String signatureMethodAlgorithm = signatureMethod.getAlgorithm();
    if (secVal && ((ALGO_ID_MAC_HMAC_NOT_RECOMMENDED_MD5.equals(signatureMethodAlgorithm)
            || ALGO_ID_SIGNATURE_NOT_RECOMMENDED_RSA_MD5.equals(signatureMethodAlgorithm)))) {
        throw new MarshalException(
                "It is forbidden to use algorithm " + signatureMethod + " when secure validation is enabled");
    }

    // unmarshal References
    ArrayList<Reference> refList = new ArrayList<Reference>(5);
    Element refElem = DOMUtils.getNextSiblingElement(smElem);

    int refCount = 0;
    while (refElem != null) {
        refList.add(new DOMReference(refElem, context, provider));
        refElem = DOMUtils.getNextSiblingElement(refElem);

        refCount++;
        if (secVal && (refCount > MAXIMUM_REFERENCE_COUNT)) {
            String error = "A maxiumum of " + MAXIMUM_REFERENCE_COUNT + " "
                    + "references per Manifest are allowed with secure validation";
            throw new MarshalException(error);
        }
    }
    references = Collections.unmodifiableList(refList);
}

From source file:org.jcp.xml.dsig.internal.dom.DOMReference.java

/**
 * Creates a <code>DOMReference</code> from an element.
 *
 * @param refElem a Reference element//from w  w  w  . j av a2  s .  co m
 */
public DOMReference(Element refElem, XMLCryptoContext context, Provider provider) throws MarshalException {
    // unmarshal Transforms, if specified
    Element nextSibling = DOMUtils.getFirstChildElement(refElem);
    List<Transform> transforms = new ArrayList<Transform>(5);
    if (nextSibling.getLocalName().equals("Transforms")) {
        Element transformElem = DOMUtils.getFirstChildElement(nextSibling);
        while (transformElem != null) {
            transforms.add(new DOMTransform(transformElem, context, provider));
            transformElem = DOMUtils.getNextSiblingElement(transformElem);
        }
        nextSibling = DOMUtils.getNextSiblingElement(nextSibling);
    }

    // unmarshal DigestMethod
    Element dmElem = nextSibling;
    this.digestMethod = DOMDigestMethod.unmarshal(dmElem);

    // unmarshal DigestValue
    try {
        Element dvElem = DOMUtils.getNextSiblingElement(dmElem);
        this.digestValue = Base64.decode(dvElem);
    } catch (Base64DecodingException bde) {
        throw new MarshalException(bde);
    }

    // unmarshal attributes
    this.uri = DOMUtils.getAttributeValue(refElem, "URI");
    this.id = DOMUtils.getAttributeValue(refElem, "Id");
    if (this.id != null) {
        DOMCryptoContext dcc = (DOMCryptoContext) context;
        dcc.setIdAttributeNS(refElem, null, "Id");
    }

    this.type = DOMUtils.getAttributeValue(refElem, "Type");
    this.here = refElem.getAttributeNodeNS(null, "URI");
    this.refElem = refElem;
    this.transforms = transforms;
    this.allTransforms = transforms;
    this.appliedTransformData = null;
    this.provider = provider;
}

From source file:org.jcp.xml.dsig.internal.dom.DOMSignatureMethod.java

static SignatureMethod unmarshal(Element smElem) throws MarshalException {
    String alg = DOMUtils.getAttributeValue(smElem, "Algorithm");
    if (alg.equals(SignatureMethod.RSA_SHA1)) {
        return new SHA1withRSA(smElem);
    } else if (alg.equals(RSA_SHA256)) {
        return new SHA256withRSA(smElem);
    } else if (alg.equals(RSA_SHA384)) {
        return new SHA384withRSA(smElem);
    } else if (alg.equals(RSA_SHA512)) {
        return new SHA512withRSA(smElem);
    } else if (alg.equals(SignatureMethod.DSA_SHA1)) {
        return new SHA1withDSA(smElem);
    } else if (alg.equals(ECDSA_SHA1)) {
        return new SHA1withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA256)) {
        return new SHA256withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA384)) {
        return new SHA384withECDSA(smElem);
    } else if (alg.equals(ECDSA_SHA512)) {
        return new SHA512withECDSA(smElem);
    } else if (alg.equals(SignatureMethod.HMAC_SHA1)) {
        return new DOMHMACSignatureMethod.SHA1(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA256)) {
        return new DOMHMACSignatureMethod.SHA256(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA384)) {
        return new DOMHMACSignatureMethod.SHA384(smElem);
    } else if (alg.equals(DOMHMACSignatureMethod.HMAC_SHA512)) {
        return new DOMHMACSignatureMethod.SHA512(smElem);
    } else {//from  ww  w.  j ava2 s. c o m
        throw new MarshalException("unsupported SignatureMethod algorithm: " + alg);
    }
}