Class WSSecSignature
java.lang.Object
org.apache.ws.security.message.WSSecBase
org.apache.ws.security.message.WSSecSignature
Creates a Signature according to WS Specification, X509 profile.
This class is a refactored implementation of the previous WSS4J class
The flexibility and fine granular control is required to implement a handler that uses WSSecurityPolicy files to control the setup of a Security header.
WSSignEnvlope. This new class allows better control of
the process to create a Signature and to add it to the Security header.
The flexibility and fine granular control is required to implement a handler that uses WSSecurityPolicy files to control the setup of a Security header.
- Author:
- Davanum Srinivas (dims@yahoo.com), Werner Dittmann (werner@apache.org)
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BinarySecurityprotected Stringprotected Stringprotected Documentprotected org.apache.xml.security.keys.KeyInfoprotected Stringprotected SecurityTokenReferenceprotected org.apache.xml.security.signature.XMLSignatureprotected Stringprotected byte[]protected Stringprotected WSSecUsernameTokenprotected booleanprotected WSDocInfo -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddReferencesToSign(Vector references, WSSecHeader secHeader) This method adds references to the Signature.voidappendBSTElementToHeader(WSSecHeader secHeader) voidappendToHeader(WSSecHeader secHeader) Appends the Signature element to the elements already in the Security header.build(Document doc, Crypto cr, WSSecHeader secHeader) Builds a signed soap envelope.voidCompute the Signature over the references.protected ElementReturns the BST Token element.Get the id of the BSt generated duringprepare().getId()Get the id generated duringprepare().protected SetgetInclusivePrefixes(Element target) protected SetgetInclusivePrefixes(Element target, boolean excludeVisible) Get the canonicalization method.Get the name of the signature algorithm that is being used.Returns the SignatureElement.byte[]Returns the computed Signature value.booleanGet the single cert flag.voidprepare(Document doc, Crypto cr, WSSecHeader secHeader) Initialize a WSSec Signature.voidprependBSTElementToHeader(WSSecHeader secHeader) Prepend the BinarySecurityToken to the elements already in the Security header.voidprependToHeader(WSSecHeader secHeader) Prepends the Signature element to the elements already in the Security header.voidsetSigCanonicalization(String algo) Set the canonicalization method to use.voidsetSignatureAlgorithm(String algo) Set the name of the signature encryption algorithm to use.voidsetUsernameToken(WSSecUsernameToken usernameToken) voidsetUseSingleCertificate(boolean useSingleCert) set the single cert flag.Methods inherited from class WSSecBase
getKeyIdentifierType, setBodyID, setKeyIdentifierType, setParts, setUserInfo, setWsConfig, setWsuId
-
Field Details
-
useSingleCert
protected boolean useSingleCert -
sigAlgo
-
canonAlgo
-
usernameToken
-
signatureValue
protected byte[] signatureValue -
document
-
wsDocInfo
-
certUri
-
sig
protected org.apache.xml.security.signature.XMLSignature sig -
keyInfo
protected org.apache.xml.security.keys.KeyInfo keyInfo -
keyInfoUri
-
secRef
-
strUri
-
bstToken
-
-
Constructor Details
-
WSSecSignature
public WSSecSignature()Constructor.
-
-
Method Details
-
setUseSingleCertificate
public void setUseSingleCertificate(boolean useSingleCert) set the single cert flag.- Parameters:
useSingleCert-
-
isUseSingleCertificate
public boolean isUseSingleCertificate()Get the single cert flag.- Returns:
- A blolean if single vertificate is set.
-
setSignatureAlgorithm
Set the name of the signature encryption algorithm to use. If the algorithm is not set then an automatic detection of the signature algorithm to use is perfomed during theprepare()method. Refer to WSConstants which algorithms are supported.- Parameters:
algo- Is the name of the signature algorithm- See Also:
-
getSignatureAlgorithm
Get the name of the signature algorithm that is being used. Call this method afterprepareto get the information which signature algorithem was automaticall detected if no signature algorithm was preset.- Returns:
- the identifier URI of the signature algorithm
-
setSigCanonicalization
Set the canonicalization method to use. If the canonicalization method is not set then the recommended Exclusive XML Canonicalization is used by default Refer to WSConstants which algorithms are supported.- Parameters:
algo- Is the name of the signature algorithm- See Also:
-
getSigCanonicalization
Get the canonicalization method. If the canonicalization method was not set then Exclusive XML Canonicalization is used by default.- Returns:
- The string describing the canonicalization algorithm.
-
setUsernameToken
- Parameters:
usernameToken- The usernameToken to set.
-
getSignatureValue
public byte[] getSignatureValue()Returns the computed Signature value. Call this method aftercomputeSignature()orbuild()methods were called.- Returns:
- Returns the signatureValue.
-
getId
Get the id generated duringprepare(). Returns the the value of wsu:Id attribute of the Signature element.- Returns:
- Return the wsu:Id of this token or null if
prepare()was not called before.
-
getBSTTokenId
Get the id of the BSt generated duringprepare().- Returns:
- Returns the the value of wsu:Id attribute of the BinaruSecurityToken element.
-
prepare
Initialize a WSSec Signature. The method sets up and initializes a WSSec Signature structure after the relevant information was set. After setup of the references to elements to sign may be added. After all references are added they can be signed. This method does not add the Signature element to the security header. SeeprependSignatureElementToHeader()method.- Parameters:
doc- The SOAP envelope asDocumentcr- An instance of the Crypto API to handle keystore and certificatessecHeader- The security header that will hold the Signature. This ise use to construct namespace prefixes for Signature. This method- Throws:
WSSecurityException
-
addReferencesToSign
public void addReferencesToSign(Vector references, WSSecHeader secHeader) throws WSSecurityException This method adds references to the Signature. The added references are signed when callingcomputeSignature(). This method can be called several times to add references as required.addReferencesToSign()can be called anytime afterprepare.- Parameters:
references- A vector containingWSEncryptionPartobjects that define the parts to sign.secHeader- Used to compute namespaces to be inserted by InclusiveNamespaces to be WSI compliant.- Throws:
WSSecurityException
-
prependToHeader
Prepends the Signature element to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the Signature element at any position in the Security header.- Parameters:
securityHeader- The secHeader that holds the Signature element.
-
appendToHeader
Appends the Signature element to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the Signature element at any position in the Security header.- Parameters:
securityHeader- The secHeader that holds the Signature element.
-
prependBSTElementToHeader
Prepend the BinarySecurityToken to the elements already in the Security header. The method can be called any time afterprepare(). This allows to insert the BST element at any position in the Security header.- Parameters:
secHeader- The security header that holds the BST element.
-
getSignatureElement
Returns the SignatureElement. The method can be called any time afterprepare().- Returns:
- The DOM Element of the signature.
-
getBinarySecurityTokenElement
Returns the BST Token element. The method can be called any time afterprepare().- Returns:
-
appendBSTElementToHeader
-
computeSignature
Compute the Signature over the references. After references are set this method computes the Signature for them. This method can be called anytime after the references were set. SeeaddReferencesToSign().- Throws:
WSSecurityException
-
build
Builds a signed soap envelope. This is a convenience method and for backward compatibility. The method creates a Signature and puts it into the Security header. It does so by calling the single functions in order to perform a one shot signature. This method is compatible with the build method of the previous version with the exception of the additional WSSecHeader parameter.- Parameters:
doc- The unsigned SOAP envelope asDocumentcr- An instance of the Crypto API to handle keystore and certificatessecHeader- the security header element to hold the encrypted key element.- Returns:
- A signed SOAP envelope as
Document - Throws:
WSSecurityException
-
createSTRParameter
-
getInclusivePrefixes
-
getInclusivePrefixes
-