Top Description Inners Fields Constructors Methods
com.ongres.scram.client

public Class ScramClient

extends Object
Class Inheritance
Imports
com.ongres.scram.common.ScramMechanism, .ScramMechanisms, com.ongres.scram.common.gssapi.Gs2CbindFlag, com.ongres.scram.common.stringprep.StringPreparation, com.ongres.scram.common.util.CryptoUtil, java.security.NoSuchAlgorithmException, .NoSuchProviderException, .SecureRandom, java.util.ArrayList, .List

A class that can be parametrized to generate ScramSessions. This class supports the channel binding and string preparation mechanisms that are provided by module scram-common. The class is fully configurable, including options to selected the desired channel binding, automatically pick the best client SCRAM mechanism based on those supported (advertised) by the server, selecting an externally-provided SecureRandom instance or an external nonceProvider, or choosing the nonce length. This class is thread-safe if the two following conditions are met: So this class, once instantiated via the Builder#setup()} method, can serve for multiple users and authentications.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
ScramClient.Builder

This class is not meant to be used directly.

public static enum
ScramClient.ChannelBinding

Select whether this client will support channel binding or not

public static class
ScramClient.PreBuilder1

This class is not meant to be used directly.

public static class
ScramClient.PreBuilder2

This class is not meant to be used directly.

Field Summary

Modifier and TypeField and Description
private final ScramClient.ChannelBinding
public static final int
DEFAULT_NONCE_LENGTH

Length (in characters, bytes) of the nonce generated by default (if no nonce supplier is provided)

private final NonceSupplier
private final ScramMechanism
private final SecureRandom
private final StringPreparation

Constructor Summary

AccessConstructor and Description
private
ScramClient(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism, SecureRandom secureRandom, NonceSupplier nonceSupplier)

Method Summary

Modifier and TypeMethod and Description
public static ScramClient.PreBuilder1

Returns:

The next step in the chain (PreBuilder1).
channelBinding
(ScramClient.ChannelBinding
The channel binding setting
channelBinding
)

Selects for the client whether to use channel binding.

public ScramMechanism
public StringPreparation
public ScramSession

Returns:

The ScramSession instance
scramSession
(String
The username of the authentication exchange
user
)

Instantiates a ScramSession for the specified user and this parametrized generator.

public static List<String>

Returns:

A list of the IANA-registered, SCRAM supported mechanisms
supportedMechanisms
()

List all the supported SCRAM mechanisms by this client implementation

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelBindingback to summary
private final ScramClient.ChannelBinding channelBinding
DEFAULT_NONCE_LENGTHback to summary
public static final int DEFAULT_NONCE_LENGTH

Length (in characters, bytes) of the nonce generated by default (if no nonce supplier is provided)

nonceSupplierback to summary
private final NonceSupplier nonceSupplier
scramMechanismback to summary
private final ScramMechanism scramMechanism
secureRandomback to summary
private final SecureRandom secureRandom
stringPreparationback to summary
private final StringPreparation stringPreparation

Constructor Detail

ScramClientback to summary
private ScramClient(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism, SecureRandom secureRandom, NonceSupplier nonceSupplier)

Method Detail

channelBindingback to summary
public static ScramClient.PreBuilder1 channelBinding(ScramClient.ChannelBinding channelBinding) throws IllegalArgumentException

Selects for the client whether to use channel binding. Refer to ChannelBinding documentation for the description of the possible values.

Parameters
channelBinding:ScramClient.ChannelBinding

The channel binding setting

Returns:ScramClient.PreBuilder1

The next step in the chain (PreBuilder1).

Exceptions
IllegalArgumentException:
If channelBinding is null
getScramMechanismback to summary
public ScramMechanism getScramMechanism()
getStringPreparationback to summary
public StringPreparation getStringPreparation()
scramSessionback to summary
public ScramSession scramSession(String user)

Instantiates a ScramSession for the specified user and this parametrized generator.

Parameters
user:String

The username of the authentication exchange

Returns:ScramSession

The ScramSession instance

supportedMechanismsback to summary
public static List<String> supportedMechanisms()

List all the supported SCRAM mechanisms by this client implementation

Returns:List<String>

A list of the IANA-registered, SCRAM supported mechanisms

com.ongres.scram.client back to summary

public Class ScramClient.Builder

extends PreBuilder2
Class Inheritance

This class is not meant to be used directly. Use instead ScramClient#channelBinding(ChannelBinding) and chained methods.

Field Summary

Modifier and TypeField and Description
private final ScramMechanism
private int
private NonceSupplier
private final ScramMechanism
private SecureRandom
Inherited from com.ongres.scram.client.ScramClient.PreBuilder2:
stringPreparation

Constructor Summary

AccessConstructor and Description
private
Builder(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism)

Method Summary

Modifier and TypeMethod and Description
public ScramClient.Builder

Returns:

The same class
nonceLength
(int
The length of the nonce. Must be positive and greater than 0
length
)

Sets a non-default (ScramClient#DEFAULT_NONCE_LENGTH) length for the nonce generation, if no alternate nonceSupplier is provided via Builder#nonceSupplier(NonceSupplier).

public ScramClient.Builder

Returns:

The same class
nonceSupplier
(NonceSupplier
A supplier of valid nonce Strings. Please note that according to the SCRAM RFC only ASCII printable characters (except the comma, ',') are permitted on a nonce. Length is not limited.
nonceSupplier
)

Optional call.

public ScramClient.Builder

Returns:

The same class
secureRandomAlgorithmProvider
(String
The name of the algorithm to use.
algorithm
,
String
The name of the provider of SecureRandom. Might be null.
provider
)

Optional call.

public ScramClient

Returns:

The fully built instance.
setup
()

Gets the client, fully constructed and configured, with the provided channel binding, string preparation properties, and the selected SCRAM mechanism based on server supported mechanisms.

Inherited from com.ongres.scram.client.ScramClient.PreBuilder2:
selectClientMechanismselectMechanismBasedOnServerAdvertisedselectMechanismBasedOnServerAdvertisedCsv

Field Detail

channelBindingMechanismback to summary
private final ScramMechanism channelBindingMechanism

Hides com.ongres.scram.client.ScramClient.PreBuilder2.channelBindingMechanism.

nonceLengthback to summary
private int nonceLength
nonceSupplierback to summary
private NonceSupplier nonceSupplier
nonChannelBindingMechanismback to summary
private final ScramMechanism nonChannelBindingMechanism

Hides com.ongres.scram.client.ScramClient.PreBuilder2.nonChannelBindingMechanism.

secureRandomback to summary
private SecureRandom secureRandom

Constructor Detail

Builderback to summary
private Builder(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism)

Method Detail

nonceLengthback to summary
public ScramClient.Builder nonceLength(int length) throws IllegalArgumentException

Sets a non-default (ScramClient#DEFAULT_NONCE_LENGTH) length for the nonce generation, if no alternate nonceSupplier is provided via Builder#nonceSupplier(NonceSupplier).

Parameters
length:int

The length of the nonce. Must be positive and greater than 0

Returns:ScramClient.Builder

The same class

Exceptions
IllegalArgumentException:
If length is less than 1
nonceSupplierback to summary
public ScramClient.Builder nonceSupplier(NonceSupplier nonceSupplier) throws IllegalArgumentException

Optional call. The client will use a default nonce generator, unless an external one is provided by this method. *

Parameters
nonceSupplier:NonceSupplier

A supplier of valid nonce Strings. Please note that according to the SCRAM RFC only ASCII printable characters (except the comma, ',') are permitted on a nonce. Length is not limited.

Returns:ScramClient.Builder

The same class

Exceptions
IllegalArgumentException:
If nonceSupplier is null
secureRandomAlgorithmProviderback to summary
public ScramClient.Builder secureRandomAlgorithmProvider(String algorithm, String provider) throws IllegalArgumentException

Optional call. Selects a non-default SecureRandom instance, based on the given algorithm and optionally provider. This SecureRandom instance will be used to generate secure random values, like the ones required to generate the nonce (unless an external nonce provider is given via Builder#nonceSupplier(NonceSupplier)). Algorithm and provider names are those supported by the SecureRandom class.

Parameters
algorithm:String

The name of the algorithm to use.

provider:String

The name of the provider of SecureRandom. Might be null.

Returns:ScramClient.Builder

The same class

Exceptions
IllegalArgumentException:
If algorithm is null, or either the algorithm or provider are not supported
setupback to summary
public ScramClient setup()

Gets the client, fully constructed and configured, with the provided channel binding, string preparation properties, and the selected SCRAM mechanism based on server supported mechanisms. If no SecureRandom algorithm and provider were provided, a default one would be used. If no nonceSupplier was provided, a default nonce generator would be used, of the ScramClient#DEFAULT_NONCE_LENGTH length, unless Builder#nonceLength(int) is called.

Returns:ScramClient

The fully built instance.

com.ongres.scram.client back to summary

public final Enum ScramClient.ChannelBinding

extends Enum<ScramClient.ChannelBinding>
Class Inheritance

Select whether this client will support channel binding or not

Field Summary

Modifier and TypeField and Description
private final Gs2CbindFlag
public static final ScramClient.ChannelBinding
IF_SERVER_SUPPORTS_IT

Channel binding is preferred.

public static final ScramClient.ChannelBinding
NO

Don't use channel binding.

public static final ScramClient.ChannelBinding
YES

Force use of channel binding.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Gs2CbindFlag
public static ScramClient.ChannelBinding
public static ScramClient.ChannelBinding[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

gs2CbindFlagback to summary
private final Gs2CbindFlag gs2CbindFlag
IF_SERVER_SUPPORTS_ITback to summary
public static final ScramClient.ChannelBinding IF_SERVER_SUPPORTS_IT

Channel binding is preferred. Non-channel binding mechanisms will be used if either the server does not support channel binding, or no channel binding data is provided as part of the ClientFirstMessage

NOback to summary
public static final ScramClient.ChannelBinding NO

Don't use channel binding. Server must support at least one non-channel binding mechanism.

YESback to summary
public static final ScramClient.ChannelBinding YES

Force use of channel binding. Server must support at least one channel binding mechanism. Channel binding data will need to be provided as part of the ClientFirstMessage.

Constructor Detail

ChannelBindingback to summary
private ChannelBinding(Gs2CbindFlag gs2CbindFlag)

Method Detail

gs2CbindFlagback to summary
public Gs2CbindFlag gs2CbindFlag()
valueOfback to summary
public static ScramClient.ChannelBinding valueOf(String name)
valuesback to summary
public static ScramClient.ChannelBinding[] values()
com.ongres.scram.client back to summary

public Class ScramClient.PreBuilder1

extends Object
Class Inheritance
Known Direct Subclasses
com.ongres.scram.client.ScramClient.PreBuilder2

This class is not meant to be used directly. Use ScramClient#channelBinding(ChannelBinding) instead.

Field Summary

Modifier and TypeField and Description
protected final ScramClient.ChannelBinding

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public ScramClient.PreBuilder2
stringPreparation(StringPreparation
The string preparation algorithm
stringPreparation
)

Selects the string preparation algorithm to use by the client.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

channelBindingback to summary
protected final ScramClient.ChannelBinding channelBinding

Constructor Detail

PreBuilder1back to summary
private PreBuilder1(ScramClient.ChannelBinding channelBinding)

Method Detail

stringPreparationback to summary
public ScramClient.PreBuilder2 stringPreparation(StringPreparation stringPreparation) throws IllegalArgumentException

Selects the string preparation algorithm to use by the client.

Parameters
stringPreparation:StringPreparation

The string preparation algorithm

Exceptions
IllegalArgumentException:
If stringPreparation is null
com.ongres.scram.client back to summary

public Class ScramClient.PreBuilder2

extends PreBuilder1
Class Inheritance
Known Direct Subclasses
com.ongres.scram.client.ScramClient.Builder

This class is not meant to be used directly. Use ScramClient#channelBinding(ChannelBinding).{#stringPreparation(StringPreparation)} instead.

Field Summary

Modifier and TypeField and Description
protected ScramMechanism
protected ScramMechanism
protected final StringPreparation
Inherited from com.ongres.scram.client.ScramClient.PreBuilder1:
channelBinding

Constructor Summary

AccessConstructor and Description
private
PreBuilder2(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation)

Method Summary

Modifier and TypeMethod and Description
public ScramClient.Builder
selectClientMechanism(ScramMechanism
The selected scram mechanism
scramMechanism
)

Select a fixed client mechanism.

public ScramClient.Builder
selectMechanismBasedOnServerAdvertised(String...
One or more IANA-registered SCRAM mechanism names, as advertised by the server
serverMechanisms
)

Inform the client of the SCRAM mechanisms supported by the server.

public ScramClient.Builder
selectMechanismBasedOnServerAdvertisedCsv(String
A CSV (Comma-Separated Values) String, containining all the SCRAM mechanisms supported by the server
serverMechanismsCsv
)

Inform the client of the SCRAM mechanisms supported by the server.

Inherited from com.ongres.scram.client.ScramClient.PreBuilder1:
stringPreparation

Field Detail

channelBindingMechanismback to summary
protected ScramMechanism channelBindingMechanism
nonChannelBindingMechanismback to summary
protected ScramMechanism nonChannelBindingMechanism
stringPreparationback to summary
protected final StringPreparation stringPreparation

Constructor Detail

PreBuilder2back to summary
private PreBuilder2(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation)

Method Detail

selectClientMechanismback to summary
public ScramClient.Builder selectClientMechanism(ScramMechanism scramMechanism)

Select a fixed client mechanism. It must be compatible with the channel binding selection previously performed. If automatic selection based on server advertised mechanisms is preferred, please use methods Builder#selectMechanismBasedOnServerAdvertised(String...) or Builder#selectMechanismBasedOnServerAdvertisedCsv(String).

Parameters
scramMechanism:ScramMechanism

The selected scram mechanism

Exceptions
IllegalArgumentException:
If the selected mechanism is null or not compatible with the prior channel binding selection, or channel binding selection is dependent on the server advertised methods
selectMechanismBasedOnServerAdvertisedback to summary
public ScramClient.Builder selectMechanismBasedOnServerAdvertised(String... serverMechanisms)

Inform the client of the SCRAM mechanisms supported by the server. Based on this list, the channel binding settings previously specified, and the relative strength of the supported SCRAM mechanisms for this client, the client will have enough data to select which mechanism to use for future interactions with the server. All names provided here need to be standar IANA Registry names for SCRAM mechanisms, or will be ignored.

Parameters
serverMechanisms:String[]

One or more IANA-registered SCRAM mechanism names, as advertised by the server

Exceptions
IllegalArgumentException:
If no server mechanisms are provided
See Also
SASL SCRAM Family Mechanisms
selectMechanismBasedOnServerAdvertisedCsvback to summary
public ScramClient.Builder selectMechanismBasedOnServerAdvertisedCsv(String serverMechanismsCsv) throws IllegalArgumentException

Inform the client of the SCRAM mechanisms supported by the server. Calls Builder#selectMechanismBasedOnServerAdvertised(String...) with the results of splitting the received comma-separated values.

Parameters
serverMechanismsCsv:String

A CSV (Comma-Separated Values) String, containining all the SCRAM mechanisms supported by the server

Exceptions
IllegalArgumentException:
If selectMechanismBasedOnServerAdvertisedCsv is null