Package org.apache.wss4j.dom.message
Class WSSecSignature
java.lang.Object
org.apache.wss4j.dom.message.WSSecBase
org.apache.wss4j.dom.message.WSSecSignatureBase
org.apache.wss4j.dom.message.WSSecSignature
- Direct Known Subclasses:
WSSecSignatureSAML
Creates a Signature according to WS Specification, X509 profile.
This class is a re-factored implementation of the previous WSS4J class
WSSignEnvelope. 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.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Elementprotected CanonicalizationMethodprotected Stringprotected KeyInfoprotected Stringprotected byte[]protected XMLSignatureprotected XMLSignatureFactoryprotected byte[]protected StringFields inherited from class org.apache.wss4j.dom.message.WSSecBase
addWSUNamespace, attachmentCallbackHandler, callbackLookup, expandXopInclude, keyIdentifierType, password, storeBytesInAttachment, user -
Constructor Summary
ConstructorsConstructorDescriptionWSSecSignature(WSSecHeader securityHeader) WSSecSignature(WSSecHeader securityHeader, Provider provider) WSSecSignature(Document doc) WSSecSignature(Document doc, Provider provider) -
Method Summary
Modifier and TypeMethodDescriptionaddReferencesToSign(List<WSEncryptionPart> references) This method adds references to the Signature.voidAppend the BinarySecurityToken to the security header.Builds a signed soap envelope.voidcomputeSignature(List<Reference> referenceList) Compute the Signature over the references.voidcomputeSignature(List<Reference> referenceList, boolean prepend, Element siblingElement) Compute the Signature over the references.Returns the BST Token element.Get the id of the BST generated duringprepare().getId()Get the id generated duringprepare().Get the SecurityTokenReference to be used in the KeyInfo element.Get the canonicalization method.Get the name (uri) of the signature algorithm that is being used.Returns the SignatureElement.byte[]Returns the computed Signature value.booleanbooleanbooleanGet the single cert flag.protected voidmarshalKeyInfo(WSDocInfo wsDocInfo) voidInitialize a WSSec Signature.voidPrepend the BinarySecurityToken to the elements already in the Security header.voidsetAddInclusivePrefixes(boolean addInclusivePrefixes) voidsetCustomKeyInfoElement(Element keyInfoElement) voidsetCustomTokenId(String customTokenId) Set the custom token idvoidsetCustomTokenValueType(String customTokenValueType) Set the custom token value type to usevoidsetDigestAlgo(String digestAlgo) Set the string that defines which digest algorithm to use.voidsetEncrKeySha1value(String encrKeySha1value) Set the encrypted key sha1 valuevoidsetIncludeSignatureToken(boolean includeSignatureToken) voidsetSecretKey(byte[] secretKey) Set the secret key to usevoidSet the SecurityTokenReference to be used in the KeyInfo element.voidsetSigCanonicalization(String algo) Set the canonicalization method to use.voidsetSignatureAlgorithm(String algo) Set the name (uri) of the signature encryption algorithm to use.voidsetSignatureProvider(Provider signatureProvider) voidsetUseSingleCertificate(boolean useSingleCert) Set the single cert flag.voidSet the X509 Certificate to useMethods inherited from class org.apache.wss4j.dom.message.WSSecSignatureBase
addReferencesToSign, cleanup, createSTRParameter, getInclusivePrefixes, getInclusivePrefixesMethods inherited from class org.apache.wss4j.dom.message.WSSecBase
clean, getDocument, getIdAllocator, getKeyIdentifierType, getParts, getSecurityHeader, getWsDocInfo, isExpandXopInclude, setAttachmentCallbackHandler, setBodyID, setCallbackLookup, setExpandXopInclude, setIdAllocator, setKeyIdentifierType, setStoreBytesInAttachment, setUserInfo, setWsDocInfo, setWsuId
-
Field Details
-
signatureFactory
-
keyInfo
-
c14nMethod
-
sig
-
secretKey
protected byte[] secretKey -
strUri
-
bstToken
-
keyInfoUri
-
certUri
-
signatureValue
protected byte[] signatureValue
-
-
Constructor Details
-
WSSecSignature
-
WSSecSignature
-
WSSecSignature
-
WSSecSignature
-
-
Method Details
-
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:
cr- An instance of the Crypto API to handle keystore and certificates- Throws:
WSSecurityException
-
marshalKeyInfo
- 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.- Parameters:
cr- An instance of the Crypto API to handle keystore and certificates- Returns:
- A signed SOAP envelope as
Document - Throws:
WSSecurityException
-
addReferencesToSign
public List<Reference> addReferencesToSign(List<WSEncryptionPart> references) throws WSSecurityException This method adds references to the Signature.- Parameters:
references- The list of references to sign- Throws:
WSSecurityException
-
getSignatureElement
Returns the SignatureElement. The method can be called any time afterprepare().- Returns:
- The DOM Element of the signature.
-
prependBSTElementToHeader
public void 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. -
appendBSTElementToHeader
public void appendBSTElementToHeader()Append the BinarySecurityToken to the security header. -
computeSignature
Compute the Signature over the references. The signature element will be prepended to the security header. This method can be called any time after the references were set. SeeaddReferencesToSign().- Parameters:
referenceList- The list of references to sign- Throws:
WSSecurityException
-
computeSignature
public void computeSignature(List<Reference> referenceList, boolean prepend, Element siblingElement) throws WSSecurityException Compute the Signature over the references. This method can be called any time after the references were set. SeeaddReferencesToSign().- Parameters:
referenceList- The list of references to signprepend- Whether to prepend the signature element to the security headersiblingElement- If prepending, then prepend before this sibling Element- Throws:
WSSecurityException
-
setUseSingleCertificate
public void setUseSingleCertificate(boolean useSingleCert) Set the single cert flag.- Parameters:
useSingleCert-
-
isUseSingleCertificate
public boolean isUseSingleCertificate()Get the single cert flag.- Returns:
- A boolean if single certificate is set.
-
setSignatureAlgorithm
Set the name (uri) of the signature encryption algorithm to use. If the algorithm is not set then an automatic detection of the signature algorithm to use is performed during theprepare()method. Refer to WSConstants which algorithms are supported.- Parameters:
algo- the name of the signature algorithm- See Also:
-
getSignatureAlgorithm
Get the name (uri) of the signature algorithm that is being used. Call this method afterprepareto get the information which signature algorithm was automatically 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.
-
getDigestAlgo
- Returns:
- the digest algorithm to use
-
setDigestAlgo
Set the string that defines which digest algorithm to use. The default is WSConstants.SHA1.- Parameters:
digestAlgo- the digestAlgo 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.
-
setSecretKey
public void setSecretKey(byte[] secretKey) Set the secret key to use- Parameters:
secretKey- the secret key to use
-
setCustomTokenValueType
Set the custom token value type to use- Parameters:
customTokenValueType- the custom token value type to use
-
setCustomTokenId
Set the custom token id- Parameters:
customTokenId- the custom token id
-
getCustomTokenId
-
setEncrKeySha1value
Set the encrypted key sha1 value- Parameters:
encrKeySha1value- the encrypted key sha1 value
-
setX509Certificate
Set the X509 Certificate to use- Parameters:
cer- the X509 Certificate to use
-
getBinarySecurityTokenElement
Returns the BST Token element. The method can be called any time afterprepare().- Returns:
- the BST Token element
-
getSecurityTokenReferenceURI
- Returns:
- the URI associated with the SecurityTokenReference
(must be called after
#prepare(Document, Crypto)
-
getSecurityTokenReference
Get the SecurityTokenReference to be used in the KeyInfo element. -
setSecurityTokenReference
Set the SecurityTokenReference to be used in the KeyInfo element. If this method is not called, a SecurityTokenRefence will be generated. -
isIncludeSignatureToken
public boolean isIncludeSignatureToken() -
setIncludeSignatureToken
public void setIncludeSignatureToken(boolean includeSignatureToken) -
isAddInclusivePrefixes
public boolean isAddInclusivePrefixes() -
setAddInclusivePrefixes
public void setAddInclusivePrefixes(boolean addInclusivePrefixes) -
setCustomKeyInfoElement
-
getCustomKeyInfoElement
-
getSignatureProvider
-
setSignatureProvider
-
getKeyInfoUri
-