Spring securityについて


Spring Acegi Securityはspring securityの主要なアーキテクチャである.
ここでは4つのfilterの概念を理解する必要があります.Authentication Processing Filter、HttpSession ContectIntegration Filter、ExceptonTranslation Filter、Filter SecurityInterceptor.
これら4つのFilterはFilterChinProxyフィルタチェーンによって管理されています.4つのフィルタを連結するように、彼はFilterインターフェースを実現しました.WebapplicationContUtils類のgetWebApplectContextを呼び出してSpringコンテキストハンドルを取得します.つまり、ここのターゲットパラメータ構成のBeanは、Filter ChinProxyのinit()方法を呼び出して、Spring Securityフィルタチェーンを起動して、各種アイデンティティ認証とライセンスサービスを行う.
web.xmlは以下のような構成で使用できます.

<filter>  
 <filter-name>filterChainProxy</filter-name>  
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>  
</filter>  
<filter-mapping>  
<filter-name>filterChainProxy<filter-name>  
<url-pattern>/*</url-pattern>  
</filter-mapping> 
Spring-security.xmlのサンプルコードは以下の通りです.

<bean id="filterChainProxy"    class="org.springframework.security.util.FilterChainProxy">
<security:filter-chain-map path-type="ant">
<security:filter-chain pattern="/logout.jsp" filters="logoutFilter" />
<security:filter-chain pattern="/**" filters="httpSessionContextIntegrationFilter,authenticationProcessingFilter,FilterSecurityInterceptor" />
</security:filter-chain-map>
</bean>
各フィルタを一つずつ紹介します.
Authentication ProcessigFilterは認証プロセスフィルタであり、フォーム認証を処理するためにそれを使用しています.filter ProcessUrlと定義されているのと同じ要求を受けると、それは動作を開始します.

<bean id="authenticationProcessingFilter" class="org.springframework.security.ui.webapp.AuthenticationProcessingFilter"> 
<property name="authenticationManager" ref="authenticationManager"></property> 
<property name="filterProcessesUrl" value="/login"></property> 
<property name="defaultTargetUrl" value="/error.jsp?error=1"></property> 
<property name="authenticationFailureUrl" value="/index.jsp?error_code=1"></property> 
</bean> 
Authentication ProcessigFilterはauthenticationManagerを呼び出してユーザのアイデンティティの認証を完了します.主にAuthenticate方法で認証します.Authentication(ユーザ名パスワードのみを含む)をパラメータとして使用して、認証は完全なAuthenticationオブジェクトに戻ります.最後にAuthenticationオブジェクトをSecurityConttextに保存します.
http Session Contect Integration Filterは統合フィルタであり、生成されたHTTPセッションでSecurityContectを保持する.これはこの認証機構が一回だけ認証され、次にHTTP requestを介してfilter chainの次のfilterに渡されることを意味する.
例は以下の通りです

<bean id="sif"
class="org.springframework.security.context.HttpSessionContextIntegrationFilter">
<property name="allowSessionCreation" value="false"/>
</bean>  
Filter Security Interceptor管理制限アクセス権限チェックとチェックを付与します.どのような資源が安全で、どのような役割がそれらを訪問するかを知っています.Filter SecurityInterceptorはAuthenticationManagerと仕事をするAccess DecisionManagerを使用します.

<bean id="filterSecurityInterceptor" class="org.springframework.security.intercept.web.FilterSecurityInterceptor"> 
<property name="accessDecisionManager" ref="accessDecisionManager"></property> 
<property name="authenticationManager" ref="authenticationManager"></property> 
<property name="objectDefinitionSource"> 
<value> 
CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON 
PATTERN_TYPE_APACHE_ANT 
/login=ROLE_connect 
/success.jsp=ROLE_connect 
</value> 
</property> 
</bean> 
Exception Translation FilterはFilter Security Interceptorに依存して、Filter Security Interceptorの投げた例外を捕獲するために使用されます.

<bean id="exceptionTranslationFilter"    class="org.springframework.security.ui.ExceptionTranslationFilter">
<property name="authenticationEntryPoint" ref="authenticationEntryPoint"/>
<property name="accessDeniedHandler" ref="accessDeniedHandler"/>
</bean>            
<bean id="authenticationEntryPoint"     class="org.springframework.security.ui.preauth.PreAuthenticatedProcessingFilterEntryPoint">
</bean>
<bean id="accessDeniedHandler"  class="org.springframework.security.ui.AccessDeniedHandlerImpl">
<property name="errorPage" value="/logout.html"/>
</bean>