스프링 프레임워크에서 서비스의 기본 인증 부분을 테스트 하면서 로그인이 되지 않는 오류가 발생하였다.
이 문제는 어떻게 해결을 해야 할지 확인해 봤다.
이 문제를 참고 하기 위하여 아래 사이트를 참고 하였다.
https://songsunbi.tistory.com/33
java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null" 오류
스프링 시큐리티 5버전으로 넘어오면서 passwordEncoder가 생겼습니다. 아래와 같이 예전 방식으로 코딩하면 에러가 발생합니다. 패스워드 앞에 {noop}을 추가해주면 해결됩니다. id를 추가해야 보안
songsunbi.tistory.com
결국 나는 패스워드 앞에 몇글자 붙쳐서 해결을 하였다.
pw앞에 prefix를 붙여서 저장한다. "{noop}"
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("{noop}1234").roles("USER").and()
.withUser("admin").password("{noop}1234").roles("USER", "ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.httpBasic();
}
@Bean
public PasswordEncoder passwordEncoder() {
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
아래 포스트 되어 있는 글을 이제 읽으니 이해가 된다. 참고 하면 됩니다.
- PasswordEncoderFactories.createDelegatingPasswordEncoder()로 생성한 PasswordEncode는 BCryptPasswordEncoder가 사용되며 앞에 {id}로 PasswordEncoder 유형이 정의된다.
- 기본이 bcrypt이다.
- 정리하면, SpringSecurity가 로그인 과정에서 어떤 Encoder를 쓸지는 database에 저장된 password의 prefix { Encoder명 }를 보고 결정한다.
- 우리는 따로 설정을하지않았으니, SpringSecurity가 prefix를 보고 Enocder형식을 정해야 하는데, 이것조처 설정이 되어있지 않아서 에러가 난것이다.
https://taesan94.tistory.com/119
[SpringSecurity] java.lang.IllegalArgumentException: There is no PasswordEncoder mapped for the id "null"
참조 블로그 ! [ 참조링크 1 ] [ 허니몬(Honeymon)의 자바guru ] [ 참조링크 3 ] SpringSecurity를 적용하기위해서, 계정테이블에 ID : TEST, PW : 1234의 데이터를 직접 INSERT하였다. 이후에 로그인 form에서 로..
taesan94.tistory.com