public class WSTrustUtil extends Object
Utility class that provides methods for parsing/creating WS-Trust elements.
Constructor and Description |
---|
WSTrustUtil() |
Modifier and Type | Method and Description |
---|---|
static AppliesTo |
createAppliesTo(String endpointURI)
Creates an instance of
AppliesTo using the specified endpoint address. |
static Lifetime |
createDefaultLifetime(long tokenTimeout)
Creates a
Lifetime instance that specifies a range of time that starts at the current GMT time and has
the
specified duration in milliseconds. |
static EndpointReferenceType |
createIssuer(String addressUri)
Given an address, create the WS-Addressing issuer
|
static KeyIdentifierType |
createKeyIdentifier(String valueType,
String value)
Creates an instance of
KeyIdentifierType with the specified values. |
static KeyInfoType |
createKeyInfo(byte[] secret,
PublicKey encryptionKey,
URI keyWrapAlgo)
Creates a
KeyInfoType that wraps the specified secret. |
static KeyInfoType |
createKeyInfo(byte[] secret,
PublicKey encryptionKey,
URI keyWrapAlgo,
X509Certificate cer)
Creates a
KeyInfoType that wraps the specified secret. |
static KeyInfoType |
createKeyInfo(Certificate certificate)
Creates a
KeyInfoType that wraps the specified certificate. |
static KeyValueType |
createKeyValue(PublicKey key)
Creates a
KeyValueType that wraps the specified public key. |
static OnBehalfOfType |
createOnBehalfOfWithUsername(String username,
String id)
Creates a
OnBehalfOfType instance that contains a UsernameTokenType . |
static byte[] |
createRandomSecret(int size)
Creates a random
byte[] secret of the specified size. |
static RequestedReferenceType |
createRequestedReference(KeyIdentifierType keyIdentifier,
Map<QName,String> attributes)
Creates an instance of
RequestedReferenceType with the specified values. |
static byte[] |
getBinarySecret(EntropyType entropy)
Parses the specified
EntropyType and returns the first binary secret contained in the entropy. |
static Principal |
getOnBehalfOfPrincipal(OnBehalfOfType onBehalfOf)
Parses the contents of the
OnBehalfOf element and returns a Principal representing the identity
on behalf
of which the request was made. |
static String |
getServiceNameFromAppliesTo(RequestSecurityToken requestSecurityToken) |
static byte[] |
P_SHA1(byte[] secret,
byte[] seed,
int requiredSize)
This method implements the
P_SHA-1 function as defined in the RFC 2246 - The TLS Protocol Version 1.0
Section
5. |
static String |
parseAppliesTo(AppliesTo appliesTo)
Parses the contents of the
AppliesTo element and returns the address the uniquely identify the service
provider. |
static RenewingType |
parseRenewingType(XMLEventReader xmlEventReader) |
static void |
persistSTSConfiguration(STSType stsConfiguration,
OutputStream outputStream)
Marshall the
STSType to an outputstream |
public static KeyIdentifierType createKeyIdentifier(String valueType, String value)
Creates an instance of KeyIdentifierType
with the specified values.
valueType
- a String
representing the identifier value type.value
- a String
representing the identifier value.KeyIdentifierType
instance.public static RequestedReferenceType createRequestedReference(KeyIdentifierType keyIdentifier, Map<QName,String> attributes)
Creates an instance of RequestedReferenceType
with the specified values. This method first creates a
SecurityTokenReferenceType
with the specified key identifier and attributes and then use this reference
to
construct the RequestedReferenceType
that is returned.
keyIdentifier
- the key identifier of the security token reference.attributes
- the attributes to be set on the security token reference.RequestedReferenceType
instance.public static AppliesTo createAppliesTo(String endpointURI)
Creates an instance of AppliesTo
using the specified endpoint address.
endpointURI
- a String
representing the endpoint URI.AppliesTo
instance.public static EndpointReferenceType createIssuer(String addressUri)
addressUri
- public static String parseAppliesTo(AppliesTo appliesTo)
Parses the contents of the AppliesTo
element and returns the address the uniquely identify the service
provider.
appliesTo
- the AppliesTo
instance to be parsed.public static RenewingType parseRenewingType(XMLEventReader xmlEventReader) throws ParsingException
ParsingException
public static Lifetime createDefaultLifetime(long tokenTimeout)
Creates a Lifetime
instance that specifies a range of time that starts at the current GMT time and has
the
specified duration in milliseconds.
tokenTimeout
- the token timeout value (in milliseconds).Lifetime
instance.public static Principal getOnBehalfOfPrincipal(OnBehalfOfType onBehalfOf)
Parses the contents of the OnBehalfOf
element and returns a Principal
representing the identity
on behalf
of which the request was made.
onBehalfOf
- the type that represents the OnBehalfOf
element.Principal
representing the extracted identity, or null
if the contents of the
OnBehalfOf
element could not be parsed.public static OnBehalfOfType createOnBehalfOfWithUsername(String username, String id)
Creates a OnBehalfOfType
instance that contains a UsernameTokenType
.
username
- a String
that represents the username of the UsernameTokenType
.id
- an optional String
that uniquely identifies the UsernameTokenType
.OnBehalfOfType
instance.public static byte[] getBinarySecret(EntropyType entropy)
Parses the specified EntropyType
and returns the first binary secret contained in the entropy.
entropy
- a reference to the EntropyType
that contains the binary secret.byte[]
containing the secret; null
if the specified entropy doesn't contain any
secret.public static void persistSTSConfiguration(STSType stsConfiguration, OutputStream outputStream)
Marshall the STSType
to an outputstream
stsConfiguration
- outputStream
- public static byte[] createRandomSecret(int size)
Creates a random byte[]
secret of the specified size.
size
- the size of the secret to be created, in bytes.byte[]
containing the generated secret.public static byte[] P_SHA1(byte[] secret, byte[] seed, int requiredSize) throws NoSuchAlgorithmException, InvalidKeyException
This method implements the P_SHA-1
function as defined in the RFC 2246 - The TLS Protocol Version 1.0
Section
5. HMAC and the pseudorandom function:
P_hash(secret, seed) = HMAC_hash(secret, A(1) + seed) + HMAC_hash(secret, A(2) + seed) + HMAC_hash(secret, A(3) + seed) + ... Where + indicates concatenation. A() is defined as: A(0) = seed A(i) = HMAC_hash(secret, A(i-1))
secret
- a byte[]
that represents the HMAC secret.seed
- a byte[]
that represents the seed to be used.requiredSize
- an int
that specifies the size (in bytes) of the result.byte[]
containing the result of the P_SHA-1
function.NoSuchAlgorithmException
- if an error occurs while creating the Mac
instance.InvalidKeyException
- if an error occurs while initializing the Mac
instance.public static KeyInfoType createKeyInfo(byte[] secret, PublicKey encryptionKey, URI keyWrapAlgo, X509Certificate cer) throws WSTrustException
Creates a KeyInfoType
that wraps the specified secret. If the encryptionKey
parameter is not
null, the
secret is encrypted using the specified public key before it is set in the KeyInfoType
. It also create a
keyinfo with the information about the key used for the encryption
secret
- a byte[]
representing the secret (symmetric key).encryptionKey
- the PublicKey
that must be used to encrypt the secret.keyWrapAlgo
- the key wrap algorithm to be used.KeyInfoType
instance.WSTrustException
- if an error occurs while creating the KeyInfoType
object.public static KeyInfoType createKeyInfo(byte[] secret, PublicKey encryptionKey, URI keyWrapAlgo) throws WSTrustException
Creates a KeyInfoType
that wraps the specified secret. If the encryptionKey
parameter is not
null, the
secret is encrypted using the specified public key before it is set in the KeyInfoType
.
secret
- a byte[]
representing the secret (symmetric key).encryptionKey
- the PublicKey
that must be used to encrypt the secret.keyWrapAlgo
- the key wrap algorithm to be used.KeyInfoType
instance.WSTrustException
- if an error occurs while creating the KeyInfoType
object.public static KeyInfoType createKeyInfo(Certificate certificate) throws WSTrustException
Creates a KeyInfoType
that wraps the specified certificate.
certificate
- the Certificate
to be wrapped as a X509DataType
inside the KeyInfoType
.KeyInfoType
object.WSTrustException
- if an error occurs while creating the KeyInfoType
.public static KeyValueType createKeyValue(PublicKey key)
Creates a KeyValueType
that wraps the specified public key. This method supports DSA and RSA keys.
key
- the PublicKey
that will be represented as a KeyValueType
.KeyValueType
or null
if the specified key is neither a DSA nor a RSA
key.public static String getServiceNameFromAppliesTo(RequestSecurityToken requestSecurityToken)
Copyright © 2017 JBoss by Red Hat. All rights reserved.