스터디-Spring 27

[스프링 시큐리티] ExceptionTranslationFilter - 예외 처리 필터

https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/reference/htmlsingle/#exceptiontranslationfilter Spring Security Reference The authenticator is also responsible for retrieving any required user attributes. This is because the permissions on the attributes may depend on the type of authentication being used. For example, if binding as the user, it may be necessary to read them docs..

스터디-Spring 2022.02.15

[스프링 시큐리티] UsernamePasswordAuthenticationFilter - Form 인증 처리 필터

폼 로그인을 처리하는 필터 form에 입력한 username과 password로 AuthenticationToken을 만들고, AuthenticationManager를 통해 인증을 시도 AuthenticationManager(구현체: ProviderManager)는 여러 AuthenticationProvider를 이용하여 인증을 시도 한다 그 구현체 중 DaoAuthenticationProvider는 UserDetailsService를 이용하여 UserDetails를 가져오고, 사용자가 입력한 password와 비교하여 인증을 처리한다.

스터디-Spring 2022.02.09

[스프링 시큐리티] LogoutFilter - 로그아웃 처리 필터

LogoutHandler (Composite 객체 - 여러개의 LogoutHandler를 사용하고 있다) LogoutSuccessHandler (Logout을 성공한 다음 처리를 위한 객체) - 기본 객체 SimpleUrlLogoutSuccessHandler logout process LogoutFilter -> CompositeLogoutHandler(LogoutHandler 여러개를 갖고있음) -> csrf 사용시 csrf token을 null로 변경(CsrfLogoutHandler) -> session을 invalidate함(초기화), 그리고 SecurityContextHolder를 비움 (SecurityContextLogoutHandler) HttpSecurity config에서의 logout설정..

스터디-Spring 2022.02.08

[스프링 시큐리티] CsrfFilter - CSRF 공격 방지

CSRF(Cross-site Request Forgery) - 사이트 간 요청 위조 https://ko.wikipedia.org/wiki/%EC%82%AC%EC%9D%B4%ED%8A%B8_%EA%B0%84_%EC%9A%94%EC%B2%AD_%EC%9C%84%EC%A1%B0%EF%BB%BF 사이트 간 요청 위조 - 위키백과, 우리 모두의 백과사전 ko.wikipedia.org 과정 1. 이용자는 웹사이트에 로그인하여 정상적인 쿠키를 발급(인증을 받은 상태라는 뜻) 2. 공격자가 메일로 다음과 같이 코드를 심어 보냄 위의 URL은 패스워드를 변경하는 URL이고 인증이 되어있어야만 접근가능 3. 이용자가 메일을 읽으면 브라우저는 이미지 파일을 받아오기 위해 위의 URL을 조회함 4. 이용자의 브라우저는 인증이..

스터디-Spring 2022.02.07

[스프링 시큐리티] HeaderWriterFilter

기본적으로 5개의 header writer 적용 XContentTypeOptionsHeaderWriter: MIME타입 스니핑 방어 X-Content-Type-Options: nosniff https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options XXssProtectionHeaderWriter: 브라우저에 내장된 XSS 필터 적용 X-XSS-Protection: 1; mode=block https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection CacheControlHeadersWriter: 캐시 히스토리 취약점 방어 Cache-Control:..

스터디-Spring 2022.01.30

[스프링 시큐리티] SecurityContextPersistenceFilter

SecurityContextRepository를 사용하여 Repository 전략에 맞게 SecurityContext를 읽어오거나 초기화 기본 전략은 HttpSessionSecurityContextRepository - HttpSession을 사용한다 This filter MUST be executed BEFORE any authentication processing mechanisms. Authentication processing mechanisms (e.g. BASIC, CAS processing filters etc) expect the SecurityContextHolder to contain a valid SecurityContext by the time they execute. 기본적으로 인..

스터디-Spring 2022.01.30

[스프링 시큐리티] @Async & WebAsyncManagerIntegrationFilter

Async 웹 MVC를 지원하는 필터 스프링 MVC의 Async 기능(핸들러에서 Callable을 리턴할 수 있는 기능)을 사용할 때에도 SecurityContext를 공유하도록 도와주는 필터 해당 필터는 AsyncManager에 Interceptor를 등록하고 핵심 기능은 SecurityContextCallableProcessingInterceptor 에서 구현 PreProcess: SecurityContext를 설정 Callable: 다른 쓰레드이지만 그 안에서는 동일한 SecurityContext를 참조할 수 있음 PostProcess: SecurityContext를 clear @Async를 사용하는 서비스를 호출하는 경우, Thread가 다르기 때문에 SecurityContext를 공유받지 못한다..

스터디-Spring 2022.01.21

[스프링 시큐리티] 스프링 시큐리티 아키텍처 정리

AbstractSecurityWebApplicationInitializer 또는 SecurityFilterAutoConfiguration로 자동으로 DeligatingFilterProxy를 등록 요청을 FilterChainProxy로 위임함 Filter들은 WebSecurity, HttpSecurity를 통해 만들어짐 The WebSecurity is created by WebSecurityConfiguration to create the FilterChainProxy known as the Spring Security Filter Chain (springSecurityFilterChain). The springSecurityFilterChain is the Filter that the Delegatin..

스터디-Spring 2022.01.17

[스프링 시큐리티] ExceptionTranslationFilter

필터 체인에서 발생하는 AccessDeniedException과 AuthenticationException을 처리하는 필터 private void handleAccessDeniedException(HttpServletRequest request, HttpServletResponse response, FilterChain chain, AccessDeniedException exception) throws ServletException, IOException { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); boolean isAnonymous = this.authenticationTrustResol..

스터디-Spring 2022.01.17