spring security
-
Spring Security 5 버전에서 6 버전으로 바뀌면서 변경된 내용중 SecurityContextHolder 에 관한 내용이 있어 공부하게 되었다. SecurityContext 사용자 인증 정보를 저장하고 있는 Authentication 객체를 저장하는 보관소이다. SecurityContextHolder 전략(Strategy)에 따라 SecurityContext 에 저장하는 방식이 다르며 일반적으로 ThreadLocal 에 저장한다. Authentication 인증 객체를 한 쓰레드에서 공유하므로 언제든지 불러와 사용할 수 있다. SecurityContextHolder SecurityContext 를 관리하고 저장하는 객체이다. SecurityContext 저장을 위해 ThreadLocal 를 가..
SecurityContext, SecurityContextHolderSpring Security 5 버전에서 6 버전으로 바뀌면서 변경된 내용중 SecurityContextHolder 에 관한 내용이 있어 공부하게 되었다. SecurityContext 사용자 인증 정보를 저장하고 있는 Authentication 객체를 저장하는 보관소이다. SecurityContextHolder 전략(Strategy)에 따라 SecurityContext 에 저장하는 방식이 다르며 일반적으로 ThreadLocal 에 저장한다. Authentication 인증 객체를 한 쓰레드에서 공유하므로 언제든지 불러와 사용할 수 있다. SecurityContextHolder SecurityContext 를 관리하고 저장하는 객체이다. SecurityContext 저장을 위해 ThreadLocal 를 가..
2024.02.23 -
기존 Spring Boot 2.7 이하버전, Spring Security 5.6 이전버전에서는 아래와 같이 설정했다. .authorizeRequests() 메서드를 통해 허용할 URL, formLogin() 메서드를 통해 로그인 설정 등 많이 바뀐건 아니지만 불필요한 소스를 삭제하고 간단하게 설정하는방법으로 바꼈다고 한다. Spring Security 5.6 이전버전 기존소스 @Configuration @EnableWebSecurity public class SecurityConfig{ @Autowired private AuthenticationUserDetailsService authenticationUserManager; @Bean public WebSecurityCustomizer configure..
Spring Boot 2.7 이상, Spring Security 5.6 이상버전 설정하기기존 Spring Boot 2.7 이하버전, Spring Security 5.6 이전버전에서는 아래와 같이 설정했다. .authorizeRequests() 메서드를 통해 허용할 URL, formLogin() 메서드를 통해 로그인 설정 등 많이 바뀐건 아니지만 불필요한 소스를 삭제하고 간단하게 설정하는방법으로 바꼈다고 한다. Spring Security 5.6 이전버전 기존소스 @Configuration @EnableWebSecurity public class SecurityConfig{ @Autowired private AuthenticationUserDetailsService authenticationUserManager; @Bean public WebSecurityCustomizer configure..
2023.07.11 -
Filter 와 Interceptor Interceptor 는 스프링 컨테이너 영역이므로 Spring 빈으로 등록이 가능하지만 Filter 는 서블릿 컨테이너의 영역이라서 Spring 의 빈으로 등록할 수 없다고 생각했다. 위 이미지와 같이 Filtre 는 서블릿 컨테이너의 영역에서 존재하고 서블릿이 제공하는 기술이며 스프링 컨테이너의 영역과는 분리되어 있다. 하지만 개발을 하게 되면 Filter 를 Spring 빈으로 등록하여 사용하는걸 볼 수 있다. 서블릿 컨테이너에서 관리되는 DelegatingFilterProxy 가 서블릿 컨테이너와 스프링 컨테이너를 연결할 수 있는 프록시용 필터이다. Spring Security Filter Spring Security 는 위 이미지와 같이 서블릿 Filter ..
Spring Security DelegatingFilterProxy(서블릿 컨테이너와 스프링 컨테이너의 다리 역할)Filter 와 Interceptor Interceptor 는 스프링 컨테이너 영역이므로 Spring 빈으로 등록이 가능하지만 Filter 는 서블릿 컨테이너의 영역이라서 Spring 의 빈으로 등록할 수 없다고 생각했다. 위 이미지와 같이 Filtre 는 서블릿 컨테이너의 영역에서 존재하고 서블릿이 제공하는 기술이며 스프링 컨테이너의 영역과는 분리되어 있다. 하지만 개발을 하게 되면 Filter 를 Spring 빈으로 등록하여 사용하는걸 볼 수 있다. 서블릿 컨테이너에서 관리되는 DelegatingFilterProxy 가 서블릿 컨테이너와 스프링 컨테이너를 연결할 수 있는 프록시용 필터이다. Spring Security Filter Spring Security 는 위 이미지와 같이 서블릿 Filter ..
2023.03.23 -
LogoutFilter 란? LogoutFilter는 Spring Security 에서 로그아웃에 대한 처리를 담당하는 필터로 사용자가 특정 로그아웃 URL로 로그아웃을 요청 했을 경우에만 적용되는 필터이다. LogoutFilter는 세션 무효화, 인증토큰 삭제 등 Security Context에서 해당 인증 객체를 삭제한다. 아래는 LogoutFilter 클래스와 doFilter 메서드이다. requiresLogout() 메서드를 통해 요청된 URL이 로그아웃 URL인지 확인한다. 아래는 requiresLogout 메서드이다. RequestMatcher 의 matches 를 통해 URL 정보를 확인하고 맞으면 true 를 리턴한다. 로그아웃 URL 이 맞을 경우SecurityContextHolder 에..
[Spring Security] LogoutFilterLogoutFilter 란? LogoutFilter는 Spring Security 에서 로그아웃에 대한 처리를 담당하는 필터로 사용자가 특정 로그아웃 URL로 로그아웃을 요청 했을 경우에만 적용되는 필터이다. LogoutFilter는 세션 무효화, 인증토큰 삭제 등 Security Context에서 해당 인증 객체를 삭제한다. 아래는 LogoutFilter 클래스와 doFilter 메서드이다. requiresLogout() 메서드를 통해 요청된 URL이 로그아웃 URL인지 확인한다. 아래는 requiresLogout 메서드이다. RequestMatcher 의 matches 를 통해 URL 정보를 확인하고 맞으면 true 를 리턴한다. 로그아웃 URL 이 맞을 경우SecurityContextHolder 에..
2023.02.17 -
Spring Security를 사용하여 커스텀 필터를 생성하지 않고 로그인 인증을 진행할때 AbstractAuthenticationProcessingFilter 를 상속받은 UsernamePasswordAuthenticationFilter 에 의해 진행된다. 본인은 AbstractAuthenticationProcessingFilter 를 직접 상속받아 커스텀 필터를 만들었다. 특정 계정이 로그인 되어 있는 상황에서 다른 브라우저에서 로그인을 진행하면 최대 세션 개수에 의해 로그아웃이 진행되었어야 했다. 설정은 아래와 같다. maximumSession(1) 설정에 의해 최대 세션 개수는 1개이고 maxSessionsPreventsLogin(false) 로 이전 사용자 만료 설정으로 설정했다. 이전 사용자 ..
Spring Security ConcurrentSessionControlAuthenticationStrategy 설정(동시세션제어 설정)Spring Security를 사용하여 커스텀 필터를 생성하지 않고 로그인 인증을 진행할때 AbstractAuthenticationProcessingFilter 를 상속받은 UsernamePasswordAuthenticationFilter 에 의해 진행된다. 본인은 AbstractAuthenticationProcessingFilter 를 직접 상속받아 커스텀 필터를 만들었다. 특정 계정이 로그인 되어 있는 상황에서 다른 브라우저에서 로그인을 진행하면 최대 세션 개수에 의해 로그아웃이 진행되었어야 했다. 설정은 아래와 같다. maximumSession(1) 설정에 의해 최대 세션 개수는 1개이고 maxSessionsPreventsLogin(false) 로 이전 사용자 만료 설정으로 설정했다. 이전 사용자 ..
2022.12.27 -
Spring Security 에서 세션 제어를 위해 인증 api를 추가해줘야 한다. 아래와 같이 HttpSecurity 의 .sessionManagement() 를 사용해 세션 관리 기능이 동작한다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest() .authenticated() .and() .formLogin() .and() .sessionManagement() .maximu..
Spring Security 정리하기 (#3 세션 제어)Spring Security 에서 세션 제어를 위해 인증 api를 추가해줘야 한다. 아래와 같이 HttpSecurity 의 .sessionManagement() 를 사용해 세션 관리 기능이 동작한다. @Configuration @EnableWebSecurity public class SecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest() .authenticated() .and() .formLogin() .and() .sessionManagement() .maximu..
2022.12.23