2011-11-30 14 views
5

我々のアプリケーションには標準的な要件があります。 1. CASサーバー 2. LDAP(NTLM)だから、Springのセキュリティ設定を変更する

を、今、私たちはCASサーバーが使用可能かどうかをチェックし、CASまたはLDAPセキュリティ設定のいずれかを使用する必要があります。我々は2つのスプリングセキュリティ構成を有している

CASサーバーの可用性に基づいています。

私はEntrypoint URLを動的に変更しようとしていましたが、両方の設定ファイルが異なるBean /クラスを使用しています。

これを達成する他の方法はありますか?

これを実現するにはどうすればいいのか教えてください。

ありがとうございます。

ラジ

答えて

7

あなたは、CASサーバーがLoginUrlAuthenticationEntryPointに委譲アップまたはそれ以外であれば、標準CasAuthenticationEntryPointに委譲しますDelegatingAuthenticationEntryPointを作成することができます。

<sec:http entry-point-ref="delegateEntryPoint"> 
     ... 
    </sec:http> 
<bean id="delegateEntryPoint" class="sample.DelegatingAuthenticationEntryPoint"> 
    <constructor-arg> 
     <bean class="org.springframework.security.cas.web.CasAuthenticationEntryPoint" 
      p:serviceProperties-ref="serviceProperties" 
      p:loginUrl="https://example.com/cas/login" /> 
    </constructor-arg> 
    <constructor-arg> 
     <bean class="org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint" 
      p:loginFormUrl="/login"/> 
    </constructor-arg> 
</bean> 
:インプリメンテーションは、あなたは、次のようなエントリ・ポイント-REF属性を使用してDelegatingAuthenticationEntryPointを配線します以下

public class DelegatingAuthenticationEntryPoint implements AuthenticationEntryPoint { 
    private AuthenticationEntryPoint casAuthenticationEntryPoint; 
    private AuthenticationEntryPoint ldapAuthenticationEntryPoint; 

    public DelegatingAuthenticationEntryPoint(AuthenticationEntryPoint casAuthenticationEntryPoint, 
     AuthenticationEntryPoint ldapAuthenticationEntryPoint) { 
     this.casAuthenticationEntryPoint = casAuthenticationEntryPoint; 
     this.ldapAuthenticationEntryPoint = ldapAuthenticationEntryPoint; 
    } 

    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) 
     throws IOException, ServletException { 
     if(casServerAvailable()) { 
      casAuthenticationEntryPoint.commence(request, response, authException); 
     } else { 
      ldapAuthenticationEntryPoint.commence(request, response, authException); 
     } 
    } 

    private boolean casServerAvailable() { 
     // TODO implement this method 
     return false; 
    } 
} 

のようになります。

関連する問題