인증되지 않은 사용자가 로그인 정보 쿠키를 가지고 있다면 자동으로 인증처리를 해주는 기능을 담당하고 이를 통해 Authentication 인터페이스 구현체인 RememberMeAuthenticationToken를 갖게 된다.
private void doFilter(HttpServletRequest request, HttpServletResponse response, FilterChain chain)
throws IOException, ServletException {
...
Authentication rememberMeAuth = this.rememberMeServices.autoLogin(request, response);
...
}
사용자의 SecurityContext를 가져오거나 갱신하는 역할을 하고 인증 관련 필터 중 가장 최상단에 위치한다. 현재는 deprecated 되었고 SecurityContextHolderFilter 사용으로 대체 되었다.
세션 하이재킹 기법중 하나로 정상 사용자의 세션을 탈취하여 인증을 우회하는 기법인 session-fixation attack을 방지하기 위한 필터로 Spring Security에서는 4가지 설정 가능한 옵션을 제공한다.
@Override
protected void configure(HttpSecurity http) throws Exception {
http
/**
* 세션 관련 설정
*/
.sessionManagement()
.sessionFixation().changeSessionId()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.invalidSessionUrl("/")
.maximumSessions(1)
.maxSessionsPreventsLogin(false)
.and()
.and()
;
}
인증된 사용자 중 특정 권한이 부여된 사용자에게 특저 기능 또는 데이터에 접근을 허용하는 기능으로 우선 인증된 사용자와 권한을 매핑하고 보호되는 리소스에 대한 권한을 확인하는 방식으로 동작한다.
SpEL 표현식을 사용해 접근 승인 여부에 대한 규칙을 지정할 수 있다.
표현식 | 설명 |
---|---|
hasIpAddress(ipAddress) | 요청 IP 주소가 특정 IP 주소 또는 특정 대역에 해당하는지 확인 |
hasRole(String role) | 사용자가 특정 role을 갖고 있는지 확인 |
hasAnyRole(String… roles) | 사용자가 주어진 role 목록 중 매칭되는 role을 갖고 있는지 확인 |
hasAnyRole(String… roles) | 사용자가 주어진 role 목록 중 매칭되는 role을 갖고 있는지 확인 |
hasAuthority(String authority) | 사용자가 특정 권한을 갖고 있는지 확인 |
hasAnyAuthority(String… authorities) | 사용자가 주어진 권한 목록 중 매칭되는 권한을 갖고 있는지 확인 |
permitAll | 모든 사용자에 대해 접근 허용 |
denyAll | 모든 사용자에 대해 접근 거부 |
isAnonymous() | 사용자가 익명 사용자인지 확인 |
isRememberMe() | 사용자가 remember-me 를 통해 인증되었는지 확인 |
isAuthenticated() | 사용자가 인증되었는지 확인 |
isFullyAuthenticated() | 사용자가 익명 사용자가 아니고, remember-me 인증 사용자도 아닌지 확인 |
http
// ... 생략 ...
.authorizeRequests()
.antMatchers("/me").hasAnyRole("USER", "ADMIN")
.antMatchers("/admin").access("isFullyAuthenticated() and hasRole('ADMIN') and oddAdmin")
.anyRequest().permitAll()
.expressionHandler(new CustomWebSecurityExpressionHandler(new AuthenticationTrustResolverImpl(), "ROLE_"))
.and()
// ... 생략 ...