인증 된 사용자가 특정 자원에 접근하고자 할 때 접근 할 자격이 되는지 증명하는 것을 인가(Authorization)이라 한다.
Authority는 권한을 의미하며 Authentication 객체에서 부여된 권한을 나타내기 위해 사용된다.
💡Authentication : 사용자의 종합적인 인증처리를 하는 객체로 아래의 네가지 구성요소로 구성된다.
principal : 사용자의 아이디, User객체를 저장한다.
(UserDetails의 구현으로 User객체를 형성할 수 있다.)
credential : 사용자 암호(저장시 암호화되어 저장된다(단방향))
authorities : 인증된 사용자의 권한 목록(주로 사용되는 구현체는 SimpleGrantedAuthrity이다.)
Authenticated : 인증 여부(True/False)
GrantAuthority객체는 principal(사용자 정보)에게 부여한 권한을 나타낸다.(GrantAuthrity는 인터페이스로 일반적인 구현체는 SimpleGrantedAuthority이다.)
GrantAuthority는 단 하나의 메서드만을 가지고 있다.
public interface GrantAuthority extends Serializable {
String getAuthority();
}
인증 된 이후 AccessDecisionManager가 해당 Authentication 객체에서 GrantedAuthority를 꺼내 접근 권한을 결정한다. 만약 Authorities가 복잡하게 구현되어 있으면 getAuthority에선 null을 리턴한다.(구체적인 코드 필요)
SimpleGrantedAuthority 클래스는 String 형태의 사용자의 권한에 해당하는 문자열을 GrantedAuthority 로 반환해줍니다.
스프링 시큐리티는 사용자가 특정 자원에 접근하려 할 때, 접근을 제어하는 인터셉터를 제공합니다. 호출을 허용할지 말지를 결정하는 pre-Invocation 결정은 AccessDecisionManager에서 결정합니다.
인증, 요청, 권한 정보를 이용하여 사용자의 자원접근을 허용/거부 여부를 최종 결정하는 주체입니다.
AbstractSecuriyInterceptor에 의해 호출됩니다.
여러 개의 Voter를 가질 수 있으며, Voter들로부터 접근 허용, 거부, 보류에 해당하는 각각의 값을 리턴받아 판단, 결정합니다.
AccessDecisionManager는 3가지의 메서드를 가지고 있습니다.
void decide(Authentication authentication, Object secureObject, Collection<ConfigAttribute> attrs) throws AccessDeniedException;
boolean supports(ConfigAttribute attribute);
boolean supports(Class clazz);
decide
Collection<ConfigAttribute> attrs
: 권한 정보(hasRole("USER"))
support(ConfigAttribute)
support(Class)
보안 객체를 실행하기 전에는 AbstractSecurityInterceptor가 AccessDecisionManager를 호출합니다.
하지만 실제로 보안 객체가 리턴하는 객체를 바꿔야 하는 애플리케이션도 있습니다.
FileSecurityInterceptor는 HttpServletRequest를 사용해서 권한을 인가하고, 인터셉터는 FilterChainProxy에 하나의 보안 필터로 추가됩니다.