Package com.ongres.scram.client
Class ScramClient
- java.lang.Object
-
- com.ongres.scram.client.ScramClient
-
public class ScramClient extends java.lang.Object
A class that can be parametrized to generateScramSession
s. 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:- The SecureRandom used (
SecureRandom
by default) are thread-safe too. The contract ofRandom
marks it as thread-safe, so inherited classes are also expected to maintain it. - No external nonceSupplier is provided; or if provided, it is thread-safe.
ScramClient.Builder.setup()
} method, can serve for multiple users and authentications. - The SecureRandom used (
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ScramClient.Builder
This class is not meant to be used directly.static class
ScramClient.ChannelBinding
Select whether this client will support channel binding or notstatic class
ScramClient.PreBuilder1
This class is not meant to be used directly.static class
ScramClient.PreBuilder2
This class is not meant to be used directly.
-
Field Summary
Fields Modifier and Type Field Description private ScramClient.ChannelBinding
channelBinding
static int
DEFAULT_NONCE_LENGTH
Length (in characters, bytes) of the nonce generated by default (if no nonce supplier is provided)private java.util.function.Supplier<java.lang.String>
nonceSupplier
private ScramMechanism
scramMechanism
private java.security.SecureRandom
secureRandom
private StringPreparation
stringPreparation
-
Constructor Summary
Constructors Modifier Constructor Description private
ScramClient(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, java.util.Optional<ScramMechanism> nonChannelBindingMechanism, java.util.Optional<ScramMechanism> channelBindingMechanism, java.security.SecureRandom secureRandom, java.util.function.Supplier<java.lang.String> nonceSupplier)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ScramClient.PreBuilder1
channelBinding(ScramClient.ChannelBinding channelBinding)
Selects for the client whether to use channel binding.ScramMechanism
getScramMechanism()
StringPreparation
getStringPreparation()
ScramSession
scramSession(java.lang.String user)
Instantiates aScramSession
for the specified user and this parametrized generator.static java.util.List<java.lang.String>
supportedMechanisms()
List all the supported SCRAM mechanisms by this client implementation
-
-
-
Field Detail
-
DEFAULT_NONCE_LENGTH
public static final int DEFAULT_NONCE_LENGTH
Length (in characters, bytes) of the nonce generated by default (if no nonce supplier is provided)- See Also:
- Constant Field Values
-
channelBinding
private final ScramClient.ChannelBinding channelBinding
-
stringPreparation
private final StringPreparation stringPreparation
-
scramMechanism
private final ScramMechanism scramMechanism
-
secureRandom
private final java.security.SecureRandom secureRandom
-
nonceSupplier
private final java.util.function.Supplier<java.lang.String> nonceSupplier
-
-
Constructor Detail
-
ScramClient
private ScramClient(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, java.util.Optional<ScramMechanism> nonChannelBindingMechanism, java.util.Optional<ScramMechanism> channelBindingMechanism, java.security.SecureRandom secureRandom, java.util.function.Supplier<java.lang.String> nonceSupplier)
-
-
Method Detail
-
channelBinding
public static ScramClient.PreBuilder1 channelBinding(ScramClient.ChannelBinding channelBinding) throws java.lang.IllegalArgumentException
Selects for the client whether to use channel binding. Refer toScramClient.ChannelBinding
documentation for the description of the possible values.- Parameters:
channelBinding
- The channel binding setting- Returns:
- The next step in the chain (PreBuilder1).
- Throws:
java.lang.IllegalArgumentException
- If channelBinding is null
-
getStringPreparation
public StringPreparation getStringPreparation()
-
getScramMechanism
public ScramMechanism getScramMechanism()
-
supportedMechanisms
public static java.util.List<java.lang.String> supportedMechanisms()
List all the supported SCRAM mechanisms by this client implementation- Returns:
- A list of the IANA-registered, SCRAM supported mechanisms
-
scramSession
public ScramSession scramSession(java.lang.String user)
Instantiates aScramSession
for the specified user and this parametrized generator.- Parameters:
user
- The username of the authentication exchange- Returns:
- The ScramSession instance
-
-