2011-11-30 45 views
5

Chúng tôi có yêu cầu điển hình trong đơn đăng ký của mình.Thay đổi cấu hình Bảo mật mùa xuân

Chúng tôi có hai cấu hình Xuân An: 1. CAS Server 2. LDAP (NTLM)

Vì vậy, bây giờ chúng ta cần phải kiểm tra xem máy chủ CAS có sẵn hay không và sử dụng một trong hai CAS hoặc cấu hình bảo mật LDAP dựa trên tính khả dụng của máy chủ CAS.

Tôi đã cố gắng tự động thay đổi url Entrypoint, tuy nhiên, cả hai tệp cấu hình đều sử dụng các bean/lớp khác nhau.

Có cách nào khác để đạt được điều này không?

Vui lòng cho tôi biết cách chúng tôi có thể đạt được điều này và cách thực hiện?

Xin cảm ơn trước.

Raj

Trả lời

7

Bạn có thể tạo một DelegatingAuthenticationEntryPoint rằng sẽ uỷ thác cho CasAuthenticationEntryPoint tiêu chuẩn nếu CAS server tăng hoặc uỷ thác cho LoginUrlAuthenticationEntryPoint. Việc thực hiện sẽ trông giống như sau

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; 
    } 
} 

Sau đó bạn sẽ dây các DelegatingAuthenticationEntryPoint sử dụng thuộc tính entry-point-ref tương tự như sau:

<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> 
Các vấn đề liên quan