11.2. 설정

로그인 폼은 단순히 j_usernamej_password 입력 필드를 포함하며, 그리고 필터에 의해 모니터링되고 있는 URL로 게시(post)한다(기본값은 j_acegi_security_check이다). web.xml에는 다음과 같이 FilterToBeanProxy를 정의한다:

<filter>
  <filter-name>Acegi Authentication Processing Filter</filter-name>
  <filter-class>org.acegisecurity.util.FilterToBeanProxy</filter-class>
  <init-param>
    <param-name>targetClass</param-name>
    <param-value>org.acegisecurity.ui.webapp.AuthenticationProcessingFilter</param-value>
  </init-param>
</filter>

<filter-mapping>
  <filter-name>Acegi Authentication Processing Filter</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

FilterToBeanProxy에 관해 자세히 알아보려면 Filters 섹션을 참고하길 바란다. 애플리케이션 컨텍스트에는 AuthenticationProcessingFilter를 정의할 필요가 있을 것이다:

<bean id="authenticationProcessingFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter">
  <property name="authenticationManager"><ref bean="authenticationManager"/></property>
  <property name="authenticationFailureUrl"><value>/acegilogin.jsp?login_error=1</value></property>
  <property name="defaultTargetUrl"><value>/</value></property>
  <property name="filterProcessesUrl"><value>/j_acegi_security_check</value></property>
</bean>        

설정된 AuthenticationManager는 각각의 인증 요청을 처리한다. 인증이 실패하면 브라우저는 authenticationFailureUrl로 이동할 것이다. AbstractProcessingFilter.ACEGI_SECURITY_LAST_EXCEPTION_KEY로 알 수 있는 AuthenticationExceptionHttpSession 속성에 위치할 것이며, 사용자는 오류 페이지에서 오류가 발생한 원인에 관해 알 수 있을 것이다.

인증이 성공하면 결과 Authentication 객체는 SecurityContextHolder에 위치할 것이다.

일단 SecurityContextHolder가 갱신되면, 브라우저는 대상 URL로 이동할 필요가 있을 것이다. 대상 URL은 보통 AbstractProcessingFilter.ACEGI_SECURITY_TARGET_URL_KEY로 설정되어 있는 HttpSession 속성으로 알 수 있다. 이 속성은 AuthenticationException이 발생할 경우 ExceptionTranslationFilter에 의해 자동적으로 설정되며, 따라서 로그인이 성공한 후 사용자는 사용자가 접근을 시도했던 곳으로 돌아갈 수 있다. 몇 가지 이유로 HttpSession이 대상 URL을 가리키지 않을 경우 브라우저는 defaultTargetUrl 프로퍼티로 이동할 것이다.