List of usage examples for javax.xml.crypto.dsig Transform getAlgorithm
String getAlgorithm();
AlgorithmMethod
. From source file:org.apache.jcp.xml.dsig.internal.dom.DOMXMLSignature.java
private void digestReference(DOMReference ref, XMLSignContext signContext) throws XMLSignatureException { if (ref.isDigested()) { return;// www . ja va2 s . co m } // check dependencies String uri = ref.getURI(); if (Utils.sameDocumentURI(uri)) { String id = Utils.parseIdFromSameDocumentURI(uri); if (id != null && signatureIdMap.containsKey(id)) { XMLStructure xs = signatureIdMap.get(id); if (xs instanceof DOMReference) { digestReference((DOMReference) xs, signContext); } else if (xs instanceof Manifest) { Manifest man = (Manifest) xs; List manRefs = man.getReferences(); for (int i = 0, size = manRefs.size(); i < size; i++) { digestReference((DOMReference) manRefs.get(i), signContext); } } } // if uri="" and there are XPath Transforms, there may be // reference dependencies in the XPath Transform - so be on // the safe side, and skip and do at end in the final sweep if (uri.length() == 0) { @SuppressWarnings("unchecked") List<Transform> transforms = ref.getTransforms(); for (Transform transform : transforms) { String transformAlg = transform.getAlgorithm(); if (transformAlg.equals(Transform.XPATH) || transformAlg.equals(Transform.XPATH2)) { return; } } } } ref.digest(signContext); }
From source file:org.apache.ws.security.components.crypto.AlgorithmSuiteValidator.java
/** * Check the Signature Algorithms/*from www . j av a 2 s. com*/ */ public void checkSignatureAlgorithms(XMLSignature xmlSignature) throws WSSecurityException { // Signature Algorithm String signatureMethod = xmlSignature.getSignedInfo().getSignatureMethod().getAlgorithm(); checkSignatureMethod(signatureMethod); // C14n Algorithm String c14nMethod = xmlSignature.getSignedInfo().getCanonicalizationMethod().getAlgorithm(); checkC14nAlgorithm(c14nMethod); for (Object refObject : xmlSignature.getSignedInfo().getReferences()) { Reference reference = (Reference) refObject; // Digest Algorithm String digestMethod = reference.getDigestMethod().getAlgorithm(); Set<String> allowedDigestAlgorithms = algorithmSuite.getDigestAlgorithms(); if (!allowedDigestAlgorithms.isEmpty() && !allowedDigestAlgorithms.contains(digestMethod)) { LOG.debug("DigestMethod " + digestMethod + " does not match required value"); throw new WSSecurityException(WSSecurityException.INVALID_SECURITY); } // Transform Algorithms for (int i = 0; i < reference.getTransforms().size(); i++) { Transform transform = (Transform) reference.getTransforms().get(i); String algorithm = transform.getAlgorithm(); Set<String> allowedTransformAlgorithms = algorithmSuite.getTransformAlgorithms(); if (!allowedTransformAlgorithms.isEmpty() && !allowedTransformAlgorithms.contains(algorithm)) { LOG.debug("Transform method " + algorithm + " does not match required value"); throw new WSSecurityException(WSSecurityException.INVALID_SECURITY); } } } }