Package com.sun.identity.saml.xmlsig
Class XMLSignatureManager
- java.lang.Object
-
- com.sun.identity.saml.xmlsig.XMLSignatureManager
-
public class XMLSignatureManager extends Object
The classXMLSignatureManagerprovides methods to sign and verify XML signature.
-
-
Field Summary
Fields Modifier and Type Field Description protected static XMLSignatureManagerinstance
-
Constructor Summary
Constructors Modifier Constructor Description protectedXMLSignatureManager()ConstructorprotectedXMLSignatureManager(KeyProvider keyProvider, SignatureProvider sigProvider)Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static XMLSignatureManagergetInstance()Gets the singleton instance ofXMLSignatureManagerwith defaultKeyProviderandSignatureProvider.static XMLSignatureManagergetInstance(KeyProvider keyProvider, SignatureProvider sigProvider)Get an instance ofXMLSignatureManagerwith specifiedKeyProviderandSignatureProvider.KeyProvidergetKeyProvider()GetKeyProviderSignatureProvidergetSignatureProvider()Returns the SignatureProviderElementsignWithBinarySecurityToken(Document doc, Certificate cert, String algorithm, List ids, String refenceType)Sign part of the XML document wth binary security token using referred by the supplied a list of id attributes of nodes.ElementsignWithKerberosToken(Document doc, Key key, String algorithm, List ids)ElementsignWithSAMLToken(Document doc, Certificate cert, String assertionID, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignWithSAMLToken(Document doc, Key key, boolean symmetricKey, Certificate signingCert, Certificate encryptCert, String assertionID, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodes using SAML Token.ElementsignWithUserNameToken(Document doc, Certificate cert, String algorithm, List ids)Sign part of the XML document wth UserName security token using referred by the supplied a list of id attributes of nodes.ElementsignWithWSSSAMLTokenProfile(Document doc, Certificate cert, String assertionID, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignWithWSSSAMLTokenProfile(Document doc, Certificate cert, String assertionID, String algorithm, List ids, String wsfVersion)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignWithWSSX509TokenProfile(Document doc, Certificate cert, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignWithWSSX509TokenProfile(Document doc, Certificate cert, String algorithm, List ids, String wsfVersion)Sign part of the XML document referred by the supplied a list of id attributes of nodesStringsignXML(String XML, String certAlias)Sign the XML string using enveloped signatures.StringsignXML(String XML, String certAlias, String algorithm)Sign the XML string using enveloped signatures.StringsignXML(String xmlString, String certAlias, String algorithm, String id)Sign the XML string using enveloped signatures.StringsignXML(String xmlString, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.StringsignXML(String xmlString, String certAlias, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignXML(Document doc, String certAlias)Sign the XML document using enveloped signatures.ElementsignXML(Document doc, String certAlias, String algorithm)Sign the XML document using enveloped signatures.ElementsignXML(Document doc, String certAlias, String algorithm, String id)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.ElementsignXML(Document doc, String certAlias, String algorithm, String id, String xpath)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.ElementsignXML(Document doc, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.ElementsignXML(Document doc, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert, String xpath)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.ElementsignXML(Document doc, String certAlias, String algorithm, String transformAlag, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignXML(Document doc, String certAlias, String algorithm, List ids)Sign part of the XML document referred by the supplied a list of id attributes of nodesElementsignXMLUsingKeyPass(Document doc, String certAlias, String encryptedKeyPass, String algorithm, String idAttrName, String id, boolean includeCert, String xpath)Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.booleanverifyWSSSignature(Document document, String certAlias)Verify all the signatures of the XML document for the web services security.booleanverifyWSSSignature(Document document, Key key)Verify web services message signature using specified keybooleanverifyWSSSignature(Document document, Key key, String certAlias, String encryptAlias)Verify web services message signature using specified keybooleanverifyXMLSignature(String XML)Verify the signature of the XML stringbooleanverifyXMLSignature(String XML, String certAlias)Verify the signature of the XML stringbooleanverifyXMLSignature(String xmlString, String idAttrName, String certAlias)Verify the signature of the XML stringbooleanverifyXMLSignature(String wsfVersion, String certAlias, Document document)Verify all the signatures of the XML documentbooleanverifyXMLSignature(Document document)Verify all the signatures of the XML documentbooleanverifyXMLSignature(Document document, String certAlias)Verify all the signatures of the XML documentbooleanverifyXMLSignature(Document document, Certificate cert)Verify the signature of the XML documentbooleanverifyXMLSignature(Element element)Verify the signature of the XML documentbooleanverifyXMLSignature(Element element, String certAlias)Verify the signature of the XML documentbooleanverifyXMLSignature(Element element, String idAttrName, String certAlias)Verify the signature of the XML document
-
-
-
Field Detail
-
instance
protected static XMLSignatureManager instance
-
-
Constructor Detail
-
XMLSignatureManager
protected XMLSignatureManager()
Constructor
-
XMLSignatureManager
protected XMLSignatureManager(KeyProvider keyProvider, SignatureProvider sigProvider)
Constructor
-
-
Method Detail
-
getInstance
public static XMLSignatureManager getInstance()
Gets the singleton instance ofXMLSignatureManagerwith defaultKeyProviderandSignatureProvider.- Returns:
XMLSignatureManager
-
getInstance
public static XMLSignatureManager getInstance(KeyProvider keyProvider, SignatureProvider sigProvider)
Get an instance ofXMLSignatureManagerwith specifiedKeyProviderandSignatureProvider.- Parameters:
keyProvider-KeyProvidersigProvider-SignatureProvider.- Returns:
XMLSignatureManager.
-
getSignatureProvider
public SignatureProvider getSignatureProvider()
Returns the SignatureProvider- Returns:
- SignatureKeyProvider instance
-
signXML
public Element signXML(Document doc, String certAlias) throws XMLSignatureException
Sign the XML document using enveloped signatures.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias name- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm) throws XMLSignatureException
Sign the XML document using enveloped signatures.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- signature algorithm- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public String signXML(String XML, String certAlias) throws XMLSignatureException
Sign the XML string using enveloped signatures.- Parameters:
XML- XML string to be signedcertAlias- Signer's certificate alias name- Returns:
- XML signature string
- Throws:
XMLSignatureException- if the XML string could not be signed
-
signXML
public String signXML(String XML, String certAlias, String algorithm) throws XMLSignatureException
Sign the XML string using enveloped signatures.- Parameters:
XML- XML string to be signedcertAlias- Signer's certificate alias namealgorithm- signature algorithm- Returns:
- XML signature string
- Throws:
XMLSignatureException- if the XML string could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, String id) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmid- attribute value of the node to be signed- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, String id, String xpath) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmid- id attribute value of the node to be signedxpath- expression should uniquely identify a node before which- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmidAttrName- attribute name for the id attribute of the node to be signed.id- id attribute value of the node to be signedincludeCert- if true, include the signing certificate inKeyInfo. if false, does not include the signing certificate.- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public String signXML(String xmlString, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
xmlString- a string representing XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmidAttrName- attribute name for the id attribute of the node to be signed.id- id attribute value of the node to be signedincludeCert- if true, include the signing certificate inKeyInfo. if false, does not include the signing certificate.- Returns:
- a string of signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, String idAttrName, String id, boolean includeCert, String xpath) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmidAttrName- attribute name for the id attribute of the node to be signed.id- id attribute value of the node to be signedincludeCert- if true, include the signing certificate inKeyInfo. if false, does not include the signing certificate.xpath- expression should uniquely identify a node before which- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXMLUsingKeyPass
public Element signXMLUsingKeyPass(Document doc, String certAlias, String encryptedKeyPass, String algorithm, String idAttrName, String id, boolean includeCert, String xpath) throws XMLSignatureException
Sign part of the XML document referred by the supplied id attribute using enveloped signatures and use exclusive XML canonicalization.- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias nameencryptedKeyPass- Use the supplied encrypted key password to get the private keyalgorithm- XML signature algorithmidAttrName- attribute name for the id attribute of the node to be signed.id- id attribute value of the node to be signedincludeCert- if true, include the signing certificate inKeyInfo. if false, does not include the signing certificate.xpath- expression should uniquely identify a node before which- Returns:
- a signed dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public String signXML(String xmlString, String certAlias, String algorithm, String id) throws XMLSignatureException
Sign the XML string using enveloped signatures.- Parameters:
xmlString- XML string to be signedcertAlias- Signer's certificate alias namealgorithm- XML Signature algorithmid- id attribute value of the node to be signed- Returns:
- XML signature string
- Throws:
XMLSignatureException- if the XML string could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- signature dom object
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public String signXML(String xmlString, String certAlias, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
xmlString- XML dom object's string formatcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- XML signature string
- Throws:
XMLSignatureException- if the document could not be signed
-
signXML
public Element signXML(Document doc, String certAlias, String algorithm, String transformAlag, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcertAlias- Signer's certificate alias namealgorithm- XML signature algorithmtransformAlag- XML signature transform algorithm Those transfer constants are defined asSAMLConstants.TRANSFORM_XXX.ids- list of id attribute values of nodes to be signed- Returns:
- XML signature element
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithWSSSAMLTokenProfile
public Element signWithWSSSAMLTokenProfile(Document doc, Certificate cert, String assertionID, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcert- signer's CertificateassertionID- assertion ID for the SAML Security Tokenalgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- SAML Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithWSSSAMLTokenProfile
public Element signWithWSSSAMLTokenProfile(Document doc, Certificate cert, String assertionID, String algorithm, List ids, String wsfVersion) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcert- signer's CertificateassertionID- assertion ID for the SAML Security Tokenalgorithm- XML signature algorithmids- list of id attribute values of nodes to be signedwsfVersion- the web services framework that should be used. For WSF1.1, the version must be "1.1" and for WSF1.0, it must be "1.0"- Returns:
- SAML Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithSAMLToken
public Element signWithSAMLToken(Document doc, Certificate cert, String assertionID, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcert- signer's CertificateassertionID- assertion ID for the SAML Security Tokenalgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- SAML Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithSAMLToken
public Element signWithSAMLToken(Document doc, Key key, boolean symmetricKey, Certificate signingCert, Certificate encryptCert, String assertionID, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes using SAML Token.- Parameters:
doc- XML dom objectkey- the key that will be used to sign the document.symmetricKey- true if the supplied key is a symmetric key type.signingCert- signer's Certificate. If present, this certificate will be added as part of signatureKeyInfo.encryptCert- the certificate if present will be used to encrypt the symmetric key and replay it as part ofKeyInfoassertionID- assertion ID for the SAML Security Tokenalgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- SAML Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithKerberosToken
public Element signWithKerberosToken(Document doc, Key key, String algorithm, List ids) throws XMLSignatureException
- Throws:
XMLSignatureException
-
signWithBinarySecurityToken
public Element signWithBinarySecurityToken(Document doc, Certificate cert, String algorithm, List ids, String refenceType) throws XMLSignatureException
Sign part of the XML document wth binary security token using referred by the supplied a list of id attributes of nodes.- Parameters:
doc- the XMLDOMdocument.cert- Signer's certificatealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signedrefenceType- signed element reference type- Returns:
- X509 Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithUserNameToken
public Element signWithUserNameToken(Document doc, Certificate cert, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document wth UserName security token using referred by the supplied a list of id attributes of nodes.- Parameters:
doc- the XMLDOMdocument.cert- Signer's certificatealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- X509 Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithWSSX509TokenProfile
public Element signWithWSSX509TokenProfile(Document doc, Certificate cert, String algorithm, List ids) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcert- Signer's certificatealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signed- Returns:
- X509 Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
signWithWSSX509TokenProfile
public Element signWithWSSX509TokenProfile(Document doc, Certificate cert, String algorithm, List ids, String wsfVersion) throws XMLSignatureException
Sign part of the XML document referred by the supplied a list of id attributes of nodes- Parameters:
doc- XML dom objectcert- Signer's certificatealgorithm- XML signature algorithmids- list of id attribute values of nodes to be signedwsfVersion- the web services framework that should be used. For WSF1.1, it should be "1.1" and for WSF1.0, it should be "1.0"- Returns:
- X509 Security Token signature
- Throws:
XMLSignatureException- if the document could not be signed
-
verifyXMLSignature
public boolean verifyXMLSignature(Document document) throws XMLSignatureException
Verify all the signatures of the XML document- Parameters:
document- XML dom document whose signature to be verified- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(Document document, String certAlias) throws XMLSignatureException
Verify all the signatures of the XML document- Parameters:
document- XML dom document whose signature to be verifiedcertAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(Document document, Certificate cert) throws XMLSignatureException
Verify the signature of the XML document- Parameters:
document- XML dom document whose signature to be verifiedcert- Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(Element element) throws XMLSignatureException
Verify the signature of the XML document- Parameters:
element- XML dom document whose signature to be verified- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(Element element, String certAlias) throws XMLSignatureException
Verify the signature of the XML document- Parameters:
element- XML dom document whose signature to be verifiedcertAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(Element element, String idAttrName, String certAlias) throws XMLSignatureException
Verify the signature of the XML document- Parameters:
element- XML dom document whose signature to be verifiedidAttrName- Attribute name for the id attributecertAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(String XML) throws XMLSignatureException
Verify the signature of the XML string- Parameters:
XML- XML string whose signature to be verified- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(String XML, String certAlias) throws XMLSignatureException
Verify the signature of the XML string- Parameters:
XML- XML string whose signature to be verifiedcertAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo/- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyXMLSignature
public boolean verifyXMLSignature(String xmlString, String idAttrName, String certAlias) throws XMLSignatureException
Verify the signature of the XML string- Parameters:
xmlString- XML string whose signature to be verifiedidAttrName- Attribute name for the id attributecertAlias-certAliasfor Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.- Returns:
- true if the XML signature is verified, false otherwise.
- Throws:
XMLSignatureException- if problem occurs during verification.
-
verifyXMLSignature
public boolean verifyXMLSignature(String wsfVersion, String certAlias, Document document) throws XMLSignatureException
Verify all the signatures of the XML document- Parameters:
wsfVersion- the web services version that should be used.certAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.document- XML dom document whose signature to be verified- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification.
-
verifyWSSSignature
public boolean verifyWSSSignature(Document document, String certAlias) throws XMLSignatureException
Verify all the signatures of the XML document for the web services security.- Parameters:
document- XML dom document whose signature to be verifiedcertAlias- alias for Signer's certificate, this is used to search signer's public certificate if it is not presented inds:KeyInfo.- Returns:
- true if the XML signature is verified, false otherwise
- Throws:
XMLSignatureException- if problem occurs during verification
-
verifyWSSSignature
public boolean verifyWSSSignature(Document document, Key key) throws XMLSignatureException
Verify web services message signature using specified key- Parameters:
document- the document to be validatedkey- the secret key to be used for validating signature- Returns:
- true if verification is successful.
- Throws:
XMLSignatureException
-
verifyWSSSignature
public boolean verifyWSSSignature(Document document, Key key, String certAlias, String encryptAlias) throws XMLSignatureException
Verify web services message signature using specified key- Parameters:
document- the document to be validatedkey- the secret key to be used for validating signaturecertAlias- the certificate alias used for validating the signature if the key is not available.encryptAlias- the certificate alias that may be used to decrypt the symmetric key that may be part ofKeyInfo- Returns:
- true if verification is successful.
- Throws:
XMLSignatureException
-
getKeyProvider
public KeyProvider getKeyProvider()
GetKeyProvider- Returns:
KeyProvider
-
-