Top Description Inners Fields Constructors Methods
org.glassfish.tyrus.client.auth

pack-priv final Class DigestAuthenticator

extends Authenticator
Class Inheritance
Imports
java.io.IOException, java.net.URI, java.security.MessageDigest, .NoSuchAlgorithmException, .SecureRandom, java.util.logging.Logger, java.util.regex.Matcher, .Pattern, org.glassfish.tyrus.core.l10n.LocalizationMessages

Generates a value of Authorization header of HTTP request for Digest Http Authentication scheme (RFC 2617).
Authors
[email protected], Stefan Katerkamp ([email protected]), Miroslav Fuksa, Ondrej Kosatka

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static enum
pack-priv class
private static enum

Field Summary

Modifier and TypeField and Description
private static final int
private static final char[]
private static final Pattern
private static final Logger
private SecureRandom

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private static void
append(StringBuilder
string builder instance
sb
,
String
key string
key
,
String
value string
value
,
boolean
true if value needs to be enclosed in quotes
useQuote
)

Append comma separated key=value token

private static void
append(StringBuilder
string builder instance
sb
,
String
key string
key
,
String
value string
value
)

Append comma separated key=value token.

private static String

Returns:

hex string
bytesToHex
(byte[]
array of bytes
bytes
)

Convert bytes array to hex string.

private String

Returns:

digest authentication token string
createNextAuthToken
(final DigestAuthenticator.DigestScheme
DigestScheme instance
ds
,
final String
client request uri
uri
,
final Credentials credentials)

Creates digest string including counter.

public String
generateAuthorizationHeader(final URI
Uri of the server endpoint.
uri
,
final String
"WWW-Authenticate" header value received in a handshake response.
wwwAuthenticateHeader
,
final Credentials
credentials passed by property ClientProperties#CREDENTIALS. Can be null when there were no Credentials registered.
credentials
)

Implements abstract org.glassfish.tyrus.client.auth.Authenticator.generateAuthorizationHeader.

Generate value used as "Authorization" header value for next request.

private static String

Returns:

M5 hash string
md5
(String...
one or more strings
tokens
)

Colon separated value MD5 hash.

private DigestAuthenticator.DigestScheme

Returns:

DigestScheme or null if no digest header exists.
parseAuthHeaders
(final String
value of WWW-Authenticate header
authHeader
)

Parse digest header.

private String

Returns:

hex string
randomBytes
(int
number of bytes to generate
nbBytes
)

Generate a random sequence of bytes and return its hex representation

Field Detail

CLIENT_NONCE_BYTE_COUNTback to summary
private static final int CLIENT_NONCE_BYTE_COUNT
HEX_ARRAYback to summary
private static final char[] HEX_ARRAY
KEY_VALUE_PAIR_PATTERNback to summary
private static final Pattern KEY_VALUE_PAIR_PATTERN
loggerback to summary
private static final Logger logger
randomGeneratorback to summary
private SecureRandom randomGenerator

Constructor Detail

DigestAuthenticatorback to summary
pack-priv DigestAuthenticator()

Method Detail

appendback to summary
private static void append(StringBuilder sb, String key, String value, boolean useQuote)

Append comma separated key=value token

Parameters
sb:StringBuilder

string builder instance

key:String

key string

value:String

value string

useQuote:boolean

true if value needs to be enclosed in quotes

appendback to summary
private static void append(StringBuilder sb, String key, String value)

Append comma separated key=value token. The value gets enclosed in quotes.

Parameters
sb:StringBuilder

string builder instance

key:String

key string

value:String

value string

bytesToHexback to summary
private static String bytesToHex(byte[] bytes)

Convert bytes array to hex string.

Parameters
bytes:byte[]

array of bytes

Returns:String

hex string

createNextAuthTokenback to summary
private String createNextAuthToken(final DigestAuthenticator.DigestScheme ds, final String uri, final Credentials credentials) throws AuthenticationException

Creates digest string including counter.

Parameters
ds:DigestAuthenticator.DigestScheme

DigestScheme instance

uri:String

client request uri

Returns:String

digest authentication token string

Exceptions
AuthenticationException:
if MD5 hash fails
generateAuthorizationHeaderback to summary
public String generateAuthorizationHeader(final URI uri, final String wwwAuthenticateHeader, final Credentials credentials) throws AuthenticationException

Implements abstract org.glassfish.tyrus.client.auth.Authenticator.generateAuthorizationHeader.

Doc from org.glassfish.tyrus.client.auth.Authenticator.generateAuthorizationHeader.

Generate value used as "Authorization" header value for next request.

Thrown AuthenticationException will be wrapped as DeploymentException and thrown as a result of WebSocketContainer.connectToServer(...) method call.

Parameters
uri:URI

Uri of the server endpoint.

wwwAuthenticateHeader:String

"WWW-Authenticate" header value received in a handshake response.

credentials:Credentials

credentials passed by property ClientProperties#CREDENTIALS. Can be null when there were no Credentials registered.

Returns:String

value for Authorization header which will be put into next handshake request.

Annotations
@Override
Exceptions
AuthenticationException:
when it is not possible to create "Authorization" header.
md5back to summary
private static String md5(String... tokens) throws AuthenticationException

Colon separated value MD5 hash.

Parameters
tokens:String[]

one or more strings

Returns:String

M5 hash string

Exceptions
AuthenticationException:
if MD5 algorithm cannot be instantiated
parseAuthHeadersback to summary
private DigestAuthenticator.DigestScheme parseAuthHeaders(final String authHeader) throws IOException

Parse digest header.

Parameters
authHeader:String

value of WWW-Authenticate header

Returns:DigestAuthenticator.DigestScheme

DigestScheme or null if no digest header exists.

randomBytesback to summary
private String randomBytes(int nbBytes)

Generate a random sequence of bytes and return its hex representation

Parameters
nbBytes:int

number of bytes to generate

Returns:String

hex string

org.glassfish.tyrus.client.auth back to summary

pack-priv final Enum DigestAuthenticator.Algorithm

extends Enum<DigestAuthenticator.Algorithm>
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final String
public static final DigestAuthenticator.Algorithm
public static final DigestAuthenticator.Algorithm
public static final DigestAuthenticator.Algorithm

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static DigestAuthenticator.Algorithm
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static DigestAuthenticator.Algorithm
public static DigestAuthenticator.Algorithm[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

mdback to summary
private final String md
MD5back to summary
public static final DigestAuthenticator.Algorithm MD5
MD5_SESSback to summary
public static final DigestAuthenticator.Algorithm MD5_SESS
UNSPECIFIEDback to summary
public static final DigestAuthenticator.Algorithm UNSPECIFIED

Constructor Detail

Algorithmback to summary
private Algorithm(String md)

Method Detail

parseback to summary
public static DigestAuthenticator.Algorithm parse(String val)
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static DigestAuthenticator.Algorithm valueOf(String name)
valuesback to summary
public static DigestAuthenticator.Algorithm[] values()
org.glassfish.tyrus.client.auth back to summary

pack-priv final Class DigestAuthenticator.DigestScheme

extends Object
Class Inheritance
  • java.lang.Object
  • org.glassfish.tyrus.client.auth.DigestAuthenticator.DigestScheme

Digest scheme POJO

Field Summary

Modifier and TypeField and Description
private final DigestAuthenticator.Algorithm
private volatile int
private final String
private final String
private final DigestAuthenticator.QOP
private final String
private final boolean

Constructor Summary

AccessConstructor and Description
pack-priv
DigestScheme(String realm, String nonce, String opaque, DigestAuthenticator.QOP qop, DigestAuthenticator.Algorithm algorithm, boolean stale)

Method Summary

Modifier and TypeMethod and Description
public DigestAuthenticator.Algorithm
public int
public String
public String
public DigestAuthenticator.QOP
public String
public int
public boolean
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private final DigestAuthenticator.Algorithm algorithm
ncback to summary
private volatile int nc
nonceback to summary
private final String nonce
opaqueback to summary
private final String opaque
qopback to summary
private final DigestAuthenticator.QOP qop
realmback to summary
private final String realm
staleback to summary
private final boolean stale

Constructor Detail

DigestSchemeback to summary
pack-priv DigestScheme(String realm, String nonce, String opaque, DigestAuthenticator.QOP qop, DigestAuthenticator.Algorithm algorithm, boolean stale)

Method Detail

getAlgorithmback to summary
public DigestAuthenticator.Algorithm getAlgorithm()
getNcback to summary
public int getNc()
getNonceback to summary
public String getNonce()
getOpaqueback to summary
public String getOpaque()
getQopback to summary
public DigestAuthenticator.QOP getQop()
getRealmback to summary
public String getRealm()
incrementCounterback to summary
public int incrementCounter()
isStaleback to summary
public boolean isStale()
org.glassfish.tyrus.client.auth back to summary

private final Enum DigestAuthenticator.QOP

extends Enum<DigestAuthenticator.QOP>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final DigestAuthenticator.QOP
private final String
public static final DigestAuthenticator.QOP

Constructor Summary

AccessConstructor and Description
private
QOP(String qop)

Method Summary

Modifier and TypeMethod and Description
public static DigestAuthenticator.QOP
public String
toString()

Overrides java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration.

public static DigestAuthenticator.QOP
public static DigestAuthenticator.QOP[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinalvalueOf

Field Detail

AUTHback to summary
public static final DigestAuthenticator.QOP AUTH
qopback to summary
private final String qop
UNSPECIFIEDback to summary
public static final DigestAuthenticator.QOP UNSPECIFIED

Constructor Detail

QOPback to summary
private QOP(String qop)

Method Detail

parseback to summary
public static DigestAuthenticator.QOP parse(String val)
toStringback to summary
public String toString()

Overrides java.lang.Enum.toString.

Doc from java.lang.Enum.toString.

Returns the name of this enum constant, as contained in the declaration. This method may be overridden, though it typically isn't necessary or desirable. An enum class should override this method when a more "programmer-friendly" string form exists.

Returns:String

the name of this enum constant

Annotations
@Override
valueOfback to summary
public static DigestAuthenticator.QOP valueOf(String name)
valuesback to summary
public static DigestAuthenticator.QOP[] values()