2011-11-30 12 views
5

Abbiamo un tipico requisito nella nostra applicazione.Modifica della configurazione di Spring Security

Abbiamo due configurazioni di Primavera di sicurezza: 1. CAS Server 2. LDAP (NTLM)

Così, ora abbiamo bisogno di verificare se il server CAS è disponibile o meno e utilizzare CAS o configurazione di sicurezza LDAP basato sulla disponibilità del server CAS.

Stavo cercando di modificare dinamicamente l'URL di Entrypoint, tuttavia, entrambi i file di configurazione utilizzano bean/classi diversi.

C'è qualche altro modo per raggiungere questo obiettivo?

Per favore fatemi sapere come possiamo ottenere questo e come?

Grazie in anticipo.

Raj

risposta

7

Si potrebbe creare un DelegatingAuthenticationEntryPoint che delegare alla CasAuthenticationEntryPoint standard se il CAS Server era in alto o in altro modo delegare alla LoginUrlAuthenticationEntryPoint. L'implementazione sarebbe simile alla seguente

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

Si potrebbe quindi collegare il DelegatingAuthenticationEntryPoint utilizzando l'attributo entry-point-ref simile al seguente:

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