Class DefaultXMLSigner
java.lang.Object
se.idsec.signservice.security.sign.xml.impl.DefaultXMLSigner
- All Implemented Interfaces:
Signer<Document,
,XMLSignerResult, VoidSignerParameters> XMLSigner
Default implementation of the
XMLSigner
interface.
If the signature algorithm is not explicitly set the OpenSAML SignatureSigningConfiguration
system
configuration will be used to obtain a default.
- Author:
- Martin Lindström (martin@idsec.se), Stefan Santesson (stefan@idsec.se)
-
Nested Class Summary
Nested Classes -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionDefaultXMLSigner
(se.swedenconnect.security.credential.PkiCredential signingCredential) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbuilder
(se.swedenconnect.security.credential.PkiCredential signingCredential) Creates a builder forDefaultXMLSigner
objects.Gets the digest algorithm to use.Gets the signature algorithm to use.se.swedenconnect.security.credential.PkiCredential
static String
registerIdAttributes
(Document document) Looks for an ID reference in the root element, and if found, registers it using theElement.setIdAttribute(String, boolean)
method.void
setAlgorithmRegistry
(se.swedenconnect.security.algorithms.AlgorithmRegistry algorithmRegistry) Assigns theAlgorithmRegistry
to use.void
setCanonicalizationTransform
(String canonicalizationTransform) Assigns the canonicalization method to use.void
setIncludeCertificateChain
(boolean includeCertificateChain) Sets whether the certificate chain/path be included in the signature (if available fromPkiCredential.getCertificateChain()
).void
setIncludeSignatureId
(boolean includeSignatureId) Should an ID attribute be written to the resulting ds:Signature element.void
setSignatureAlgorithm
(String signatureAlgorithm) Assigns the URI for the signature algorithm to be used.void
setSignatureLocation
(XMLSignatureLocation signatureLocation) Sets the indicator that tells where in the document the resulting Signature element should be inserted.void
setXPathTransform
(String xPathTransform) Sets the XPath expression to be used in an XPath transform.
-
Field Details
-
DEFAULT_CANONICALIZATION_TRANSFORM
The default canonicalization method - required Exclusive Canonicalization (omits comments).- See Also:
-
DEFAULT_XPATH_TRANSFORM
The default XPath transform (don't include Signature elements).- See Also:
-
-
Constructor Details
-
DefaultXMLSigner
public DefaultXMLSigner(se.swedenconnect.security.credential.PkiCredential signingCredential) Constructor.- Parameters:
signingCredential
- the signing credential to use
-
-
Method Details
-
builder
public static DefaultXMLSigner.DefaultXMLSignerBuilder builder(se.swedenconnect.security.credential.PkiCredential signingCredential) Creates a builder forDefaultXMLSigner
objects.- Parameters:
signingCredential
- the signing credential to use- Returns:
- a builder instance
-
sign
- Specified by:
sign
in interfaceSigner<Document,
XMLSignerResult, VoidSignerParameters> - Throws:
SignatureException
-
getSigningCredential
public se.swedenconnect.security.credential.PkiCredential getSigningCredential()- Specified by:
getSigningCredential
in interfaceSigner<Document,
XMLSignerResult, VoidSignerParameters>
-
setSignatureLocation
Sets the indicator that tells where in the document the resulting Signature element should be inserted. If not set, the default "insert as the last child of the document root element" will be used.- Parameters:
signatureLocation
- location indicator
-
setSignatureAlgorithm
public void setSignatureAlgorithm(String signatureAlgorithm) throws NoSuchAlgorithmException, SignatureException Assigns the URI for the signature algorithm to be used.- Parameters:
signatureAlgorithm
- the signature algorithm URI- Throws:
NoSuchAlgorithmException
- if the algorithm is not supported (or blacklisted)SignatureException
- if the signature algorithm can not be used by the current signature credential
-
getSignatureAlgorithm
Gets the signature algorithm to use.If the digest algorithm is not explicitly set, the default signature algorithm given by the
AlgorithmRegistry
will be used.- Returns:
- the signature algorithm URI
-
getDigestAlgorithm
Gets the digest algorithm to use.- Returns:
- the digest algorithm URI
-
setCanonicalizationTransform
Assigns the canonicalization method to use. Default is "http://www.w3.org/2001/10/xml-exc-c14n#".- Parameters:
canonicalizationTransform
- canonicalization method URI
-
setXPathTransform
Sets the XPath expression to be used in an XPath transform. The default is "not(ancestor-or-self::*[local-name()=\'Signature\' and namespace-uri()=\'http://www.w3.org/2000/09/xmldsig#\'])". Ifnull
, no XPath transform is used.- Parameters:
xPathTransform
- XPath expression
-
setIncludeCertificateChain
public void setIncludeCertificateChain(boolean includeCertificateChain) Sets whether the certificate chain/path be included in the signature (if available fromPkiCredential.getCertificateChain()
). The default isfalse
(only the entity certificate is included).- Parameters:
includeCertificateChain
- whether the certificate chain should be included
-
setIncludeSignatureId
public void setIncludeSignatureId(boolean includeSignatureId) Should an ID attribute be written to the resulting ds:Signature element. Default istrue
.- Parameters:
includeSignatureId
- whether an ID attribute should be written to the Signature element
-
setAlgorithmRegistry
public void setAlgorithmRegistry(se.swedenconnect.security.algorithms.AlgorithmRegistry algorithmRegistry) Assigns theAlgorithmRegistry
to use. If not assigned, the registry configured forAlgorithmRegistrySingleton
will be used.- Parameters:
algorithmRegistry
- the registry to use
-
registerIdAttributes
Looks for an ID reference in the root element, and if found, registers it using theElement.setIdAttribute(String, boolean)
method.- Parameters:
document
- the document- Returns:
- the signature URI reference ("" if no ID is found)
-