1
votes

I know very little or nothing about xml and I have to write a spring-security.xml file . The problem i guess has something to do with my xml not following xsd. Here is the 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>

When I try to run the web application I am getting an error.

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 's:ldap-authentication-provider'. One of '{"http://www.springframework.org/schema/security":any-user-service, "http://www.springframework.org/schema/security":password-encoder}' is expected.

Here is the xsd

spring security xsd

1

1 Answers

3
votes

The xsd says that <s:authentication-manager> accepts as children an authentication-provider OR an ldap-authentication-provider. So, remove the <s:authentication-provider> that is wrapping your <s:ldap-authentication-provider> and that should get you past this problem. Your final code should look like:

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