Package com.ongres.scram.client
Class ScramClient.Builder
- java.lang.Object
-
- com.ongres.scram.client.ScramClient.PreBuilder1
-
- com.ongres.scram.client.ScramClient.PreBuilder2
-
- com.ongres.scram.client.ScramClient.Builder
-
- Enclosing class:
- ScramClient
public static class ScramClient.Builder extends ScramClient.PreBuilder2
This class is not meant to be used directly. Use insteadScramClient.channelBinding(ChannelBinding)
and chained methods.
-
-
Field Summary
Fields Modifier and Type Field Description private ScramMechanism
channelBindingMechanism
private int
nonceLength
private NonceSupplier
nonceSupplier
private ScramMechanism
nonChannelBindingMechanism
private java.security.SecureRandom
secureRandom
-
Fields inherited from class com.ongres.scram.client.ScramClient.PreBuilder2
stringPreparation
-
Fields inherited from class com.ongres.scram.client.ScramClient.PreBuilder1
channelBinding
-
-
Constructor Summary
Constructors Modifier Constructor Description private
Builder(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ScramClient.Builder
nonceLength(int length)
Sets a non-default (ScramClient.DEFAULT_NONCE_LENGTH
) length for the nonce generation, if no alternate nonceSupplier is provided vianonceSupplier(NonceSupplier)
.ScramClient.Builder
nonceSupplier(NonceSupplier nonceSupplier)
Optional call.ScramClient.Builder
secureRandomAlgorithmProvider(java.lang.String algorithm, java.lang.String provider)
Optional call.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.-
Methods inherited from class com.ongres.scram.client.ScramClient.PreBuilder2
selectClientMechanism, selectMechanismBasedOnServerAdvertised, selectMechanismBasedOnServerAdvertisedCsv
-
Methods inherited from class com.ongres.scram.client.ScramClient.PreBuilder1
stringPreparation
-
-
-
-
Field Detail
-
nonChannelBindingMechanism
private final ScramMechanism nonChannelBindingMechanism
-
channelBindingMechanism
private final ScramMechanism channelBindingMechanism
-
secureRandom
private java.security.SecureRandom secureRandom
-
nonceSupplier
private NonceSupplier nonceSupplier
-
nonceLength
private int nonceLength
-
-
Constructor Detail
-
Builder
private Builder(ScramClient.ChannelBinding channelBinding, StringPreparation stringPreparation, ScramMechanism nonChannelBindingMechanism, ScramMechanism channelBindingMechanism)
-
-
Method Detail
-
secureRandomAlgorithmProvider
public ScramClient.Builder secureRandomAlgorithmProvider(java.lang.String algorithm, java.lang.String provider) throws java.lang.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 vianonceSupplier(NonceSupplier)
). Algorithm and provider names are those supported by theSecureRandom
class.- Parameters:
algorithm
- The name of the algorithm to use.provider
- The name of the provider of SecureRandom. Might be null.- Returns:
- The same class
- Throws:
java.lang.IllegalArgumentException
- If algorithm is null, or either the algorithm or provider are not supported
-
nonceSupplier
public ScramClient.Builder nonceSupplier(NonceSupplier nonceSupplier) throws java.lang.IllegalArgumentException
Optional call. The client will use a default nonce generator, unless an external one is provided by this method. *- Parameters:
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:
- The same class
- Throws:
java.lang.IllegalArgumentException
- If nonceSupplier is null
-
nonceLength
public ScramClient.Builder nonceLength(int length) throws java.lang.IllegalArgumentException
Sets a non-default (ScramClient.DEFAULT_NONCE_LENGTH
) length for the nonce generation, if no alternate nonceSupplier is provided vianonceSupplier(NonceSupplier)
.- Parameters:
length
- The length of the nonce. Must be positive and greater than 0- Returns:
- The same class
- Throws:
java.lang.IllegalArgumentException
- If length is less than 1
-
setup
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 theScramClient.DEFAULT_NONCE_LENGTH
length, unlessnonceLength(int)
is called.- Returns:
- The fully built instance.
-
-