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 ScramMechanismnonceLength(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 ScramMechanismselectMechanism(@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.FinalBuildStageSets the StringPreparation, is recommended to leave the default SASL_PREPARATION.- Specified by:
stringPreparationin interfaceScramClient.FinalBuildStage- Parameters:
stringPreparation- type of string preparation normalization- Returns:
thisbuilder for use in a chained invocation
-
channelBinding
public ScramClient.FinalBuildStage channelBinding(@Nullable @Nullable String cbindType, byte @Nullable [] cbindData) Description copied from interface:ScramClient.FinalBuildStageIf the client supports channel binding negotiation, this method sets the type and data used for channel binding.- Specified by:
channelBindingin interfaceScramClient.FinalBuildStage- Parameters:
cbindType- channel bynding type namecbindData- channel binding data- Returns:
thisbuilder for use in a chained invocation
-
authzid
Description copied from interface:ScramClient.FinalBuildStageSets the authzid.- Specified by:
authzidin interfaceScramClient.FinalBuildStage- Parameters:
authzid- the optional authorization id- Returns:
thisbuilder for use in a chained invocation
-
username
Description copied from interface:ScramClient.UsernameBuildStageSets the username.- Specified by:
usernamein interfaceScramClient.UsernameBuildStage- Parameters:
username- the required username- Returns:
thisbuilder for use in a chained invocation
-
password
Description copied from interface:ScramClient.PasswordBuildStageSets the password.- Specified by:
passwordin interfaceScramClient.PasswordBuildStage- Parameters:
password- the required password- Returns:
thisbuilder for use in a chained invocation
-
saltedPassword
Description copied from interface:ScramClient.PasswordBuildStageSets the SaltedPassword.- Specified by:
saltedPasswordin interfaceScramClient.PasswordBuildStage- Parameters:
saltedPassword- the required SaltedPassword- Returns:
thisbuilder for use in a chained invocation
-
clientAndServerKey
public ScramClient.FinalBuildStage clientAndServerKey(byte @NotNull [] clientKey, byte @NotNull [] serverKey) Description copied from interface:ScramClient.PasswordBuildStageSets the ClientKey/ServerKey.- Specified by:
clientAndServerKeyin interfaceScramClient.PasswordBuildStage- Parameters:
clientKey- the required ClientKeyserverKey- the required ServerKey- Returns:
thisbuilder for use in a chained invocation
-
advertisedMechanisms
public ScramClient.UsernameBuildStage advertisedMechanisms(@NotNull @NotNull Collection<@NotNull String> scramMechanisms) Description copied from interface:ScramClient.MechanismsBuildStageList of the advertised mechanisms that will be negotiated between the server and the client.- Specified by:
advertisedMechanismsin interfaceScramClient.MechanismsBuildStage- Parameters:
scramMechanisms- list with the IANA-registered mechanism name of this SASL client- Returns:
thisbuilder for use in a chained invocation
-
nonceLength
Description copied from interface:ScramClient.FinalBuildStageSets 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:
nonceLengthin interfaceScramClient.FinalBuildStage- Parameters:
length- The length of the nonce. Must be positive and greater than 0- Returns:
thisbuilder for use in a chained invocation
-
nonceSupplier
public ScramClient.FinalBuildStage nonceSupplier(@NotNull @NotNull Supplier<@NotNull String> nonceSupplier) Description copied from interface:ScramClient.FinalBuildStageThe client will use a default nonce generator, unless an external one is provided by this method.- Specified by:
nonceSupplierin 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:
thisbuilder for use in a chained invocation
-
secureRandomAlgorithmProvider
public ScramClient.FinalBuildStage secureRandomAlgorithmProvider(@NotNull @NotNull String algorithm, @Nullable @Nullable String provider) Description copied from interface:ScramClient.FinalBuildStageSelects 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 theSecureRandomclass.- Specified by:
secureRandomAlgorithmProviderin interfaceScramClient.FinalBuildStage- Parameters:
algorithm- The name of the algorithm to useprovider- The name of the provider of SecureRandom. Might be null- Returns:
thisbuilder for use in a chained invocation
-
build
Description copied from interface:ScramClient.FinalBuildStageReturns the fully contructed ScramClient ready to start the message flow with the server.- Specified by:
buildin 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-PLUSmechanisms.- Returns:
- The selected mechanism, or null if no mechanism matched
-