8.2. 설정

JaasAuthenticationProvider는 JAAS를 통해 사용자의 인증주체와 신원정보에 대한 인증을 시도한다.

다음 내용을 포함하고 있는 JAAS 로그인 설정파일이 /WEB-INF/login.conf에 들어있다고 가정해 보자:

JAASTest {
  sample.SampleLoginModule required;
};

모든 Acegi Security 빈들 처럼 JaasAuthenticationProvider도 애플리케이션 컨텍스트를 통해 설정된다. 다음의 빈 정의는 위 JAAS 로그인 설정 파일과 대응된다:

<bean id="jaasAuthenticationProvider" class="org.acegisecurity.providers.jaas.JaasAuthenticationProvider">
  <property name="loginConfig">
    <value>/WEB-INF/login.conf</value>
  </property>
  <property name="loginContextName">
    <value>JAASTest</value>
  </property>
  <property name="callbackHandlers">
    <list>
      <bean class="org.acegisecurity.providers.jaas.JaasNameCallbackHandler"/>
      <bean class="org.acegisecurity.providers.jaas.JaasPasswordCallbackHandler"/>
    </list>
  </property>
  <property name="authorityGranters">
    <list>
      <bean class="org.acegisecurity.providers.jaas.TestAuthorityGranter"/>
    </list>
  </property>
</bean>

          

CallbackHandlerAuthorityGranter는 아래에서 알아볼 것이다.

JAAS CallbackHandler

대부분의 JAAS LoginModule은 일종의 콜백을 필요로 하며, 일반적으로 이러한 콜백들을 사용하여 사용자명과 비밀번호를 획득한다.

Acegi Security를 배치하는 경우에는 Acegi Security가 이러한 사용자 상호작용(인증 메커니즘을 통한)을 책임진다. 따라서 인증 요청이 JAAS를 통해 위임되기 전까지는 Acegi Security의 인증 메커니즘에는 이미 JAAS LoginModule에서 필요로 하는 모든 정보들을 포함하고 있는 Authentication 객체가 있을 것이다.

따라서 Acegi Security의 JAAS 패키지는 두 개의 기본적인 콜백 핸들러를 제공하는데, 각각 JaasNameCallbackHandlerJaasPasswordCallbackHandler이며, 이러한 각 콜백 핸들러들은 JaasAuthenticationCallbackHandler를 구현한다. 대부분의 경우 이러한 콜백 핸들러들은 내부 메커니즘을 전혀 이해해야할 필요없이 사용될 수 있다.

콜백이 작동하는 방식을 완전하게 제어할 필요가 있을 경우, 내부적으로 JaasAutheticationProvider가 이러한 JaasAuthenticationCallbackHandlerInternalCallbackHandler로 래핑한다. InternalCallbackHandler는 실제로는 JAAS의 표준 CallbackHandler 인터페이스를 구현하는 클래스이다. JAAS LoginModule이 사용될 때마다 InternalCallbackHandlerInternalCallbackHandler가 설정되어 있는 애플리케이션 컨텍스트의 목록을 전달한다. 만약 LoginModuleInternalCallbackHandler에 대해 콜백을 요청하면 이번에는 콜백이 JaasAuthenticationCallbackHandler이 래핑된 곳으로 전달된다.

JAAS AuthorityGranter

JAAS는 심지어 "역할(role)"이 JAAS에서 인증주체로서 나타내어 지더라도 인증주체와 함께 동작한다. 반면 Acegi Security는 Authentication 객체와 함께 동작한다. 각각의 Authentication 객체는 하나의 인증주체와 여러 개의 GrantedAuthority를 가진다. 이러한 서로 다른 개념들간의 맵핑을 돕기 위해 Acegi Security의 JAAS 패키지에는 AuthorityGranter 인터페이스가 포함되어 있다.

AuthorityGranter는 JAAS 인증주체를 검사하고 String을 반환할 책임이 있다. 그리고 나서 JaasAuthenticationProviderAuthorityGranter가 반환하는 StringAuthorityGranter가 전달된 JAAS 인증주체를 모두 포함하는 JaasGrantedAuthority(Acegi Security의 GrantedAuthority 인터페이스를 구현하고 있는)를 생성한다. JaasAuthenticationProvider는 JAAS LoginModule을 이용하여 사용자의 신원정보를 획득하는데, 즉 최초에 성공적으로 인증한 다음 JAAS LoginModule이 반환하는 LoginContext에 접근하여 JAAS 인증 주체를 획득한다. LoginContext.getSubject().getPrincipals()을 호출하여 반환된 인증주체들은 JaasAuthenticationProvider.setAuthorityGranters(List)에 프로퍼티로 정의되어 있는 각 AuthorityGranter로 전달된다.

Acegi Security에는 구현에 특화되어 있는 수단을 포함한 JAAS 인증주체가 모두 주어진 어떠한 AuthorityGranter도 존재하지 않는다. 하지만 간단한 AuthorityGranter 구현을 시험하는 단위 테스트에는 TestAuthorityGranter가 포함되어 있다.