2012-12-07 32 views
1

我對xml知之甚少,甚至一無所知,所以我必須編寫一個spring-security.xml文件。我猜這個問題與我的xml沒有遵循xsd有關。這裏是xml。解析spring-security.xml文件的錯誤

<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:s="http://www.springframework.org/schema/security" 
    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-3.0.xsd 
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd"> 

    <s:http auto-config="true"> 
       <s:intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
       <s:intercept-url pattern="/index.jsp" access="IS_AUTHENTICATED_ANONYMOUSLY" /> 
     <s:intercept-url pattern="/**" access="ROLE_USER" /> 
       <s:intercept-url pattern="/" access="ROLE_USER" />  
     <s:form-login login-page="/login" default-target-url="/getemp"/> 
     <s:logout logout-success-url="/logout" /> 
    </s:http> 

    <s:authentication-manager> 
     <s:authentication-provider> 

         <s:ldap-authentication-provider user-dn-pattern="uid={0},ou=people"/> 
     </s:authentication-provider> 
    </s:authentication-manager> 

     <s:ldap-server id="ldapServer" url="ldap://test.com:389" /> 

</beans> 

當我嘗試運行Web應用程序時出現錯誤。

引起:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a:發現無效的內容以元素的開頭:ldap-authentication-provider'。預計會有'{「http://www.springframework.org/schema/security":any-user-service,」http://www.springframework.org/schema/security":password-encoder}'。

這裏是XSD

spring security xsd

回答

3

xsd<s:authentication-manager>接受兒童的authentication-providerldap-authentication-provider。所以,刪除<s:authentication-provider>是包裝你的<s:ldap-authentication-provider>,並應該讓你通過這個問題。您的最終代碼應該看起來像:

<s:authentication-manager> 
    <s:ldap-authentication-provider user-dn-pattern="uid={0},ou=people"/> 
</s:authentication-manager> 
+0

謝謝..那工作 – Rpant