Skip to content

Avoid eager PasswordEncoder initialization in ClientSecretAuthenticationProvider #19783

Description

@alexey-anufriev

ClientSecretAuthenticationProvider eagerly initializes its default PasswordEncoder using PasswordEncoderFactories.createDelegatingPasswordEncoder()
in its constructor.

This factory creates legacy MessageDigestPasswordEncoder instances, including MD5. On a FIPS-compliant JDK where MD5 is unavailable, constructing ClientSecretAuthenticationProvider fails even
when a custom FIPS-compatible PasswordEncoder is configured.

encoders.put("MD5", new org.springframework.security.crypto.password.MessageDigestPasswordEncoder("MD5"));

This is similar to the issue discussed in gh-14670.

DaoAuthenticationProvider already avoids this problem by lazily initializing its default PasswordEncoder using SingletonSupplier.

private Supplier<PasswordEncoder> passwordEncoder = SingletonSupplier

I would like to suggest to apply the same pattern to ClientSecretAuthenticationProvider, preserving the existing public API and default behavior while avoiding construction of the default encoder
when setPasswordEncoder() is used.

I would be happy to submit a PR if this approach sounds correct.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions