当前位置: 首页>>代码示例>>Java>>正文


Java XMLSecurityException类代码示例

本文整理汇总了Java中org.apache.xml.security.exceptions.XMLSecurityException的典型用法代码示例。如果您正苦于以下问题:Java XMLSecurityException类的具体用法?Java XMLSecurityException怎么用?Java XMLSecurityException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


XMLSecurityException类属于org.apache.xml.security.exceptions包,在下文中一共展示了XMLSecurityException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getDigestMethodAlgorithm

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
private static String getDigestMethodAlgorithm(final Optional<Signature> signature) {
    if (signature.isPresent()) {
        XMLSignature xmlSignature = ((SignatureImpl) signature.get()).getXMLSignature();
        if (xmlSignature != null) {
            SignedInfo signedInfo = xmlSignature.getSignedInfo();
            try {
                if (signedInfo != null && signedInfo.getLength() != 0 && signedInfo.item(0) != null) {
                    MessageDigestAlgorithm messageDigestAlgorithm = signedInfo.item(0).getMessageDigestAlgorithm();
                    if (messageDigestAlgorithm != null) {
                        return messageDigestAlgorithm.getJCEAlgorithmString();
                    }
                }
            } catch (XMLSecurityException e) {
                LOG.debug(format("Error getting message digest algorithm: {0}", e));
            }
        }
    }
    return null;
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:20,代码来源:UnknownMethodAlgorithmLogger.java

示例2: signObject

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * Signs a single XMLObject.
 * 
 * @param signature the signature to computer the signature on
 * @throws SignatureException thrown if there is an error computing the signature
 */
public static void signObject(Signature signature) throws SignatureException {
    Logger log = getLogger();
    try {
        XMLSignature xmlSignature = ((SignatureImpl) signature).getXMLSignature();

        if (xmlSignature == null) {
            log.error("Unable to compute signature, Signature XMLObject does not have the XMLSignature "
                    + "created during marshalling.");
            throw new SignatureException("XMLObject does not have an XMLSignature instance, unable to compute signature");
        }
        log.debug("Computing signature over XMLSignature object");
        xmlSignature.sign(SecurityHelper.extractSigningKey(signature.getSigningCredential()));
    } catch (XMLSecurityException e) {
        log.error("An error occured computing the digital signature", e);
        throw new SignatureException("Signature computation error", e);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:24,代码来源:Signer.java

示例3: validateReference

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * Validate the Signature's SignedInfo Reference.
 * 
 * The SignedInfo must contain exactly 1 Reference.
 * 
 * @param apacheSig the Apache XML Signature instance
 * @return the valid Reference contained within the SignedInfo
 * @throws ValidationException thrown if the Signature does not contain exactly 1 Reference, or if there is an error
 *             obtaining the Reference instance
 */
protected Reference validateReference(XMLSignature apacheSig) throws ValidationException {
    int numReferences = apacheSig.getSignedInfo().getLength();
    if (numReferences != 1) {
        log.error("Signature SignedInfo had invalid number of References: " + numReferences);
        throw new ValidationException("Signature SignedInfo must have exactly 1 Reference element");
    }

    Reference ref = null;
    try {
        ref = apacheSig.getSignedInfo().item(0);
    } catch (XMLSecurityException e) {
        log.error("Apache XML Security exception obtaining Reference", e);
        throw new ValidationException("Could not obtain Reference from Signature/SignedInfo", e);
    }
    if (ref == null) {
        log.error("Signature Reference was null");
        throw new ValidationException("Signature Reference was null");
    }
    return ref;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:31,代码来源:SAMLSignatureProfileValidator.java

示例4: newKeyInfo

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * @param element
 * @return a new KeyInfo
 * @throws XMLEncryptionException
 */
KeyInfo newKeyInfo(Element element) throws XMLEncryptionException {
    try {
        KeyInfo ki = new KeyInfo(element, null);
        ki.setSecureValidation(secureValidation);
        if (internalKeyResolvers != null) {
            int size = internalKeyResolvers.size();
            for (int i = 0; i < size; i++) {
                ki.registerInternalKeyResolver(internalKeyResolvers.get(i));
            }
        }
        return ki;
    } catch (XMLSecurityException xse) {
        throw new XMLEncryptionException("Error loading Key Info", xse);
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:21,代码来源:XMLCipher.java

示例5: setEnvelope

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * Set the envelope to host the Signature element. That is the
 * XML document where the Signature element to be added. The
 * digital signature here will always be an enveloped signature.
 * The envelope will be included in the process of signing.
 *
 * @param doc the XML document to host the Signature element
 * @param algo the algorithm used for digital signature. Currently, only 
 *             two values are tested: <code>dsa-sha1</code> and 
 *             <code>rsa-sha1</code>.
 * @throws SignException internal exception when doing initialization
 *                       on Apache XML Security library
 */
public void setEnvelope(Document doc, String algo) throws SignException {
    envelope = doc;
    try {
        if (algo != null) {
            signature = new XMLSignature(envelope, NAMESPACE_URI_DS,
                                         NAMESPACE_URI_DS + algo);
        }
    } catch (XMLSecurityException e) {
        String err = "Cannot create XMLSignature object - " 
            + e.getMessage();
        logger.error(err);
        throw new SignException(err);
    }
    this.algo = algo;
    logger.debug("setEnvelope, using algorithm: " + algo);
}
 
开发者ID:cecid,项目名称:hermes,代码行数:30,代码来源:ApacheXMLDSigner.java

示例6: getCanonicalizedOctetStream

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * Returns getCanonicalizedOctetStream
 *
 * @return the canonicalization result octet stream of <code>SignedInfo</code> element
 * @throws CanonicalizationException
 * @throws InvalidCanonicalizerException
 * @throws XMLSecurityException
 */
public byte[] getCanonicalizedOctetStream()
    throws CanonicalizationException, InvalidCanonicalizerException, XMLSecurityException {
    if (this.c14nizedBytes == null) {
        Canonicalizer c14nizer =
            Canonicalizer.getInstance(this.getCanonicalizationMethodURI());
        c14nizer.setSecureValidation(isSecureValidation());

        String inclusiveNamespaces = this.getInclusiveNamespaces();
        if (inclusiveNamespaces == null) {
            this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement());
        } else {
            this.c14nizedBytes = c14nizer.canonicalizeSubtree(getElement(), inclusiveNamespaces);
        }
    }

    // make defensive copy
    return this.c14nizedBytes.clone();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:SignedInfo.java

示例7: Reference

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的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;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:33,代码来源:Reference.java

示例8: newKeyInfo

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * @param element
 * @return a new KeyInfo
 * @throws XMLEncryptionException
 */
KeyInfo newKeyInfo(Element element) throws XMLEncryptionException {
    try {
        KeyInfo ki = new KeyInfo(element, null);
        ki.setSecureValidation(secureValidation);
        if (internalKeyResolvers != null) {
            int size = internalKeyResolvers.size();
            for (int i = 0; i < size; i++) {
                ki.registerInternalKeyResolver(internalKeyResolvers.get(i));
            }
        }
        return ki;
    } catch (XMLSecurityException xse) {
        throw new XMLEncryptionException(xse, "KeyInfo.error");
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:21,代码来源:XMLCipher.java

示例9: newSignatureVerifier

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
@Override
protected SignatureVerifier newSignatureVerifier(final InputProcessorChain inputProcessorChain,
                                                 final XMLSecurityProperties securityProperties,
                                                 final SignatureType signatureType) throws XMLSecurityException {

    final InboundSecurityContext inboundSecurityContext = inputProcessorChain.getSecurityContext();

    AlgorithmSuiteSecurityEvent algorithmSuiteSecurityEvent = new AlgorithmSuiteSecurityEvent();
    algorithmSuiteSecurityEvent.setAlgorithmURI(signatureType.getSignedInfo().getCanonicalizationMethod().getAlgorithm());
    algorithmSuiteSecurityEvent.setAlgorithmUsage(XMLSecurityConstants.SigC14n);
    algorithmSuiteSecurityEvent.setCorrelationID(signatureType.getId());
    inboundSecurityContext.registerSecurityEvent(algorithmSuiteSecurityEvent);

    SignatureValueSecurityEvent signatureValueSecurityEvent = new SignatureValueSecurityEvent();
    signatureValueSecurityEvent.setSignatureValue(signatureType.getSignatureValue().getValue());
    signatureValueSecurityEvent.setCorrelationID(signatureType.getId());
    inboundSecurityContext.registerSecurityEvent(signatureValueSecurityEvent);

    return new XMLSignatureVerifier(signatureType, inboundSecurityContext, securityProperties);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:21,代码来源:XMLSignatureInputHandler.java

示例10: SignedInfo

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/**
 * @param doc
 * @param signatureMethodElem
 * @param canonicalizationMethodElem
 * @throws XMLSecurityException
 */
public SignedInfo(
    Document doc, Element signatureMethodElem, Element canonicalizationMethodElem
) throws XMLSecurityException {
    super(doc);
    // Check this?
    this.c14nMethod = canonicalizationMethodElem;
    appendSelf(c14nMethod);
    addReturnToSelf();

    this.signatureAlgorithm =
        new SignatureAlgorithm(signatureMethodElem, null);

    signatureMethod = this.signatureAlgorithm.getElement();
    appendSelf(signatureMethod);

    addReturnToSelf();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:24,代码来源:SignedInfo.java

示例11: setUpOutboundEncryptionXMLSec

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
protected void setUpOutboundEncryptionXMLSec() throws XMLSecurityException {
    XMLSecurityProperties xmlSecurityProperties = new XMLSecurityProperties();
    List<XMLSecurityConstants.Action> actions = new ArrayList<XMLSecurityConstants.Action>();
    actions.add(XMLSecurityConstants.ENCRYPT);
    xmlSecurityProperties.setActions(actions);
    xmlSecurityProperties.setEncryptionKey(encryptionSymKey);
    xmlSecurityProperties.setEncryptionSymAlgorithm("http://www.w3.org/2001/04/xmlenc#aes256-cbc");

    SecurePart securePart = new SecurePart(
            new QName("http://www.example.com", "test"),
            SecurePart.Modifier.Element
    );
    xmlSecurityProperties.addEncryptionPart(securePart);

    outboundEncryptionXMLSec = XMLSec.getOutboundXMLSec(xmlSecurityProperties);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:17,代码来源:AbstractPerformanceTest.java

示例12: testSameKeySeveralAlgorithmSigning

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
@org.junit.Test
public void testSameKeySeveralAlgorithmSigning() throws Exception {
    Document doc = XMLUtils.createDocumentBuilder(false).newDocument();
    SignatureAlgorithm signatureAlgorithm =
        new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA1);
    PrivateKey pk = KeyPairGenerator.getInstance("RSA").genKeyPair().getPrivate();
    signatureAlgorithm.initSign(pk);
    signatureAlgorithm.update((byte)2);
    signatureAlgorithm.sign();
    SignatureAlgorithm otherSignatureAlgorithm =
        new SignatureAlgorithm(doc, XMLSignature.ALGO_ID_SIGNATURE_RSA_SHA256);

    try {
        otherSignatureAlgorithm.initSign(pk);
    } catch (XMLSecurityException ex) {
        log.warn(
            "Test testSameKeySeveralAlgorithmSigning skipped as necessary algorithms "
            + "not available"
        );
        return;
    }

    otherSignatureAlgorithm.update((byte)2);
    otherSignatureAlgorithm.sign();
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:26,代码来源:SignatureAlgorithmTest.java

示例13: engineLookupAndResolvePrivateKey

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/** {@inheritDoc}. */
public PrivateKey engineLookupAndResolvePrivateKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isDebugEnabled()) {
        log.debug("Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getPrivateKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug("XMLSecurityException", e);
        }
    }

    return null;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:26,代码来源:KeyInfoReferenceResolver.java

示例14: processEvent

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
@Override
public void processEvent(XMLSecEvent xmlSecEvent) throws XMLStreamException, XMLSecurityException {
    boolean reparent = false;
    if (this.curPos == this.startPos) {
        switch (xmlSecEvent.getEventType()) {
            case XMLStreamConstants.START_ELEMENT:
                if (xmlSecEvent == parentXmlSecStartElement) {
                    parentXmlSecStartElement = null;
                }
                xmlSecEvent.setParentXMLSecStartElement(parentXmlSecStartElement);
                parentXmlSecStartElement = xmlSecEvent.asStartElement();
                break;
            case XMLStreamConstants.END_ELEMENT:
                xmlSecEvent.setParentXMLSecStartElement(parentXmlSecStartElement);
                reparent = true;
                break;
            default:
                xmlSecEvent.setParentXMLSecStartElement(parentXmlSecStartElement);
                break;
        }
    }
    outputProcessors.get(this.curPos++).processNextEvent(xmlSecEvent, this);
    if (reparent && parentXmlSecStartElement != null) {
        parentXmlSecStartElement = parentXmlSecStartElement.getParentXMLSecStartElement();
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:27,代码来源:OutputProcessorChainImpl.java

示例15: engineLookupAndResolveSecretKey

import org.apache.xml.security.exceptions.XMLSecurityException; //导入依赖的package包/类
/** {@inheritDoc}. */
public SecretKey engineLookupAndResolveSecretKey(Element element, String baseURI, StorageResolver storage)
    throws KeyResolverException {

    if (log.isDebugEnabled()) {
        log.debug("Can I resolve " + element.getTagName());
    }

    if (!engineCanResolve(element, baseURI, storage)) {
        return null;
    }

    try {
        KeyInfo referent = resolveReferentKeyInfo(element, baseURI, storage);
        if (referent != null) {
            return referent.getSecretKey();
        }
    } catch (XMLSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug("XMLSecurityException", e);
        }
    }

    return null;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:26,代码来源:KeyInfoReferenceResolver.java


注:本文中的org.apache.xml.security.exceptions.XMLSecurityException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。