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 java.lang.Object implements ScramClient.MechanismsBuildStage, ScramClient.UsernameBuildStage, ScramClient.PasswordBuildStage, ScramClient.FinalBuildStage
Builds instances of typeScramClient. Initialize attributes and then invoke thebuild()method to create an instance.
-
-
Field Summary
Fields Modifier and Type Field Description (package private) java.lang.Stringauthzid(package private) byte[]cbindData(package private) java.lang.StringcbindType(package private) Gs2CbindFlagchannelBinding(package private) byte[]clientKey(package private) java.lang.Stringnonce(package private) intnonceLength(package private) java.util.function.Supplier<java.lang.String>nonceSupplier(package private) char[]password(package private) byte[]saltedPassword(package private) java.util.Collection<java.lang.String>scramMechanisms(package private) java.security.SecureRandomsecureRandom(package private) ScramMechanismselectedScramMechanism(package private) byte[]serverKey(package private) StringPreparationstringPreparation(package private) java.lang.Stringusername
-
Constructor Summary
Constructors Modifier Constructor Description privateBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ScramClient.UsernameBuildStageadvertisedMechanisms(@NotNull java.util.Collection<@NotNull java.lang.String> scramMechanisms)List of the advertised mechanisms that will be negotiated between the server and the client.ScramClient.FinalBuildStageauthzid(@NotNull java.lang.String authzid)Sets the authzid.ScramClientbuild()Returns the fully contructed ScramClient ready to start the message flow with the server.ScramClient.FinalBuildStagechannelBinding(@Nullable java.lang.String cbindType, byte @Nullable [] cbindData)If the client supports channel binding negotiation, this method sets the type and data used for channel binding.ScramClient.FinalBuildStageclientAndServerKey(byte @NotNull [] clientKey, byte @NotNull [] serverKey)Sets the ClientKey/ServerKey.private ScramMechanismmechanismNegotiation()ScramClient.FinalBuildStagenonceLength(int length)Sets a non-default length for the nonce generation.ScramClient.FinalBuildStagenonceSupplier(@NotNull java.util.function.Supplier<@NotNull java.lang.String> nonceSupplier)The client will use a default nonce generator, unless an external one is provided by this method.ScramClient.FinalBuildStagepassword(char @NotNull [] password)Sets the password.ScramClient.FinalBuildStagesaltedPassword(byte @NotNull [] saltedPassword)Sets the SaltedPassword.ScramClient.FinalBuildStagesecureRandomAlgorithmProvider(@NotNull java.lang.String algorithm, @Nullable java.lang.String provider)Selects a non-default SecureRandom instance, based on the given algorithm and optionally provider.private static @Nullable ScramMechanismselectMechanism(@NotNull java.util.Collection<@NotNull java.lang.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).ScramClient.FinalBuildStagestringPreparation(@NotNull StringPreparation stringPreparation)Sets the StringPreparation, is recommended to leave the default SASL_PREPARATION.ScramClient.PasswordBuildStageusername(@NotNull java.lang.String username)Sets the username.
-
-
-
Field Detail
-
selectedScramMechanism
ScramMechanism selectedScramMechanism
-
scramMechanisms
java.util.Collection<java.lang.String> scramMechanisms
-
channelBinding
Gs2CbindFlag channelBinding
-
stringPreparation
StringPreparation stringPreparation
-
nonceLength
int nonceLength
-
nonce
java.lang.String nonce
-
secureRandom
java.security.SecureRandom secureRandom
-
username
java.lang.String username
-
password
char[] password
-
saltedPassword
byte[] saltedPassword
-
clientKey
byte[] clientKey
-
serverKey
byte[] serverKey
-
cbindType
java.lang.String cbindType
-
cbindData
byte[] cbindData
-
authzid
java.lang.String authzid
-
nonceSupplier
java.util.function.Supplier<java.lang.String> nonceSupplier
-
-
Method Detail
-
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 java.lang.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
public ScramClient.FinalBuildStage authzid(@NotNull @NotNull java.lang.String 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
public ScramClient.PasswordBuildStage username(@NotNull @NotNull java.lang.String 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
public ScramClient.FinalBuildStage password(char @NotNull [] 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
public ScramClient.FinalBuildStage saltedPassword(byte @NotNull [] 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 java.util.Collection<@NotNull java.lang.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
public ScramClient.FinalBuildStage nonceLength(int length)
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 java.util.function.Supplier<@NotNull java.lang.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 java.lang.String algorithm, @Nullable @Nullable java.lang.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
public ScramClient 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
private ScramMechanism mechanismNegotiation()
-
selectMechanism
@Nullable private static @Nullable ScramMechanism selectMechanism(@NotNull @NotNull java.util.Collection<@NotNull java.lang.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:
channelBinding- True to select-PLUSmechanisms.scramMechanisms- The mechanisms supported by the other peer- Returns:
- The selected mechanism, or null if no mechanism matched
-
-