2012-05-04 1 views
6

Ho creato un servizio Web Axis come applicazione Java 6 in esecuzione su Tomcat 7. Per motivi di sicurezza, il framework Spring Security 2.0.1 è integrato.Sicurezza di primavera: escluso il documento WSDL da richiedere l'autenticazione

Per motivi di sicurezza, l'endpoint del servizio deve essere protetto con l'autenticazione di base. Tuttavia, il documento WSDL dovrebbe essere disponibile pubblicamente.

ho creato una configurazione di sicurezza primavera come questo:


<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd"> 

    <http> 
     <intercept-url pattern="/services/InitechAuthenticationService*" access="ROLE_WSUSER" /> 
     <intercept-url pattern="/services/InitechAuthenticationService?wsdl" filters="none" /> 
     <http-basic /> 
    </http> 

    <authentication-provider> 
     <user-service> 
      <user name="internal" password="${WS_USER_INTERNAL_PASSWORD}" authorities="ROLE_WSUSER" /> 
      <user name="external" password="${WS_USER_EXTERNAL_PASSWORD}" authorities="ROLE_WSUSER" /> 
     </user-service> 
    </authentication-provider> 

</beans:beans> 

Il problema è che indipendentemente dall'ordine delle linee intercetta-url, la linea


<intercept-url pattern="/services/InitechAuthenticationService*" access="ROLE_WSUSER" /> 

sembra sempre di essere applicata e la riga


<intercept-url pattern="/services/InitechAuthenticationService?wsdl" filters="none" /> 

viene ignorato. Mi sarei aspettato che si potesse controllare il comportamento in qualche modo, ad es. specificando l'ordine (in modo che Spring Security selezioni la prima o l'ultima regola di corrispondenza) o la specificità delle regole in modo che Spring Security selezioni la regola più specifica, cioè quella con "wsdl" alla fine in questo caso. Come escludere il documento WSDL dall'autenticazione, abilitando contemporaneamente l'autenticazione per l'utilizzo effettivo del WS?

risposta

4

Ho risolto il problema modificando la parte http della configurazione per utilizzare le espressioni regolari anziché Ant Path Matcher. La configurazione di lavoro completo è qui:


<?xml version="1.0" encoding="UTF-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
    xmlns:beans="http://www.springframework.org/schema/beans" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd 
      http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.1.xsd"> 

    <http path-type="regex"> 
     <intercept-url pattern="/services/InitechAuthenticationService*" access="ROLE_WSUSER" /> 
     <intercept-url pattern="/services/InitechAuthenticationService\\?wsdl" filters="none" /> 
     <http-basic /> 
    </http> 

    <authentication-provider> 
     <user-service> 
      <user name="internal" password="${WS_USER_INTERNAL_PASSWORD}" authorities="ROLE_WSUSER" /> 
      <user name="external" password="${WS_USER_EXTERNAL_PASSWORD}" authorities="ROLE_WSUSER" /> 
     </user-service> 
    </authentication-provider> 

</beans:beans> 

le modifiche:

  1. aggiunto percorso-tipo "regex" attributo http
  2. cambiato? a \\? nell'intercept-url per wsdl