Package org.apache.rampart.util
Class RampartUtil
java.lang.Object
org.apache.rampart.util.RampartUtil
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic org.apache.neethi.PolicyaddRampartConfig(RampartMessageData rmd, org.apache.neethi.Policy policy) static StringaddWsuIdToElement(org.apache.axiom.om.OMElement elem) static NodeChange the owner document of the given node.static ElementappendChildToSecHeader(RampartMessageData rmd, org.apache.axiom.om.OMElement elem) static ElementappendChildToSecHeader(RampartMessageData rmd, Element elem) static booleancheckRequiredElements(org.apache.axiom.soap.SOAPEnvelope envelope, HashMap decNamespaces, String expression) Get a element for SOAPstatic org.apache.wss4j.common.WSEncryptionPartcreateEncryptionPart(String name, String id) Creates an Encryption or Signature paert with given name and id.static org.apache.wss4j.common.WSEncryptionPartcreateEncryptionPart(String name, String id, String namespace, String modifier) Creates an encryption part.static org.apache.wss4j.common.WSEncryptionPartCreates an encryption part.static org.apache.axiom.om.OMElementcreateRSTTempalteForSCT(int conversationVersion, int wstVersion) static booleanReturns true if needed to encrypt first.static SetfindAllPrefixNamespaces(org.apache.axiom.om.OMElement currentElement, HashMap decNamespacess) static List<org.apache.wss4j.common.WSEncryptionPart>getContentEncryptedElements(List<org.apache.wss4j.common.WSEncryptionPart> encryptedPartsElements, org.apache.axiom.soap.SOAPEnvelope envelope, List<String> elements, HashMap decNamespaces) static StringgetContextIdentifierKey(org.apache.axis2.context.MessageContext msgContext) Creates the unique (reproducible) id for to hold the context identifier of the message exchange.static HashtablegetContextMap(org.apache.axis2.context.MessageContext msgContext) Returns the map of security context token identifiersstatic List<org.apache.wss4j.common.WSEncryptionPart>static org.apache.wss4j.common.crypto.CryptogetEncryptionCrypto(RampartConfig config, ClassLoader loader) Create theCryptoinstance for encryption using information from the rampart configuration assertionstatic KeyGeneratorgetEncryptionKeyGenerator(String symEncrAlgo) static StringgetIssuedToken(RampartMessageData rmd, IssuedToken issuedToken) Obtain an issued token.static org.apache.wss4j.common.kerberos.KerberosTokenDecodergetKerberosTokenDecoder(org.apache.axis2.context.MessageContext msgContext, KerberosConfig kerberosConfig) Instantiates any Kerberos token decoder implementation configured viaKerberosConfig.setKerberosTokenDecoderClass(String)using theclass loaderof the specified message context'sservice.static intgetKeyIdentifier(X509Token token) figure out the key identifier of a give X509Tokenstatic List<org.apache.wss4j.common.WSEncryptionPart>getPartsAndElements(boolean sign, org.apache.axiom.soap.SOAPEnvelope envelope, boolean includeBody, List<org.apache.wss4j.common.WSEncryptionPart> parts, List<String> elements, HashMap decNamespaces) static CallbackHandlergetPasswordCB(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) static CallbackHandlerstatic org.apache.neethi.PolicygetPolicyFromMetadataRef(org.apache.axiom.om.OMElement mex) Retrieve policy using metadata referencegetPolicyValidatorCB(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) Returns an instance of PolicyValidatorCallbackHandler to be used to validate ws-security results.static RampartConfigCallbackHandlergetRampartConfigCallbackHandler(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) static StringgetRequestEncryptedKeyId(List<org.apache.wss4j.dom.handler.WSHandlerResult> results) static byte[]getRequestEncryptedKeyValue(List<org.apache.wss4j.dom.handler.WSHandlerResult> results) static StringReturns SAML10 Assertion namespace.static StringgetSecConvToken(RampartMessageData rmd, SecureConversationToken secConvTok) Obtain a security context token.static Stringstatic org.apache.wss4j.common.crypto.CryptogetSignatureCrypto(RampartConfig config, ClassLoader loader) Create theCryptoinstance for signature using information from the rampart configuration assertionstatic List<org.apache.wss4j.common.WSEncryptionPart>static StringgetSoapBodyId(org.apache.axiom.soap.SOAPEnvelope env) static List<org.apache.wss4j.common.WSEncryptionPart>static List<org.apache.wss4j.common.WSEncryptionPart>static intgetTimestampMaxSkew(RampartMessageData messageData) static intgetTimeToLive(RampartMessageData messageData) static StringgetToken(RampartMessageData rmd, org.apache.axiom.om.OMElement rstTemplate, String issuerEpr, String action, org.apache.neethi.Policy issuerPolicy) Request a token.static StringgetUsername(List<org.apache.wss4j.dom.handler.WSHandlerResult> results) Scan throughWSHandlerResultlist for a Username token and return the username if a Username Token foundstatic Collection<UsernameToken>static Collection<UsernameToken>getUsernameTokens(SupportingToken suppTok) static voidhandleEncryptedSignedHeaders(List<org.apache.wss4j.common.WSEncryptionPart> encryptedParts, List<org.apache.wss4j.common.WSEncryptionPart> signedParts, Document doc) static ElementinsertSiblingAfter(RampartMessageData rmd, Element child, Element sibling) static ElementinsertSiblingAfterOrPrepend(RampartMessageData rmd, Element child, Element elem) If the child is present insert the element as a sibling after him.static ElementinsertSiblingBefore(RampartMessageData rmd, Element child, Element sibling) static ElementinsertSiblingBeforeOrPrepend(RampartMessageData rmd, Element child, Element elem) static booleanisSecHeaderRequired(RampartPolicyData rpd, boolean initiator, boolean inflow) Method to check whether security header is required in incoming messagestatic booleanisSecurityFault(org.apache.axiom.soap.SOAPFault fault) Check if the given SOAP fault reports a security fault.static booleanisTokenValid(RampartMessageData rmd, String id) static org.apache.wss4j.common.ext.WSPasswordCallbackperformCallback(CallbackHandler cbHandler, String username, int doAction) Perform a callback to get a password.static StringprocessIssuerAddress(org.apache.axiom.om.OMElement issuerAddress) Process a give issuer address element and return the address.static voidsetDecryptionCrypto(org.apache.axis2.context.MessageContext msgContext) Sets decryption crypto file or crypto reference key to signature crypto file or signature crypto reference.static voidsetEncryptionCrypto(org.apache.axis2.context.MessageContext msgContext) Sets encryption crypto file or crypto reference key to signature crypto file or signature crypto reference.static voidsetEncryptionUser(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecEncryptedKey encrKeyBuilder) static voidsetEncryptionUser(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecEncryptedKey encrKeyBuilder, String encrUser) static voidsetKeyIdentifierType(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecBase secBase, Token token) Sets the keyIdentifierType ofWSSecSignatureorWSSecEncryptedKeyaccording to the givenTokenandRampartPolicyDataFirst check the requirements specified under Token Assertion and if not found check the WSS11 and WSS10 assertionsstatic voidvalidateTransport(RampartMessageData messageData) Validate transport binding policy assertions.
-
Constructor Details
-
RampartUtil
public RampartUtil()
-
-
Method Details
-
getPasswordCB
- Throws:
RampartException
-
getPasswordCB
public static CallbackHandler getPasswordCB(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) throws RampartException - Parameters:
msgContext- Axis2 MessageContextrpd- RampartPolicyData- Returns:
- The
CallbackHandlerinstance - Throws:
RampartException- If an error occurred getting the CallbackHandler Object
-
getKerberosTokenDecoder
public static org.apache.wss4j.common.kerberos.KerberosTokenDecoder getKerberosTokenDecoder(org.apache.axis2.context.MessageContext msgContext, KerberosConfig kerberosConfig) throws RampartException Instantiates any Kerberos token decoder implementation configured viaKerberosConfig.setKerberosTokenDecoderClass(String)using theclass loaderof the specified message context'sservice.- Parameters:
msgContext- The current message context. Must not be null and must contain a valid service instance.kerberosConfig- Rampart's Kerberos configuration.- Returns:
- A new instance of
KerberosTokenDecoderimplementation configured viaKerberosConfig.setKerberosTokenDecoderClass(String)ornullif no Kerberos token decoder is configured. - Throws:
RampartException- If the class cannot be loaded or instantiated.
-
getPolicyValidatorCB
public static PolicyValidatorCallbackHandler getPolicyValidatorCB(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) throws RampartException Returns an instance of PolicyValidatorCallbackHandler to be used to validate ws-security results.- Parameters:
msgContext-MessageContextrpd-RampartPolicyData- Returns:
PolicyValidatorCallbackHandler- Throws:
RampartException- RampartException
-
getRampartConfigCallbackHandler
public static RampartConfigCallbackHandler getRampartConfigCallbackHandler(org.apache.axis2.context.MessageContext msgContext, RampartPolicyData rpd) throws RampartException - Throws:
RampartException
-
performCallback
public static org.apache.wss4j.common.ext.WSPasswordCallback performCallback(CallbackHandler cbHandler, String username, int doAction) throws RampartException Perform a callback to get a password.The called back function gets an indication why to provide a password: to produce a UsernameToken, Signature, or a password (key) for a given name.
- Parameters:
cbHandler- CallbackHandlerusername- userdoAction- action- Returns:
- WSPasswordCallback value of Callback
- Throws:
RampartException- If an error occurred getting the CallbackHandler Object
-
getEncryptionCrypto
public static org.apache.wss4j.common.crypto.Crypto getEncryptionCrypto(RampartConfig config, ClassLoader loader) throws RampartException Create theCryptoinstance for encryption using information from the rampart configuration assertion- Parameters:
config- Rampart Configurationloader- ClassLoader to perform operations- Returns:
- The
Cryptoinstance to be used for encryption - Throws:
RampartException- If the arguments are malformed.
-
getSignatureCrypto
public static org.apache.wss4j.common.crypto.Crypto getSignatureCrypto(RampartConfig config, ClassLoader loader) throws RampartException Create theCryptoinstance for signature using information from the rampart configuration assertion- Parameters:
config- Rampart Configurationloader- ClassLoader to perform operations- Returns:
- The Crypto instance to be used for signature
- Throws:
RampartException- If an error occurred getting the Crypto Object
-
getKeyIdentifier
figure out the key identifier of a give X509Token- Parameters:
token- X509 token- Returns:
- The key identifier of a give X509Token
- Throws:
RampartException- If an error occurred getting the key identifier
-
processIssuerAddress
public static String processIssuerAddress(org.apache.axiom.om.OMElement issuerAddress) throws RampartException Process a give issuer address element and return the address.- Parameters:
issuerAddress- address- Returns:
- The address of an issuer address element
- Throws:
RampartException- If the issuer address element is malformed.
-
getPolicyFromMetadataRef
public static org.apache.neethi.Policy getPolicyFromMetadataRef(org.apache.axiom.om.OMElement mex) throws RampartException Retrieve policy using metadata reference<wsa:Metadata xmlns:wsa="http://www.w3.org/2005/08/addressing"> <mex:Metadata xmlns:mex="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <mex:MetadataSection> <mex:MetadataReference> <wsa:Address>http://address/of/mex/service</wsa:Address> </mex:MetadataReference> </mex:MetadataSection> </mex:Metadata> </wsa:Metadata>- Parameters:
mex- Metadata element- Returns:
- Policy from the mex service
- Throws:
RampartException- If the element is malformed.
-
addRampartConfig
public static org.apache.neethi.Policy addRampartConfig(RampartMessageData rmd, org.apache.neethi.Policy policy) -
createRSTTempalteForSCT
public static org.apache.axiom.om.OMElement createRSTTempalteForSCT(int conversationVersion, int wstVersion) throws RampartException - Throws:
RampartException
-
getTimeToLive
-
getTimestampMaxSkew
-
getSecConvToken
public static String getSecConvToken(RampartMessageData rmd, SecureConversationToken secConvTok) throws TrustException, RampartException Obtain a security context token.- Parameters:
rmd- RampartMessageDatasecConvTok- context token- Returns:
- Return the SecurityContextidentifier of the token
- Throws:
TrustException- If TrustUtil failsRampartException- If the arguments are malformed.
-
getIssuedToken
public static String getIssuedToken(RampartMessageData rmd, IssuedToken issuedToken) throws RampartException Obtain an issued token.- Parameters:
rmd- RampartMessageDataissuedToken- issued token- Returns:
- String The identifier of the issued token
- Throws:
RampartException- If the arguments are malformed.
-
getToken
public static String getToken(RampartMessageData rmd, org.apache.axiom.om.OMElement rstTemplate, String issuerEpr, String action, org.apache.neethi.Policy issuerPolicy) throws RampartException Request a token.- Parameters:
rmd- RampartMessageDatarstTemplate- templateissuerEpr- expirationaction- what to findissuerPolicy- policy- Returns:
- Return the identifier of the obtained token
- Throws:
RampartException- If the arguments are malformed.
-
getSoapBodyId
-
addWsuIdToElement
-
adoptNode
Change the owner document of the given node. The method first attempts to move the node usingDocument.adoptNode(Node). If that fails, it will import the node into the target document usingDocument.importNode(Node, boolean).- Parameters:
targetDocument- the target documentnode- the node to adopt or import- Returns:
- the adopted or imported node
-
appendChildToSecHeader
public static Element appendChildToSecHeader(RampartMessageData rmd, org.apache.axiom.om.OMElement elem) -
appendChildToSecHeader
-
insertSiblingAfter
-
insertSiblingBefore
-
getEncryptedParts
public static List<org.apache.wss4j.common.WSEncryptionPart> getEncryptedParts(RampartMessageData rmd) -
getSignedParts
-
getSupportingEncryptedParts
public static List<org.apache.wss4j.common.WSEncryptionPart> getSupportingEncryptedParts(RampartMessageData rmd, SupportingPolicyData rpd) -
getSupportingSignedParts
public static List<org.apache.wss4j.common.WSEncryptionPart> getSupportingSignedParts(RampartMessageData rmd, SupportingPolicyData rpd) -
findAllPrefixNamespaces
-
getContentEncryptedElements
-
createEncryptionPart
Creates an Encryption or Signature paert with given name and id. Name must not be null.- Parameters:
name- The name of the partid- The id of the part.- Returns:
- WSEncryptionPart.
-
createEncryptionPart
public static org.apache.wss4j.common.WSEncryptionPart createEncryptionPart(String name, String id, String namespace, String modifier) Creates an encryption part. Could be a part or could be an element pointed through xpath expression.- Parameters:
name- Name of the element.id- The id of the elementnamespace- Namespace of the element.modifier- Modifier "Content" or "Element"- Returns:
- A WSEncryptionPart
-
createEncryptionPart
public static org.apache.wss4j.common.WSEncryptionPart createEncryptionPart(String name, String id, String namespace, String modifier, String xPath) Creates an encryption part. Could be a part or could be an element pointed through xpath expression.- Parameters:
name- Name of the element.id- The id of the elementnamespace- Namespace of the element.modifier- Modifier "Content" or "Element"xPath- The xPath expression- Returns:
- A WSEncryptionPart
-
getPartsAndElements
-
checkRequiredElements
public static boolean checkRequiredElements(org.apache.axiom.soap.SOAPEnvelope envelope, HashMap decNamespaces, String expression) Get a element for SOAP- Parameters:
envelope- SOAP Envelope of which we should check required elementsdecNamespaces- Declared namespaces in RequiredElements assertionexpression- XPATH expression of required elements- Returns:
- boolean State of required elements
-
getEncryptionKeyGenerator
public static KeyGenerator getEncryptionKeyGenerator(String symEncrAlgo) throws org.apache.wss4j.common.ext.WSSecurityException - Throws:
org.apache.wss4j.common.ext.WSSecurityException
-
getContextIdentifierKey
Creates the unique (reproducible) id for to hold the context identifier of the message exchange.- Parameters:
msgContext- Axis2 message state- Returns:
- Id to hold the context identifier in the message context
-
getContextMap
Returns the map of security context token identifiers- Parameters:
msgContext- The message context.- Returns:
- Hashtable the map of security context token identifiers
-
isTokenValid
- Throws:
RampartException
-
setEncryptionUser
public static void setEncryptionUser(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecEncryptedKey encrKeyBuilder) throws RampartException - Throws:
RampartException
-
setEncryptionUser
public static void setEncryptionUser(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecEncryptedKey encrKeyBuilder, String encrUser) throws RampartException - Throws:
RampartException
-
setKeyIdentifierType
public static void setKeyIdentifierType(RampartMessageData rmd, org.apache.wss4j.dom.message.WSSecBase secBase, Token token) Sets the keyIdentifierType ofWSSecSignatureorWSSecEncryptedKeyaccording to the givenTokenandRampartPolicyDataFirst check the requirements specified under Token Assertion and if not found check the WSS11 and WSS10 assertions- Parameters:
rmd- RampartMessageDatasecBase- ws-wss4j Objecttoken- Rampart token
-
getUsername
Scan throughWSHandlerResultlist for a Username token and return the username if a Username Token found- Parameters:
results- ws-wss4j Object- Returns:
- String username
-
getRequestEncryptedKeyId
-
getRequestEncryptedKeyValue
public static byte[] getRequestEncryptedKeyValue(List<org.apache.wss4j.dom.handler.WSHandlerResult> results) -
insertSiblingAfterOrPrepend
public static Element insertSiblingAfterOrPrepend(RampartMessageData rmd, Element child, Element elem) If the child is present insert the element as a sibling after him. If the child is null, then prepend the element.- Parameters:
rmd- RampartMessageDatachild- Elementelem- - element mentioned above- Returns:
- Element new Element
-
insertSiblingBeforeOrPrepend
public static Element insertSiblingBeforeOrPrepend(RampartMessageData rmd, Element child, Element elem) -
isSecHeaderRequired
Method to check whether security header is required in incoming message- Parameters:
rpd- RampartPolicyDatainitiator- defines precendenceinflow- defines precendence- Returns:
- boolean true if a security header is required in the incoming message
-
handleEncryptedSignedHeaders
-
getSigElementId
-
validateTransport
Validate transport binding policy assertions. In case an HttpsToken is required by the security policy the method will verify that the HTTPS transport was used indeed. Furthermore if the assertion requires a client certificate being used, the method will try to obtain the client certificate chain first from the message context properties directly under the keyRampartConstants.HTTPS_CLIENT_CERT_KEYand, if the property is not available, will try to get the HttpsServletRequest from the message context properties (populated there by the AxisServlet if axis2 is running inside a servlet engine) and retrieve the https client certificate chain from its attributes. The client certificate chain is expected to be available under thejavax.servlet.request.X509Certificateattribute of the servlet request. No further trust verification is done for the client certificate - the transport listener should have already verified this.- Parameters:
messageData-- Throws:
RampartException
-
getSAML10AssertionNamespace
Returns SAML10 Assertion namespace. As follows, http://docs.oasis-open.org/wss/oasis-wss-saml-token-profile-1.0#SAMLAssertionID- Returns:
- SAML10 assertion namespace.
-
setEncryptionCrypto
public static void setEncryptionCrypto(org.apache.axis2.context.MessageContext msgContext) Sets encryption crypto file or crypto reference key to signature crypto file or signature crypto reference.- Parameters:
msgContext- The message context to get signature crypto properties and encryption properties will be set to same message context.
-
setDecryptionCrypto
public static void setDecryptionCrypto(org.apache.axis2.context.MessageContext msgContext) Sets decryption crypto file or crypto reference key to signature crypto file or signature crypto reference.- Parameters:
msgContext- The message context to get signature crypto properties and decryption properties will be set to same message context.
-
encryptFirst
Returns true if needed to encrypt first.- Parameters:
rpd- Rampart policy data- Returns:
- true if policy says we need to encrypt first else false.
-
isSecurityFault
public static boolean isSecurityFault(org.apache.axiom.soap.SOAPFault fault) Check if the given SOAP fault reports a security fault.- Parameters:
fault- the SOAP fault; must not benull- Returns:
- true if the fault is a security fault; false otherwise
-
getUsernameTokens
- Parameters:
rpd- Rampart policy data instance. Must not be null.- Returns:
- A collection of all
UsernameTokensupporting token assertions in the specified Rampart policy instance. The method will check the following lists:RampartPolicyData.getSupportingTokensList()RampartPolicyData.getSignedSupportingTokens()RampartPolicyData.getSignedEndorsingSupportingTokens()RampartPolicyData.getEndorsingSupportingTokens()RampartPolicyData.getEncryptedSupportingTokens()RampartPolicyData.getSignedEncryptedSupportingTokens()RampartPolicyData.getEndorsingEncryptedSupportingTokens()RampartPolicyData.getSignedEndorsingEncryptedSupportingTokens()
-
getUsernameTokens
- Parameters:
suppTok- TheSupportingTokenassertion to check for username tokens.- Returns:
- A collection of all tokens in the specified
suppTokSupportingToken assertion which are instances ofUsernameToken. If the specifiedsuppTokSupportingToken assertion isnull, an empty collection will be returned.
-