Quantcast
Viewing latest article 15
Browse Latest Browse All 3630

No default password encoder configured

@Configuration@EnableWebSecurity@Slf4jpublic class SecurityConfig {    @Bean    public PasswordEncoder passwordEncoder()    {        return PasswordEncoderFactories.createDelegatingPasswordEncoder();    }    @Bean    public AuthenticationManager authenticationManage(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) throws Exception {        DaoAuthenticationProvider provider = new DaoAuthenticationProvider();        provider.setUserDetailsService(userDetailsService);        provider.setPasswordEncoder(passwordEncoder);        return new ProviderManager(provider);    }    @Bean    public JwtAuthenticationFilter jwtAuthenticationFilter(AuthenticationService authenticationService)    {        return new JwtAuthenticationFilter(authenticationService);    }    @Bean    public UserDetailsService userDetailsService(PasswordEncoder passwordEncoder, UserRepository userRepository)    {        BlogUserDetailsService userDetailsService = new BlogUserDetailsService(userRepository);        String email = "user@gmail.com";        String encodedPassword = passwordEncoder.encode("password");        userRepository.findByEmail(email).orElseGet(() -> {            User newUser = User.builder()                    .name("user")                    .email(email)                    .password(encodedPassword)                    .build();            return userRepository.save(newUser);        });        return userDetailsService;    }    @Bean    public SecurityFilterChain securityFilterChain(HttpSecurity http, JwtAuthenticationFilter jwtAuthenticationFilter) throws Exception    {        http                .authorizeHttpRequests(auth -> auth                        .requestMatchers(HttpMethod.POST, "/api/v1/auth/login").permitAll()                        .requestMatchers(HttpMethod.GET, "/api/v1/categories/**").permitAll()                        .requestMatchers(HttpMethod.GET, "/api/v1/posts/**").permitAll()                        .requestMatchers(HttpMethod.GET, "/api/v1/tags/**").permitAll()                        .anyRequest().authenticated())                .addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)                .csrf(AbstractHttpConfigurer::disable)                .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS));        return http.build();    }}

In above security config class, I have created password Encoder bean and also a default user in userDetailsService bean with encoded password. But, when i try to login with the default user email and password from "Postman". I get "Bad Request Error(400)", with error message that says the following:

"Given that there is no default password encoder configured, each password must have a password encoding prefix. Please either prefix this password with '{noop}' or set a default password encoder in `DelegatingPasswordEncoder`."

Why?


Viewing latest article 15
Browse Latest Browse All 3630

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>