public class WSSecurityUtil extends Object
Constructor and Description |
---|
WSSecurityUtil() |
Modifier and Type | Method and Description |
---|---|
static org.w3c.dom.Element |
appendChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element parent,
org.w3c.dom.Element child)
Deprecated.
use
Node.appendChild(Node) instead |
static org.w3c.dom.Text |
createBase64EncodedTextNode(org.w3c.dom.Document doc,
byte[] data)
create a base64 test node
|
static int |
decodeAction(String action,
Vector actions) |
static int |
decodeAction(String action,
Vector actions,
WSSConfig wssConfig)
Decode an action String.
|
static X509Certificate |
ensureSignedTogether(Iterator results,
org.w3c.dom.Element[] elements)
Search through a WSS4J results vector for a single signature covering all
these elements.
|
static WSSecurityEngineResult |
fetchActionResult(Vector wsResultVector,
int action)
Fetch the result of a given action from a given result vector
|
static Vector |
fetchAllActionResults(Vector wsResultVector,
int action,
Vector results)
Fetch the result of a given action from a given result vector
|
static org.w3c.dom.Element |
findBodyElement(org.w3c.dom.Document doc,
SOAPConstants sc)
return the first soap "Body" element.
|
static org.w3c.dom.Node |
findElement(org.w3c.dom.Node startNode,
String name,
String namespace)
Returns the first element that matches
name and
namespace . |
static org.w3c.dom.Element |
findElementById(org.w3c.dom.Node startNode,
String value,
String namespace)
Returns the single element that contains an Id with value
uri and namespace . |
static org.w3c.dom.Element |
findSAMLAssertionElementById(org.w3c.dom.Node startNode,
String value)
Returns the single SAMLAssertion element that contains an AssertionID/ID that
matches the supplied parameter.
|
static org.w3c.dom.Element |
findWsseSecurityHeaderBlock(org.w3c.dom.Document doc,
org.w3c.dom.Element envelope,
boolean doCreate)
find the first ws-security header block
|
static org.w3c.dom.Element |
findWsseSecurityHeaderBlock(org.w3c.dom.Document doc,
org.w3c.dom.Element envelope,
String actor,
boolean doCreate)
find a ws-security header block for a given actor
|
static byte[] |
generateNonce(int length)
Generate a nonce of the given length
|
static javax.crypto.Cipher |
getCipherInstance(String cipherAlgo) |
static org.w3c.dom.Node |
getDirectChild(org.w3c.dom.Node fNode,
String localName,
String namespace)
Gets a direct child with specified localname and namespace.
|
static org.w3c.dom.Element |
getDirectChildElement(org.w3c.dom.Node fNode,
String localName,
String namespace)
Gets a direct child with specified localname and namespace.
|
static org.w3c.dom.Element |
getElementByGenId(org.w3c.dom.Document doc,
String id)
Search for an element given its generic id.
|
static org.w3c.dom.Element |
getElementByWsuId(org.w3c.dom.Document doc,
String id)
Search for an element given its wsu:id.
|
static javax.xml.namespace.QName |
getFullQNameFromString(String str,
org.w3c.dom.Node e)
Return a QName when passed a string like "foo:bar" by mapping the "foo"
prefix to a namespace in the context of the given Node.
|
static String |
getIDfromReference(String ref)
Deprecated.
use getIDFromReference instead
|
static String |
getIDFromReference(String ref)
Turn a reference (eg "#5") into an ID (eg "5").
|
static int |
getKeyLength(String algorithm)
Returns the length of the key in # of bytes
|
static String |
getNamespace(String prefix,
org.w3c.dom.Node e) |
static String |
getPrefixNS(String uri,
org.w3c.dom.Node e) |
static javax.xml.namespace.QName |
getQNameFromString(String str,
org.w3c.dom.Node e)
Return a QName when passed a string like "foo:bar" by mapping the "foo"
prefix to a namespace in the context of the given Node.
|
static org.w3c.dom.Element |
getSecurityHeader(org.w3c.dom.Document doc,
String actor,
SOAPConstants sc)
Returns the first WS-Security header element for a given actor.
|
static SOAPConstants |
getSOAPConstants(org.w3c.dom.Element startElement) |
static String |
getStringForQName(javax.xml.namespace.QName qname,
org.w3c.dom.Element e)
Return a string for a particular QName, mapping a new prefix if
necessary.
|
static boolean |
isActorEqual(String actor,
String hActor)
Compares two actor strings and returns true if these are equal.
|
static javax.crypto.SecretKey |
prepareSecretKey(String symEncAlgo,
byte[] rawKey) |
static org.w3c.dom.Element |
prependChildElement(org.w3c.dom.Document doc,
org.w3c.dom.Element parent,
org.w3c.dom.Element child,
boolean addWhitespace)
Deprecated.
use
prependChildElement(Element, Element)
instead |
static org.w3c.dom.Element |
prependChildElement(org.w3c.dom.Element parent,
org.w3c.dom.Element child)
prepend a child element
|
static SecureRandom |
resolveSecureRandom() |
static SecureRandom |
resolveSecureRandom(String algorithm) |
static String |
setNamespace(org.w3c.dom.Element element,
String namespace,
String prefix)
Set a namespace/prefix on an element if it is not set already.
|
public static org.w3c.dom.Element getSecurityHeader(org.w3c.dom.Document doc, String actor, SOAPConstants sc)
doc
- actor
- wsse:Security
element or null
if not such element foundpublic static boolean isActorEqual(String actor, String hActor)
actor
- hActor
- public static org.w3c.dom.Node getDirectChild(org.w3c.dom.Node fNode, String localName, String namespace)
fNode
- the node where to start the searchlocalName
- local name of the child to getnamespace
- the namespace of the child to getnull
if not such node foundpublic static org.w3c.dom.Element getDirectChildElement(org.w3c.dom.Node fNode, String localName, String namespace)
fNode
- the node where to start the searchlocalName
- local name of the child to getnamespace
- the namespace of the child to getnull
if not such node foundpublic static org.w3c.dom.Element findBodyElement(org.w3c.dom.Document doc, SOAPConstants sc)
doc
- null
if document does not
contain a SOAP bodypublic static org.w3c.dom.Node findElement(org.w3c.dom.Node startNode, String name, String namespace)
name
and
namespace
. This is a replacement for a XPath lookup
//name
with the given namespace. It's somewhat faster than
XPath, and we do not deal with prefixes, just with the real namespace URIstartNode
- Where to start the searchname
- Local name of the elementnamespace
- Namespace URI of the elementnull
public static org.w3c.dom.Element findSAMLAssertionElementById(org.w3c.dom.Node startNode, String value)
startNode
- Where to start the searchvalue
- Value of the AssertionID/ID attributenull
otherwisepublic static org.w3c.dom.Element findElementById(org.w3c.dom.Node startNode, String value, String namespace)
uri
and namespace
. This is a
replacement for a XPath Id lookup with the given namespace. It's somewhat
faster than XPath, and we do not deal with prefixes, just with the real
namespace URI
If there are multiple elements, we log a warning and return null as this
can be used to get around the signature checking.startNode
- Where to start the searchvalue
- Value of the Id attributenamespace
- Namespace URI of the Idnull
otherwisepublic static String setNamespace(org.w3c.dom.Element element, String namespace, String prefix)
element
- namespace
- prefix
- public static javax.xml.namespace.QName getQNameFromString(String str, org.w3c.dom.Node e)
public static javax.xml.namespace.QName getFullQNameFromString(String str, org.w3c.dom.Node e)
public static String getStringForQName(javax.xml.namespace.QName qname, org.w3c.dom.Element e)
public static org.w3c.dom.Element getElementByWsuId(org.w3c.dom.Document doc, String id)
doc
- the DOM document (SOAP request)id
- the Id of the elementpublic static String getIDFromReference(String ref)
ref
- public static String getIDfromReference(String ref)
ref
- public static org.w3c.dom.Element getElementByGenId(org.w3c.dom.Document doc, String id)
doc
- the DOM document (SOAP request)id
- the Id of the elementpublic static org.w3c.dom.Element appendChildElement(org.w3c.dom.Document doc, org.w3c.dom.Element parent, org.w3c.dom.Element child)
Node.appendChild(Node)
insteaddoc
- the DOM document (SOAP request)parent
- element of this child elementchild
- the element to appendpublic static org.w3c.dom.Element prependChildElement(org.w3c.dom.Element parent, org.w3c.dom.Element child)
parent
- element of this child elementchild
- the element to appendpublic static org.w3c.dom.Element prependChildElement(org.w3c.dom.Document doc, org.w3c.dom.Element parent, org.w3c.dom.Element child, boolean addWhitespace)
prependChildElement(Element, Element)
insteaddoc
- the DOM document (SOAP request)parent
- element of this child elementchild
- the element to appendaddWhitespace
- if true prepend a newline before childpublic static org.w3c.dom.Element findWsseSecurityHeaderBlock(org.w3c.dom.Document doc, org.w3c.dom.Element envelope, boolean doCreate)
doc
- the DOM document (SOAP request)envelope
- the SOAP envelopedoCreate
- if true create a new WSS header block if none existspublic static org.w3c.dom.Element findWsseSecurityHeaderBlock(org.w3c.dom.Document doc, org.w3c.dom.Element envelope, String actor, boolean doCreate)
doc
- the DOM document (SOAP request)envelope
- the SOAP envelopeactor
- the actor (role) name of the WSS headerdoCreate
- if true create a new WSS header block if none existspublic static org.w3c.dom.Text createBase64EncodedTextNode(org.w3c.dom.Document doc, byte[] data)
doc
- the DOM document (SOAP request)data
- to encodepublic static javax.crypto.SecretKey prepareSecretKey(String symEncAlgo, byte[] rawKey)
public static SOAPConstants getSOAPConstants(org.w3c.dom.Element startElement)
public static javax.crypto.Cipher getCipherInstance(String cipherAlgo) throws WSSecurityException
WSSecurityException
public static WSSecurityEngineResult fetchActionResult(Vector wsResultVector, int action)
wsResultVector
- The result vector to fetch an action fromaction
- The action to fetchpublic static Vector fetchAllActionResults(Vector wsResultVector, int action, Vector results)
wsResultVector
- The result vector to fetch an action fromaction
- The action to fetchresults
- where to store the found results data for the actionpublic static int decodeAction(String action, Vector actions) throws WSSecurityException
WSSecurityException
public static int decodeAction(String action, Vector actions, WSSConfig wssConfig) throws WSSecurityException
action
- The initial String of actions to performactions
- The vector of created actions that will be performedwssConfig
- This object holds the list of custom actions to be performed.WSSecurityException
public static int getKeyLength(String algorithm) throws WSSecurityException
algorithm
- WSSecurityException
public static byte[] generateNonce(int length) throws WSSecurityException
Exception
WSSecurityException
public static X509Certificate ensureSignedTogether(Iterator results, org.w3c.dom.Element[] elements) throws WSSecurityException
results
- results (e.g., as stored as WSHandlerConstants.RECV_RESULTS on
an Axis MessageContext)elements
- the elements to checkWSSecurityException
- if no suitable signature could be found or if any element
didn't have a wsu:Id attributepublic static SecureRandom resolveSecureRandom() throws NoSuchAlgorithmException
NoSuchAlgorithmException
public static SecureRandom resolveSecureRandom(String algorithm) throws NoSuchAlgorithmException
algorithm
- NoSuchAlgorithmException
Copyright © 2004-2012 The Apache Software Foundation. All Rights Reserved.