14.2. 설정

Acegi Security에는 익명 인증 기능을 제공하기 위해 서로 결합되는 세 개의 클래스들을 제공하고 있다. AnonymousAuthenticationTokenAuthentication의 구현체이며 익명 인증 주체에 해당되는 GrantedAuthority[]를 저장한다. 대응되는 AnonymousAuthenticationProviderProviderManager에 연결되어 있으므로 AnonymousAuthenticationTokens가 받아들여진다. 마지막으로 AnonymousProcessingFilter가 있는데, AnonymousProcessingFilter는 일반적인 인증 메커니즘에 이어서 연결되며, SecurityContextHolder에 이미 존재하는 Authentication이 들어있지 않을 경우 자동적으로 AnonymousAuthenticationTokenSecurityContextHolder에 추가한다. 필터와 인증 제공자에 대한 정의는 다음과 같다:

<bean id="anonymousProcessingFilter" class="org.acegisecurity.providers.anonymous.AnonymousProcessingFilter">
  <property name="key"><value>foobar</value></property>
  <property name="userAttribute"><value>anonymousUser,ROLE_ANONYMOUS</value></property>
</bean>

<bean id="anonymousAuthenticationProvider" class="org.acegisecurity.providers.anonymous.AnonymousAuthenticationProvider">
  <property name="key"><value>foobar</value></property>
</bean>
        

key는 필터와 인증 제공자 사이에서 공유되므로 필터가 만들어 내는 토큰은 제공자에게 받아들여 진다. userAttributeusernameInTheAuthenticationToken,grantedAuthority[,grantedAuthority]의 형태로 표현된다. 이는 InMemoryDaoImpluserMap 프로퍼티의 등호 기호 뒤에서 사용되는 것과 동일한 문법이다.

앞서 설명했던 것과 같이 익명 인증의 이점은 모든 URI 패턴에 보안을 적용할 수 있다는 것이다. 아래는 그러한 예를 보여준다:

<bean id="filterInvocationInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor">
  <property name="authenticationManager"><ref bean="authenticationManager"/></property>
  <property name="accessDecisionManager"><ref local="httpRequestAccessDecisionManager"/></property>
  <property name="objectDefinitionSource">
    <value>
      CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
      PATTERN_TYPE_APACHE_ANT
      /index.jsp=ROLE_ANONYMOUS,ROLE_USER
      /hello.htm=ROLE_ANONYMOUS,ROLE_USER
      /logoff.jsp=ROLE_ANONYMOUS,ROLE_USER
      /acegilogin.jsp*=ROLE_ANONYMOUS,ROLE_USER
      /**=ROLE_USER
    </value>
  </property>
</bean>
        

익명 인증에 관한 논의는 AuthenticationTrustResolver 인터페이스와 이 인터페이스에 대응되는 AuthenticationTrustResolverImpl 구현체에 관한 것으로 마무리 짓도록 하자. AuthenticationTrustResolver 인터페이스는 isAnonymous(Authentication) 메소드를 제공하는데, 이 메소드는 관심있는 클래스가 이러한 특별한 유형의 인증 상태를 고려하도록 해준다. ExceptionTranslationFilterAccessDeniedException을 처리하며 이 인터페이스를 이용한다. 만약 AccessDeniedException이 던져지고, 그리고 인증이 익명 타입이면, 403(접근금지) 응답 대신 필터는 AuthenticationEntryPoint를 시작하여 인증주체가 적절히 인증을 받을 수 있도록 할 것이다. 이는 구별될 필요가 있는며, 그렇지 않을 경우 인증 주체가 항상 "인증된" 것으로 여겨져 폼이나 BASIC, 아니면 일반적인 인증 메커니즘을 통해 로그인할 수 있는 기회가 주어지지 않을 것이기 때문이다.