2011-11-30 4 views
5

Nous avons une exigence typique dans notre application.Modification de la configuration de sécurité du ressort

Nous avons deux configurations de sécurité Spring: 1. Serveur CAS 2. LDAP (NTLM)

Donc, maintenant nous devons vérifier si le serveur CAS est disponible ou non et utiliser soit CAS ou la configuration de sécurité LDAP basé sur la disponibilité du serveur CAS.

J'essayais de changer dynamiquement l'URL d'Entrypoint, cependant, les deux fichiers de configuration utilisent des beans/classes différents.

Existe-t-il un autre moyen d'y parvenir?

S'il vous plaît laissez-moi savoir si nous pouvons y arriver et comment?

Merci d'avance.

Raj

Répondre

7

Vous pouvez créer un DelegatingAuthenticationEntryPoint qui délèguent à la CasAuthenticationEntryPoint standard si le CAS serveur était ou déléguer à la LoginUrlAuthenticationEntryPoint. La mise en œuvre ressemblerait à quelque chose comme ce qui suit

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

Vous pouvez ensuite câbler l'DelegatingAuthenticationEntryPoint en utilisant l'attribut point d'entrée-ref semblable au suivant:

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