3
votes

I'm trying to enable Spring Security 2.5 in my spring app but am running into configuration problems. I've followed a few examples and have done what they are doing, but I think something else I have configured is causing problems.

Here is my web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>onBoardingUI</display-name>


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
       /WEB-INF/security-context.xml
    </param-value>
</context-param>

<!-- Enables Spring security -->
<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>org.apache.commons.fileupload.servlet.FileCleanerCleanup</listener-class>
</listener>

<servlet>
    <servlet-name>testUI</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>testUI</servlet-name>
    <url-pattern>*.html</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>testUI</servlet-name>
    <url-pattern>*.form</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<jsp-config>
    <taglib>
        <taglib-uri>/spring</taglib-uri>
        <taglib-location>/WEB-INF/tld/spring-form.tld</taglib-location>
    </taglib>
</jsp-config>

and here is my security-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
    xmlns:security="http://www.springframework.org/schema/security"
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.xsd">

<security:global-method-security
    secured-annotations="enabled" />

<security:http auto-config="true">
    <!-- Restrict URLs based on role -->
    <security:intercept-url pattern="/login*"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />
    <security:intercept-url pattern="/logoutSuccess*"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <security:intercept-url pattern="/css/main.css"
        access="IS_AUTHENTICATED_ANONYMOUSLY" />

    <security:intercept-url pattern="/**" access="ROLE_USER" />

    <!-- Override default login and logout pages -->
    <security:form-login login-page="/login.html"
        login-processing-url="/login.html" default-target-url="/index.jsp"
        authentication-failure-url="/login.jsp?login_error=1" />
    <security:logout logout-url="/logout"
        logout-success-url="/login.html" />
</security:http>

<security:authentication-provider>
    <security:jdbc-user-service
        data-source-ref="dataSource" />


</security:authentication-provider>

The war fails to deploy and this is all that is in the log:

Feb 16, 2010 11:46:29 AM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart

This is obviously something causing my listener to fail, but I'm not sure why.

This is deploying to Tomcat 6.0.20 and Spring MVC 2.5 with Spring Security 2.5.

2
Look for the actual stacktrace in other log files (stdout*.log, stderr*.log, localhost*.log) - axtavt
Yeah as stated above there should be more logging information available. Have you configured log4j or something for your webapp? Try setting a DEBUG log threshold for org.springframework and dump everything to the console. Also (although this probably isnt breaking things) you are using the 2.0 spring security XSD. - Andrew B

2 Answers

2
votes

Could it be that your 'datasource' bean isn't defined in the security-context.xml file?

Also check that the security-context.xml is in the correct place inside the WAR - according to your web.xml is should be at /WEB-INF/security-context.xml - check the exploded directory in tomcat to see if it is indeed there.

HTH

1
votes
<servlet>
    <servlet-name>testUI</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>