javaspring-boot

AuthenticationManager in Spring Boot


I have an assignment where I have to make an authentication system with passwords hashed and salted with SHA256. I've noticed there isn't a SHA password encoder implementation that I can see, so ive made my own.

I've made filters before for authentication when WebSecurityConfigurerAdapter was a thing, using the AuthenticationManager from there, but now that its deprecated, is there a default AuthenticationManager that can be injected into my custom filter?

The old way you could do it

    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception{
        return super.authenticationManagerBean();
    }

Solution

  • You can expose AuthenticationManager as a bean in many ways, for example:

    @Bean
    public AuthenticationManager authenticationManager(AuthenticationConfiguration authenticationConfiguration) throws Exception {
        return authenticationConfiguration.getAuthenticationManager();
    }
    

    Another:

    @Bean
    public AuthenticationManager authenticationManager(AuthenticationManagerBuilder authenticationManagerBuilder) {
        return authenticationManagerBuilder.getOrBuild();
    }