Package com.ongres.scram.client
Class ScramClient.Builder
java.lang.Object
com.ongres.scram.client.ScramClient.Builder
- All Implemented Interfaces:
ScramClient.FinalBuildStage
,ScramClient.MechanismsBuildStage
,ScramClient.PasswordBuildStage
,ScramClient.UsernameBuildStage
- Enclosing class:
ScramClient
static class ScramClient.Builder
extends Object
implements ScramClient.MechanismsBuildStage, ScramClient.UsernameBuildStage, ScramClient.PasswordBuildStage, ScramClient.FinalBuildStage
Builds instances of type
ScramClient
. Initialize attributes and then invoke
the build()
method to create an instance.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
private byte[]
private String
private Gs2CbindFlag
private byte[]
private String
private int
private char[]
private byte[]
private Collection
<String> private SecureRandom
private ScramMechanism
private byte[]
private StringPreparation
private String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadvertisedMechanisms
(Collection<String> scramMechanisms) List of the advertised mechanisms that will be negotiated between the server and the client.Sets the authzid.build()
Returns the fully contructed ScramClient ready to start the message flow with the server.channelBinding
(String cbindType, byte[] cbindData) If the client supports channel binding negotiation, this method sets the type and data used for channel binding.clientAndServerKey
(byte[] clientKey, byte[] serverKey) Sets the ClientKey/ServerKey.private ScramMechanism
nonceLength
(int length) Sets a non-default length for the nonce generation.nonceSupplier
(Supplier<String> nonceSupplier) The client will use a default nonce generator, unless an external one is provided by this method.password
(char[] password) Sets the password.saltedPassword
(byte[] saltedPassword) Sets the SaltedPassword.secureRandomAlgorithmProvider
(String algorithm, String provider) Selects a non-default SecureRandom instance, based on the given algorithm and optionally provider.private static ScramMechanism
selectMechanism
(Collection<String> scramMechanisms, boolean channelBinding) This method classifies SCRAM mechanisms by two properties: whether they support channel binding; and a priority, which is higher for safer algorithms (like SHA-256 vs SHA-1).stringPreparation
(StringPreparation stringPreparation) Sets the StringPreparation, is recommended to leave the default SASL_PREPARATION.Sets the username.
-
Field Details
-
selectedScramMechanism
-
scramMechanisms
-
channelBinding
-
stringPreparation
-
nonceLength
private int nonceLength -
nonce
-
secureRandom
-
username
-
password
private char[] password -
saltedPassword
private byte[] saltedPassword -
clientKey
private byte[] clientKey -
serverKey
private byte[] serverKey -
cbindType
-
cbindData
private byte[] cbindData -
authzid
-
nonceSupplier
-
-
Constructor Details
-
Builder
private Builder()
-
-
Method Details
-
stringPreparation
Description copied from interface:ScramClient.FinalBuildStage
Sets the StringPreparation, is recommended to leave the default SASL_PREPARATION.- Specified by:
stringPreparation
in interfaceScramClient.FinalBuildStage
- Parameters:
stringPreparation
- type of string preparation normalization- Returns:
this
builder for use in a chained invocation
-
channelBinding
Description copied from interface:ScramClient.FinalBuildStage
If the client supports channel binding negotiation, this method sets the type and data used for channel binding.- Specified by:
channelBinding
in interfaceScramClient.FinalBuildStage
- Parameters:
cbindType
- channel bynding type namecbindData
- channel binding data- Returns:
this
builder for use in a chained invocation
-
authzid
Description copied from interface:ScramClient.FinalBuildStage
Sets the authzid.- Specified by:
authzid
in interfaceScramClient.FinalBuildStage
- Parameters:
authzid
- the optional authorization id- Returns:
this
builder for use in a chained invocation
-
username
Description copied from interface:ScramClient.UsernameBuildStage
Sets the username.- Specified by:
username
in interfaceScramClient.UsernameBuildStage
- Parameters:
username
- the required username- Returns:
this
builder for use in a chained invocation
-
password
Description copied from interface:ScramClient.PasswordBuildStage
Sets the password.- Specified by:
password
in interfaceScramClient.PasswordBuildStage
- Parameters:
password
- the required password- Returns:
this
builder for use in a chained invocation
-
saltedPassword
Description copied from interface:ScramClient.PasswordBuildStage
Sets the SaltedPassword.- Specified by:
saltedPassword
in interfaceScramClient.PasswordBuildStage
- Parameters:
saltedPassword
- the required SaltedPassword- Returns:
this
builder for use in a chained invocation
-
clientAndServerKey
Description copied from interface:ScramClient.PasswordBuildStage
Sets the ClientKey/ServerKey.- Specified by:
clientAndServerKey
in interfaceScramClient.PasswordBuildStage
- Parameters:
clientKey
- the required ClientKeyserverKey
- the required ServerKey- Returns:
this
builder for use in a chained invocation
-
advertisedMechanisms
Description copied from interface:ScramClient.MechanismsBuildStage
List of the advertised mechanisms that will be negotiated between the server and the client.- Specified by:
advertisedMechanisms
in interfaceScramClient.MechanismsBuildStage
- Parameters:
scramMechanisms
- list with the IANA-registered mechanism name of this SASL client- Returns:
this
builder for use in a chained invocation
-
nonceLength
Description copied from interface:ScramClient.FinalBuildStage
Sets a non-default length for the nonce generation.The default value is 24. This call overwrites the length used for the client nonce.
- Specified by:
nonceLength
in interfaceScramClient.FinalBuildStage
- Parameters:
length
- The length of the nonce. Must be positive and greater than 0- Returns:
this
builder for use in a chained invocation
-
nonceSupplier
Description copied from interface:ScramClient.FinalBuildStage
The client will use a default nonce generator, unless an external one is provided by this method.- Specified by:
nonceSupplier
in interfaceScramClient.FinalBuildStage
- 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:
this
builder for use in a chained invocation
-
secureRandomAlgorithmProvider
Description copied from interface:ScramClient.FinalBuildStage
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. Algorithm and provider names are those supported by theSecureRandom
class.- Specified by:
secureRandomAlgorithmProvider
in interfaceScramClient.FinalBuildStage
- Parameters:
algorithm
- The name of the algorithm to useprovider
- The name of the provider of SecureRandom. Might be null- Returns:
this
builder for use in a chained invocation
-
build
Description copied from interface:ScramClient.FinalBuildStage
Returns the fully contructed ScramClient ready to start the message flow with the server.- Specified by:
build
in interfaceScramClient.FinalBuildStage
- Returns:
- ScramClient specific for the set of parameters
-
mechanismNegotiation
-
selectMechanism
private static ScramMechanism selectMechanism(Collection<String> scramMechanisms, boolean channelBinding) This method classifies SCRAM mechanisms by two properties: whether they support channel binding; and a priority, which is higher for safer algorithms (like SHA-256 vs SHA-1).- Parameters:
scramMechanisms
- The mechanisms supported by the other peerchannelBinding
- True to select-PLUS
mechanisms.- Returns:
- The selected mechanism, or null if no mechanism matched
-