부트 3.0 참조: https://nahwasa.com/entry/스프링부트-30이상-Spring-Security-기본-세팅-스프링-시큐리티
filter 순서 참조: https://velog.io/@ewan/Spring-Security-Custom-Authentication-Provider
프로젝트 참조: https://velog.io/@dailylifecoding/Spring-Security-Custom-Form-Login-practice-2
gradle
implementation: 'org.springframework.boot:spring-boot-starter-security'
HttpSecurity Config
security설정은 기본적으로 WebSecurityConfigurerAdapter를 구현하고 해당 객체의 메서드를 재정의해서 config를 설정
CSRF
.csrf().disable()
를 통해 csrf를 비활성화.antMatchers()
permitAll()
: antMatchers()
메서드에 나열된 URL에 대해 모든 사용자의 접근 허용.authenticated()
: antMatchers()
메서드네 나열된 URL에 대해 인증된 사용자의 접근만 허용.anyRequest()
는 antMatchers()
에서 작성되지 않은 URL모두 포함.formLogin()
.loginPage()
기본적으로 기본 form을 제공하지만 커스텀 form을 사용하는 경우 사용.loginProcessingUrl()
해당 URL로 POST요청을 하면 시큐리티가 가로채서 로그인 처리.successHandler()
로그인 성공시 핸들러(SimpleUrlAuthenticationSuccessHandler 구현체 등록).failureHadler()
로그인 실패시 핸들러(SimpleUrlAuthenticationFailureHandler 구현체 등록).logout()
.logoutRequestMatcher(new AntPathRequestMatcher())
로그아웃 URL 등록.logoutSuccessUrl()
로그아웃 성공시 Redirect URL 작성.invalidateHttpSession()
인증정보, 세션을 무효화(boolean 타입).deleteCookies()
특정 쿠키를 삭제(key를 전달)sessionManagement()
.maximumSessions()
세션 최대 허용 수(-1인 경우 무제한 세션).maxSessionPreventsLogin()
true → 중복 로그인 제한/false → 이전 로그인 세션 해체.expireUrl()
세션이 만료된 경우 이동 할 페이지.rememberMe()
.alwaysRemember()
true → 항상 기억 / false → 항상 기억하지 않음.tokenValiditySeconds()
저장 시간(초단위).rememberMe()
전달한 키 값으로 저장.userDetailsService()
기능을 사용할 때 사용자 정보AuthenticationManagerBuilder Config
loadUserByUsername()
메서드를 활용SecurityContextHolder