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 final 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 TypeFieldDescription(package private) String
(package private) byte[]
(package private) String
(package private) Gs2CbindFlag
(package private) byte[]
(package private) String
(package private) int
(package private) char[]
(package private) byte[]
(package private) Collection
<String> (package private) SecureRandom
(package private) ScramMechanism
(package private) byte[]
(package private) StringPreparation
(package private) String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionadvertisedMechanisms
(@NotNull Collection<@NotNull 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
(@Nullable String cbindType, byte @Nullable [] cbindData) If the client supports channel binding negotiation, this method sets the type and data used for channel binding.clientAndServerKey
(byte @NotNull [] clientKey, byte @NotNull [] serverKey) Sets the ClientKey/ServerKey.private ScramMechanism
nonceLength
(int length) Sets a non-default length for the nonce generation.nonceSupplier
(@NotNull Supplier<@NotNull String> nonceSupplier) The client will use a default nonce generator, unless an external one is provided by this method.password
(char @NotNull [] password) Sets the password.saltedPassword
(byte @NotNull [] saltedPassword) Sets the SaltedPassword.secureRandomAlgorithmProvider
(@NotNull String algorithm, @Nullable String provider) Selects a non-default SecureRandom instance, based on the given algorithm and optionally provider.private static @Nullable ScramMechanism
selectMechanism
(@NotNull Collection<@NotNull 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
(@NotNull StringPreparation stringPreparation) Sets the StringPreparation, is recommended to leave the default SASL_PREPARATION.Sets the username.
-
Field Details
-
selectedScramMechanism
ScramMechanism selectedScramMechanism -
scramMechanisms
Collection<String> scramMechanisms -
channelBinding
Gs2CbindFlag channelBinding -
stringPreparation
StringPreparation stringPreparation -
nonceLength
int nonceLength -
nonce
String nonce -
secureRandom
SecureRandom secureRandom -
username
String username -
password
char[] password -
saltedPassword
byte[] saltedPassword -
clientKey
byte[] clientKey -
serverKey
byte[] serverKey -
cbindType
String cbindType -
cbindData
byte[] cbindData -
authzid
String authzid -
nonceSupplier
-
-
Constructor Details
-
Builder
private Builder()
-
-
Method Details
-
stringPreparation
public ScramClient.FinalBuildStage stringPreparation(@NotNull @NotNull StringPreparation 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
public ScramClient.FinalBuildStage channelBinding(@Nullable @Nullable String cbindType, byte @Nullable [] cbindData) 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
public ScramClient.FinalBuildStage clientAndServerKey(byte @NotNull [] clientKey, byte @NotNull [] serverKey) 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
public ScramClient.UsernameBuildStage advertisedMechanisms(@NotNull @NotNull Collection<@NotNull String> scramMechanisms) 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
public ScramClient.FinalBuildStage nonceSupplier(@NotNull @NotNull Supplier<@NotNull String> 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
public ScramClient.FinalBuildStage secureRandomAlgorithmProvider(@NotNull @NotNull String algorithm, @Nullable @Nullable String provider) 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
@Nullable private static @Nullable ScramMechanism selectMechanism(@NotNull @NotNull Collection<@NotNull 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
-