
Spring Security - PasswordEncoder Domain 로직의 {noop} + password 를 passwordEncoder에게 역할을 위임 하도록 한다. PasswordEncoder 를 빈으로 등록하기 SpringSecurity 5 이전 버전에서 사용하던 NoOpPasswordEncoder 를 빈으로 등록한다. Deprecated 되어 권장하지 않는 방법이다. PasswordEncoder 적용하기 PasswordEncoder를 주입받아 Account 로 넘겨준뒤 인코딩 작업을 진행한다. AccountService 기존의 {noop} + passwordEncoder 로 인코딩 작업을 해주던 로직을 passwordEncoder를 사용하는 방식으로 변경한다. Account 테스트 pass..

Spring Security - JPA 연동하기 InMemoryUser 방식은 문제점이 존재하기때문에 DATABASE와 연동하는 방법을 사용한다. 방법이 다양하지만 그중에서도 JPA와 연동하는 방법을 사용한다. 의존성 추가하기 JPA 의존성을 추가하고, DATABASE는 h2 를 사용하도록 한다. Account User 정보에 해당하는 Account Entity 를 생성한다. username은 유일한 값이기 때문에 Unique 제약조건을 걸어준다. JpaRepository 를 상속받는 AccountRepository 를 생성해준다. 기본적인 CRUD, Paging 관련 구현이 모두 끝난다. 또한 추가적으로 username으로 조회를 해야하기때문에 username으로 조회하는 namedQuery Metho..

Spring Security - InMemory User 사용하기 시큐리티가 기본적으로 생성해주는 User를 사용하는것이 아닌 우리가 직접 생성한 유저정보를 사용하도록 설정한다. 기본 시큐리티 유저 커스터마이징 하기 스프링 부트 애플리케이션을 실행하면 다음과 같이 Log에 매번 새로운 비밀번호가 설정된 것이 남는다. 이러한 자동 설정은 어디서 오는것일까 ? 로그에서 그 힌트를 제공하고 있다. UserDetailsServiceAutoConfiguration UserDetailsServiceAutoConfiguration 다음은 우리가 Log에서 힌트를 얻었던 UserDetailsServiceAutoConfiguration 클래스이다. 이중에서 유심히 살펴봐야 할것은 inMemoryUserDetailsMan..

Spring Security - Security 설정하기 스프링 시큐리티 설정을 적용한다. 부트가 제공하는 자동설정 외에 커스터마이징을 진행한다. 설정파일 config/SecurityConfig 클래스를 생성한다. @Configuration 애노테이션으로 설정 클래스 임을 스프링에게 알려준다. @EnableWebSecurity WebSecurity 적용을 알린다. 기존의 스프링부트가 제공하던 자동설정들은 모두 무시 된다. WebSecurityConfigurerAdapter 스프링 시큐리티 설정을 편리하게 하기위한 클래스이다. 시큐리티 설정은 주로 WebSecurityConfigurerAdapter 의 Method를 Override 하는 방식으로 한다. 시큐리티 설정 HttpSecurity를 활용하여 설정..