강의를 들으며 내가 알고 있는 내용을 점검하고,
새로 배운 내용을 정리하며,
궁금한 내용을 알아가며 학습해나가는 것을 목표로 합니다.
인증되지 않은 사용자의 HTTP 요청이 remember-me 쿠키(Cookie)를 갖고 있다면, 사용자를 자동으로 인증처리 하는 필터입니다.
실제 사용자 인증은 RememberMeServices 인터페이스 구현체를 통해 처리됩니다.
MD5 해시 알고리즘 기반 쿠키 검증을 담당합니다.
외부 데이터베이스에서 인증에 필요한 데이터를 가져오고 검증합니다.
사용자마다 고유의 Series 식별자가 생성되고, 인증 시 마다 매번 갱신되는 임의의 토큰 값을 사용하여 보다 높은 보안성을 제공합니다.
remember-me 기반 Authentication 인터페이스 구현체입니다.
RememberMeAuthenticationToken 객체는 언제나 인증이 완료된 상태에만 존재합니다.
RememberMeAuthenticationToken 기반 인증 처리를 위한 AuthenticationProvider입니다.
앞서 remember-me 설정 시 입력한 key 값을 검증합니다.
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
if (!supports(authentication.getClass())) {
return null;
}
if (this.key.hashCode() != ((RememberMeAuthenticationToken) authentication).getKeyHash()) {
throw new BadCredentialsException(this.messages.getMessage("RememberMeAuthenticationProvider.incorrectKey",
"The presented RememberMeAuthenticationToken does not contain the expected key"));
}
return authentication;
}
명시적인 로그인 아이디/비밀번호 기반 인증 사용와 권한을 구분합니다.
remember-me 기반 인증과 로그인 아이디/비밀번호 기반 인증 결과가 명백히 다르다는 것에 주목해야 합니다.
@Override
public final boolean isFullyAuthenticated() {
return !this.trustResolver.isAnonymous(this.authentication)
&& !this.trustResolver.isRememberMe(this.authentication);
}
SecurityContextRepository 인터페이스 구현체를 통해 사용자의 SecurityContext를 가져오거나 갱신합니다.
인증 관련 필터 중 가장 최상단에 위치합니다.
이미 인증된 사용자는 다시 로그인할 필요가 없습니다.
SecurityContext가 존재하지 않는다면, empty SecurityContext를 생성합니다.
SecurityContextRepository 인터페이스 기본 구현은 Session을 이용하는 HttpSessionSecurityContextRepository 클래스입니다.
session-fixation attack — 세션 하이재킹 기법중 하나로 정상 사용자의 세션을 탈취하여 인증을 우회하는 기법
Spring Security에서는 4가지 설정 가능한 옵션을 제공합니다.
유효하지 않은 세션 감지 시 지정된 URL로 리다이렉트 시킵니다.
세션 생성 전략 설정
@Override
protected void configure(HttpSecurity http) throws Exception {
http
/**
* 세션 관련 설정
*/
.sessionManagement()
.sessionFixation().changeSessionId()
.sessionCreationPolicy(SessionCreationPolicy.IF_REQUIRED)
.invalidSessionUrl("/")
.maximumSessions(1)
.maxSessionsPreventsLogin(false)
.and()
.and()
;
}
AbstractAuthenticationProcessingFilter 객체는 SessionManagementFilter와 동일한 세션 고정 보호, 최대 로그인 세션 제어를 수행합니다.
인가(Authorization)란 어플리케이션 보안을 이해하는데 두 번째로 중요한 핵신 개념으로(다른 하나는 인증) 권한이 부여된 사용자들만 특정 기능 또는 데이터에 접근을 허용하는 기능입니다.
이를 위해 인가 처리는 두 개의 작업으로 구분됩니다.
Spring Security 3.0 — Dmitry Noskov
사용자가 갖고 있는 권한과 리소스에서 요구하는 권한을 확인하고, 사용자가 적절한 권한을 갖고 있지 않다면 접근 거부 처리합니다.
각각의 AccessDecisionVoter는 접근을 승인할지 거절할지 혹은 보류할지 판단합니다. (vote 메소드)
int ACCESS_GRANTED = 1;
int ACCESS_ABSTAIN = 0;
int ACCESS_DENIED = -1;
int vote(Authentication authentication, S object, Collection<ConfigAttribute> attributes);
WebExpressionVoter 구현체
SpEL 표현식 커스텀 핸들러 구현
SpEL 표현식을 구현할 때 expressionHandler를 제대로 설정하지 않으면 ExpressionUtils.evaluateAsBoolean() 메소드에서 예외가 발생합니다.
⚠️ org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'oddAdmin' cannot be found on object of type 'org.springframework.security.web.access.expression.WebSecurityExpressionRoot' - maybe not public or not valid?