|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.ws.security.util.WSSecurityUtil
public class WSSecurityUtil
WS-Security Utility methods.
Constructor Summary | |
---|---|
WSSecurityUtil()
|
Method Summary | |
---|---|
static void |
checkAllElementsProtected(java.util.List<WSSecurityEngineResult> results,
int action,
javax.xml.namespace.QName[] requiredParts)
Check that all of the QName[] requiredParts are protected by a specified action in the results list. |
static void |
checkSignsAllElements(WSSecurityEngineResult resultItem,
java.lang.String[] requiredIDs)
Ensure that this covers all required elements (identified by their wsu:Id attributes). |
static org.w3c.dom.Text |
createBase64EncodedTextNode(org.w3c.dom.Document doc,
byte[] data)
create a base64 test node |
static int |
decodeAction(java.lang.String action,
java.util.List<java.lang.Integer> actions)
|
static int |
decodeAction(java.lang.String action,
java.util.List<java.lang.Integer> actions,
WSSConfig wssConfig)
Decode an action String. |
static WSSecurityEngineResult |
fetchActionResult(java.util.List<WSSecurityEngineResult> resultList,
int action)
Fetch the result of a given action from a given result list |
static java.util.List<WSSecurityEngineResult> |
fetchAllActionResults(java.util.List<WSSecurityEngineResult> resultList,
int action,
java.util.List<WSSecurityEngineResult> actionResultList)
Fetch the result of a given action from a given result list. |
static org.w3c.dom.Element |
findBodyElement(org.w3c.dom.Document doc)
return the first soap "Body" element. |
static org.w3c.dom.Element |
findElement(org.w3c.dom.Node startNode,
java.lang.String name,
java.lang.String namespace)
Returns the first element that matches name and
namespace . |
static org.w3c.dom.Element |
findElementById(org.w3c.dom.Node startNode,
java.lang.String value,
boolean checkMultipleElements)
Returns the single element that contains an Id with value uri and namespace . |
static java.util.List<org.w3c.dom.Element> |
findElements(org.w3c.dom.Node startNode,
java.lang.String name,
java.lang.String namespace)
Returns all elements that match name and namespace . |
static java.util.List<org.w3c.dom.Element> |
findElements(WSEncryptionPart part,
CallbackLookup callbackLookup,
org.w3c.dom.Document doc)
Find the DOM Element in the SOAP Envelope that is referenced by the WSEncryptionPart argument. |
static org.w3c.dom.Element |
findSAMLAssertionElementById(org.w3c.dom.Node startNode,
java.lang.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,
java.lang.String actor,
boolean doCreate)
find a WS-Security header block for a given actor |
static byte[] |
generateDigest(byte[] inputBytes)
Generate a (SHA1) digest of the input bytes. |
static byte[] |
generateNonce(int length)
Generate a nonce of the given length using the SHA1PRNG algorithm. |
static javax.crypto.Cipher |
getCipherInstance(java.lang.String cipherAlgo)
Translate the "cipherAlgo" URI to a JCE ID, and return a javax.crypto.Cipher instance of this type. |
static org.w3c.dom.Element |
getDirectChildElement(org.w3c.dom.Node parentNode,
java.lang.String localName,
java.lang.String namespace)
Gets a direct child with specified localname and namespace. |
static java.util.List<org.w3c.dom.Element> |
getDirectChildElements(org.w3c.dom.Node fNode,
java.lang.String localName,
java.lang.String namespace)
Gets all direct children with specified localname and namespace. |
static javax.xml.namespace.QName |
getFullQNameFromString(java.lang.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 java.lang.String |
getIDFromReference(java.lang.String ref)
Turn a reference (eg "#5") into an ID (eg "5"). |
static int |
getKeyLength(java.lang.String algorithm)
Returns the length of the key in # of bytes |
static java.lang.String |
getNamespace(java.lang.String prefix,
org.w3c.dom.Node e)
|
static java.lang.String |
getPrefixNS(java.lang.String uri,
org.w3c.dom.Node e)
|
static javax.xml.namespace.QName |
getQNameFromString(java.lang.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,
java.lang.String actor)
Returns the first WS-Security header element for a given actor. |
static SOAPConstants |
getSOAPConstants(org.w3c.dom.Element startElement)
|
static java.lang.String |
getSOAPNamespace(org.w3c.dom.Element startElement)
|
static java.lang.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(java.lang.String actor,
java.lang.String hActor)
Compares two actor strings and returns true if these are equal. |
static java.util.List<org.w3c.dom.Node> |
listChildren(org.w3c.dom.Node parent)
|
static java.util.List<org.w3c.dom.Node> |
newNodes(java.util.List<org.w3c.dom.Node> a,
java.util.List<org.w3c.dom.Node> b)
|
static javax.crypto.SecretKey |
prepareSecretKey(java.lang.String symEncAlgo,
byte[] rawKey)
Convert the raw key bytes into a SecretKey object of type symEncAlgo. |
static org.w3c.dom.Element |
prependChildElement(org.w3c.dom.Element parent,
org.w3c.dom.Element child)
prepend a child element |
static java.lang.String |
setNamespace(org.w3c.dom.Element element,
java.lang.String namespace,
java.lang.String prefix)
Set a namespace/prefix on an element if it is not set already. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WSSecurityUtil()
Method Detail |
---|
public static org.w3c.dom.Element getSecurityHeader(org.w3c.dom.Document doc, java.lang.String actor) throws WSSecurityException
doc
- actor
-
wsse:Security
element or null
if not such element found
WSSecurityException
public static boolean isActorEqual(java.lang.String actor, java.lang.String hActor)
actor
- hActor
-
public static org.w3c.dom.Element getDirectChildElement(org.w3c.dom.Node parentNode, java.lang.String localName, java.lang.String namespace)
parentNode
- the node where to start the searchlocalName
- local name of the child to getnamespace
- the namespace of the child to get
null
if not such node foundpublic static java.util.List<org.w3c.dom.Element> getDirectChildElements(org.w3c.dom.Node fNode, java.lang.String localName, java.lang.String namespace)
fNode
- the node where to start the searchlocalName
- local name of the children to getnamespace
- the namespace of the children to get
null
if not such nodes are foundpublic static org.w3c.dom.Element findBodyElement(org.w3c.dom.Document doc)
doc
-
null
if document does not
contain a SOAP bodypublic static java.util.List<org.w3c.dom.Element> findElements(WSEncryptionPart part, CallbackLookup callbackLookup, org.w3c.dom.Document doc) throws WSSecurityException
part
- The WSEncryptionPart object corresponding to the DOM Element(s) we wantcallbackLookup
- The CallbackLookup object used to find Elementsdoc
- The owning document
WSSecurityException
public static org.w3c.dom.Element findElement(org.w3c.dom.Node startNode, java.lang.String name, java.lang.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 URI
startNode
- Where to start the searchname
- Local name of the elementnamespace
- Namespace URI of the element
null
public static java.util.List<org.w3c.dom.Element> findElements(org.w3c.dom.Node startNode, java.lang.String name, java.lang.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 URI
startNode
- Where to start the searchname
- Local name of the elementnamespace
- Namespace URI of the element
public static org.w3c.dom.Element findSAMLAssertionElementById(org.w3c.dom.Node startNode, java.lang.String value)
startNode
- Where to start the searchvalue
- Value of the AssertionID/ID attribute
null
otherwisepublic static org.w3c.dom.Element findElementById(org.w3c.dom.Node startNode, java.lang.String value, boolean checkMultipleElements)
uri
and namespace
. The Id can be either a wsu:Id or an Id
with no 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 checkMultipleElements is true and 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 attributecheckMultipleElements
- If true then go through the entire tree and return
null if there are multiple elements with the same Id
null
otherwisepublic static java.lang.String setNamespace(org.w3c.dom.Element element, java.lang.String namespace, java.lang.String prefix)
element
- namespace
- prefix
-
public static java.lang.String getPrefixNS(java.lang.String uri, org.w3c.dom.Node e)
public static java.lang.String getNamespace(java.lang.String prefix, org.w3c.dom.Node e)
public static javax.xml.namespace.QName getQNameFromString(java.lang.String str, org.w3c.dom.Node e)
public static javax.xml.namespace.QName getFullQNameFromString(java.lang.String str, org.w3c.dom.Node e)
public static java.lang.String getStringForQName(javax.xml.namespace.QName qname, org.w3c.dom.Element e)
public static java.lang.String getIDFromReference(java.lang.String ref)
ref
-
public 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 append
public static org.w3c.dom.Element findWsseSecurityHeaderBlock(org.w3c.dom.Document doc, org.w3c.dom.Element envelope, boolean doCreate) throws WSSecurityException
doc
- the DOM document (SOAP request)envelope
- the SOAP envelopedoCreate
- if true create a new WSS header block if none exists
WSSecurityException
public static org.w3c.dom.Element findWsseSecurityHeaderBlock(org.w3c.dom.Document doc, org.w3c.dom.Element envelope, java.lang.String actor, boolean doCreate) throws WSSecurityException
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 exists
WSSecurityException
public static org.w3c.dom.Text createBase64EncodedTextNode(org.w3c.dom.Document doc, byte[] data)
doc
- the DOM document (SOAP request)data
- to encode
public static SOAPConstants getSOAPConstants(org.w3c.dom.Element startElement)
public static java.lang.String getSOAPNamespace(org.w3c.dom.Element startElement)
public static javax.crypto.SecretKey prepareSecretKey(java.lang.String symEncAlgo, byte[] rawKey)
public static javax.crypto.Cipher getCipherInstance(java.lang.String cipherAlgo) throws WSSecurityException
WSSecurityException
public static WSSecurityEngineResult fetchActionResult(java.util.List<WSSecurityEngineResult> resultList, int action)
resultList
- The result list to fetch an action fromaction
- The action to fetch
public static java.util.List<WSSecurityEngineResult> fetchAllActionResults(java.util.List<WSSecurityEngineResult> resultList, int action, java.util.List<WSSecurityEngineResult> actionResultList)
resultList
- The result list to fetch an action fromaction
- The action to fetchactionResultList
- where to store the found results data for the action
public static int decodeAction(java.lang.String action, java.util.List<java.lang.Integer> actions) throws WSSecurityException
WSSecurityException
public static int decodeAction(java.lang.String action, java.util.List<java.lang.Integer> actions, WSSConfig wssConfig) throws WSSecurityException
action
- The initial String of actions to performactions
- The list of created actions that will be performedwssConfig
- This object holds the list of custom actions to be performed.
WSSecurityException
public static int getKeyLength(java.lang.String algorithm) throws WSSecurityException
algorithm
-
WSSecurityException
public static byte[] generateNonce(int length) throws WSSecurityException
WSSecurityException
public static byte[] generateDigest(byte[] inputBytes) throws WSSecurityException
inputBytes
- the bytes to digest
WSSecurityException
public static void checkAllElementsProtected(java.util.List<WSSecurityEngineResult> results, int action, javax.xml.namespace.QName[] requiredParts) throws WSSecurityException
results
- The List of WSSecurityEngineResults from processingaction
- The action that is required (e.g. WSConstants.SIGN)requiredParts
- An array of QNames that correspond to the required elements
WSSecurityException
public static void checkSignsAllElements(WSSecurityEngineResult resultItem, java.lang.String[] requiredIDs) throws WSSecurityException
resultItem
- the signature to checkrequiredIDs
- the list of wsu:Id values that must be covered
WSSecurityException
- if any required element is not includedpublic static java.util.List<org.w3c.dom.Node> listChildren(org.w3c.dom.Node parent)
public static java.util.List<org.w3c.dom.Node> newNodes(java.util.List<org.w3c.dom.Node> a, java.util.List<org.w3c.dom.Node> b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |