0

I'm trying to perform some custom authentication using Spring security.

I've read a few things about it:

I also found an interesting conversation regarding this ClassNotFoundException DelegatingFilterProxy: http://forum.springsource.org/showthread.php?53972-Problem-when-finding-springSecurityFilterChain-bean

So, In my web.xml I have

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

  <servlet>
    <servlet-name>mysecuredapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>mysecuredapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>


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


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

</web-app>

And in mysecuredapp-servlet.xml I have

<?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-3.0.xsd 
        http://www.springframework.org/schema/security
        http://www.springframework.org/schema/security/spring-security-3.0.xsd" >

    <http auto-config="true">
        <intercept-url pattern="/account/*" access="ROLE_USER, ROLE_ADMIN, ROLE_MASTER" />
        <intercept-url pattern="/admin/*" access="ROLE_ADMIN, ROLE_MASTER" />
        <intercept-url pattern="/master/*" access="ROLE_MASTER" />
    </http>


    <authentication-manager>
        <authentication-provider ref="daoAuthenticationProvider" />
    </authentication-manager>

    <beans:bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" >
        <beans:property name="userDetailsService" ref="userDetailsService" />
    </beans:bean>


</beans:beans>

And this is my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>

  <groupId>MySecuredApp</groupId>
  <artifactId>securedApp</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>My Secured App - Spring Hibernate Maven</name>
  <properties>
        <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
        <javax.servlet.jstl.version>1.2</javax.servlet.jstl.version>
        <org.hibernate>3.6.10.Final</org.hibernate>
        <org.springsecurity.version>3.1.2.RELEASE</org.springsecurity.version>
    </properties>

  <dependencies>
        <!-- Hibernate deps -->
        <dependency>
            <groupId>org.hibernate.javax.persistence</groupId>
            <artifactId>hibernate-jpa-2.0-api</artifactId>
            <version>1.0.1.Final</version>
        </dependency>
        <dependency>
          <groupId>org.hibernate</groupId>
          <artifactId>hibernate-entitymanager</artifactId>
          <version>${org.hibernate}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${org.hibernate}</version>
        </dependency>

        <!-- Spring security deps -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${org.springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${org.springsecurity.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${org.springsecurity.version}</version>
        </dependency>
        <!-- Spring deps -->
        <dependency>
             <groupId>org.springframework</groupId>
             <artifactId>spring-context</artifactId>
             <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-orm</artifactId>
            <version>${org.springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</artifactId>
            <version>${org.springframework.version}</version>
            <scope>test</scope>
        </dependency>

        <!-- Misc deps -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${javax.servlet.jstl.version}</version>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.10</version>
        </dependency>
        <dependency>
            <groupId>commons-dbcp</groupId>
            <artifactId>commons-dbcp</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>commons-pool</groupId>
            <artifactId>commons-pool</artifactId>
            <version>20030825.183949</version>
        </dependency>
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-io</artifactId>
            <version>1.3.2</version>
        </dependency>

       <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

       <dependency>
         <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.1</version>
        <scope>test</scope>
       </dependency>

  </dependencies>

  <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
                <encoding>UTF8</encoding>
            </configuration>
            <inherited>true</inherited>
        </plugin>
    </plugins>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
    </resources>
    <testResources>
        <testResource>
            <directory>src/test/resources</directory>
            <filtering>true</filtering>
        </testResource>
        <testResource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </testResource>
    </testResources>
  </build>
</project>

When I start tomcat (in Eclipse), I get this ClassNotFoundException DelegatingFilterProxy. Any idea why this is coming up?

Thanks in advance

Community
  • 1
  • 1
Adriano
  • 19,463
  • 19
  • 103
  • 140

2 Answers2

2

This was a foolish error from myself... since I had issues for exact same reason: not including the Spring Dependencies to the Deployment Assembly.

See this answer I posted previously for more details: Maven + Spring + Dynamic Web Module ( Eclipse ) = java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener

Community
  • 1
  • 1
Adriano
  • 19,463
  • 19
  • 103
  • 140
1

Is it possible that the filter chain isn't picking up your user details service bean? You dont seem to have a component-scan directive in your mysecuredapp-servlet.xml file, and the contextConfigLocation for the delegating filter only points to that file.

I could be wrong, but I'm fairly sure that the Spring context for the filter is separate to that for the dispatcher servlet. You'd need to either include a component-scan in your security XML file, or add you main Spring beans file to the contextConfigLocation.

Zutty
  • 5,357
  • 26
  • 31