From e9ee1a54661471f05c0541c6299a69e385018421 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 11 Aug 2019 23:44:42 +0530 Subject: [PATCH] [BAEL-15958] - Added password encoder --- .../org/baeldung/config/WebSecurityConfig.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java b/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java index 0b6cd34f3e..df7c7d1611 100644 --- a/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java +++ b/spring-security-core/src/main/java/org/baeldung/config/WebSecurityConfig.java @@ -1,12 +1,15 @@ package org.baeldung.config; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; @Configuration @EnableWebSecurity @@ -21,8 +24,13 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication() - .withUser("jim").password("jim").roles("USER", "ACTUATOR") - .and().withUser("pam").password("pam").roles("USER") - .and().withUser("michael").password("michael").roles("MANAGER"); + .withUser("jim").password(passwordEncoder().encode("jim")).roles("USER", "ACTUATOR") + .and().withUser("pam").password(passwordEncoder().encode("pam")).roles("USER") + .and().withUser("michael").password(passwordEncoder().encode("michael")).roles("MANAGER"); + } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); } }