Class ScramClient.Builder

    • Field Detail

      • scramMechanisms

        java.util.Collection<java.lang.String> scramMechanisms
      • 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
    • Constructor Detail

      • Builder

        private Builder()
    • Method Detail

      • channelBinding

        public ScramClient.FinalBuildStage channelBinding​(@Nullable
                                                          @Nullable java.lang.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 interface ScramClient.FinalBuildStage
        Parameters:
        cbindType - channel bynding type name
        cbindData - channel binding data
        Returns:
        this builder for use in a chained invocation
      • nonceLength

        public ScramClient.FinalBuildStage nonceLength​(int length)
        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 interface ScramClient.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 java.util.function.Supplier<@NotNull java.lang.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 interface ScramClient.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 java.lang.String algorithm,
                                                                         @Nullable
                                                                         @Nullable java.lang.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 the SecureRandom class.
        Specified by:
        secureRandomAlgorithmProvider in interface ScramClient.FinalBuildStage
        Parameters:
        algorithm - The name of the algorithm to use
        provider - The name of the provider of SecureRandom. Might be null
        Returns:
        this builder for use in a chained invocation
      • 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 -PLUS mechanisms.
        scramMechanisms - The mechanisms supported by the other peer
        Returns:
        The selected mechanism, or null if no mechanism matched