전체 글(131)
-
Spring Security - CsrfFilter
CSRF(사이트간 요청 위조) 사용자가 쇼핑몰의 세션쿠키를 가지고 있기 때문에, 공격용 페이지에서 사용자 의도와는 상관없이 POST, PUT, PATCH, DELETE 요청이 전송될 수 있다. CsrfFilter CsrfFilter는 사용자에게 CSRF토큰을 발급해주고, 사용자가 POST, PUT, PATCH, DELETE 요청을 할 때, CSRF토큰을 가져와야 승인을 해주는 필터이다. Spring Security에서는 기본적으로 CSRF기능이 활성화 되어있다. http.csrf(): CSRF기능 활성화 http.csrf().disabled(): CSRF기능 비활성화
2021.04.16 -
Spring Security - 인증, 인가 예외 ExceptionTranslationFilter, AuthenticationException, AccessDeniedException
ExceptionTranslationFilter Spring Security는 두 가지 예외를 다룬다. AuthenticationException - 인증 예외, 인증에 실패할 경우 발생 AccessDeniedException - 인가 예외, 인가에 실패할 경우 발생 사용 예제 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 protected void configure(HttpSecurity http) throws Exception { http.exceptionHandling() .authenticationEntryPoint(new AuthenticationEntryPoint() { @Override public void commence(HttpServletRequest htt..
2021.04.16 -
Spring Security - 인가 API, URL 방식
사용 예제 1 2 3 4 5 6 7 8 9 10 11 12 @Override protected void configure(HttpSecurity http) throws Exception { http .antMatcher(“/shop/**”) .authorizeRequests() .antMatchers(“/shop/login”, “/shop/users/**”).permitAll() .antMatchers(“/shop/mypage”).hasRole(“USER”) .antMatchers("/shop/admin/pay").access("hasRole('ADMIN')") .antMatchers("/shop/admin/**").access("hasRole('ADMIN') or hasRole(‘SYS ')") .an..
2021.04.16 -
Spring Security - 세션 생성 정책, SessionCreationPolicy
사용 예제 1 http.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED); cs 정책 종류 SessionCreationPolicy. Always : 스프링 시큐리티가 항상 세션 생성 SessionCreationPolicy. If_Required : 스프링 시큐리티가 필요 시 생성(기본값) SessionCreationPolicy. Never : 스프링 시큐리티가 생성하지 않지만 이미 존재하면 사용 SessionCreationPolicy. Stateless : 스프링 시큐리티가 생성하지 않고 존재해도 사용하지 않음
2021.04.15 -
Spring Security - 세션 고정 보호 API
세션 고정 공격이란? 공격자가 서버에 접속하여 세션쿠키를 얻어낸뒤, 사용자에게 해당 세션쿠키를 심어둡니다. 이런 상황에서 사용자가 서버에 로그인 인증을 시도하게 되면 같은 세션쿠키를 사용하고 있기 때문에 사용자 정보를 공격자가 접근할 수 있는 상태가 됩니다. 세션 고정 보호 이를 방지하기 위해 사용자가 로그인 인증을 할 때, 세션 ID를 변경한다면 공격자와 사용자의 세션쿠키 정보가 달라지기 때문에 세션 고정 공격을 방지할 수 있습니다. 사용 예제 1 2 3 4 http.sessionManagement().sessionFixation().none(); http.sessionManagement().sessionFixation().changeSessionId(); http.sessionManagement()...
2021.04.15 -
Spring Security - 동시 세션 제어 API
사용 예제 1 2 3 4 5 6 http .sessionManagement() // 세션 관리 기능 동작 .maximumSessions(1) // 동시 세션 최대 갯수, -1일시, 무제한 허용 .maxSessionsPreventsLogin(false) // false이면 기존 세션 만료처리(default), true이면 인증하려는 세션 차단 .expiredUrl("/expired") // 세션 만료되면 이동할 URL ; Colored by Color Scripter cs 같은 계정으로 다른 PC 혹은 브라우저에서 로그인을 하면 Spring Security는 어떻게 동작할까? 두 가지 정책이 있다. 1. 기존 세션을 만료처리하여 새로 인증하려는 세션을 허용하는 정책(기본값) 2. 기존 세션은 그대로 유지하..
2021.04.15