title: spring security authentication and authorization using database
body: <p>My web application is using spring security for authentication and authorization based on database. I have configured this like:
  This is my web.xml file which i introduced applicationContext.xml and applicationContext-
  security.xml:    </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
  
      &lt;display-name&gt;Struts2Example14&lt;/display-name&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/applicationContext.xml
              /WEB-INF/applicationContext-security.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;struts2&lt;/filter-name&gt;
          &lt;filter-class&gt;org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;struts2&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>this is my applicationContextSecurity.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:sec="http://www.springframework.org/schema/security"
         xmlns:beans="http://www.springframework.org/schema/mvc"
         xmlns:context="http://www.springframework.org/schema/context"
         xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd
          http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"&gt;
  
      &lt;bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/&gt;
          &lt;property name="url" value="jdbc:oracle:thin:@10.60.2.4:1521:agribase"/&gt;
          &lt;property name="username" value="sabka"/&gt;
          &lt;property name="password" value="sabka"/&gt;
      &lt;/bean&gt;
  
      &lt;sec:http use-expressions="true"&gt;
          &lt;sec:intercept-url pattern="/secured/**" access="ROLE_USER"/&gt;
          &lt;sec:intercept-url pattern="/admin/*" access="ROLE_ADMIN"/&gt;
          &lt;sec:form-login login-page="/jsp/homePage.jsp"
                          authentication-failure-url="/jsp/homePage.jsp"
                          default-target-url="/jsp/homePage.jsp"/&gt;
      &lt;/sec:http&gt;
  
      &lt;sec:authentication-manager&gt;
          &lt;sec:authentication-provider&gt;
              &lt;sec:jdbc-user-service
                  data-source-ref="dataSource"
                  users-by-username-query="
                      SELECT username,password, enabled FROM users WHERE username=?"
                  authorities-by-username-query="
                      SELECT u.username, ur.authority
                      FROM users u, user_roles ur WHERE u.user_id = ur.user_id AND u.username=?"/&gt;
          &lt;/sec:authentication-provider&gt;
      &lt;/sec:authentication-manager&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>when I run It it eclipse this error appears:</p>
  
  <pre><code>Unexpected exception parsing XML document from ServletContext resource [/WEB-    INF/applicationContext-security.xml];  
  
  nested exception is org.springframework.beans.BeanInstantiationException:Could not instantiate bean class
  [org.springframework.security.config.SecurityNamespaceHandler]:Constructor threw   exception;  
  
  nested exception is java.lang.NoClassDefFoundError:  org/springframework/aop/config/AbstractInterceptorDrivenBeanDefinitionDecorator
  </code></pre>
  
  <p>this is my classpath:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;classpath&gt;
  &lt;classpathentry kind="src" path="src"/&gt;
  &lt;classpathentry kind="src" path="WebContent/WEB-INF"/&gt;
  &lt;classpathentry exported="true" kind="con"  path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.St andardVMType/jre6"&gt;
  &lt;attributes&gt;
  &lt;attribute name="owner.project.facets" value="java"/&gt;
  &lt;/attributes&gt;
  &lt;/classpathentry&gt;
  &lt;classpathentry exported="true" kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"&gt;
  &lt;attributes&gt;
  &lt;attribute name="owner.project.facets" value="jst.web"/&gt;
  &lt;/attributes&gt;
  &lt;/classpathentry&gt;
  &lt;classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/&gt;
  &lt;classpathentry exported="true" kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="//10.60.2.7/Sabka/lib/ojdbc14.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="//10.60.2.7/Sabka/lib/ojdbc14dms.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/antlr-runtime-3.0.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/commons-fileupload-1.2.1.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/commons-io-1.3.2.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/commons-logging-1.1.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/freemarker-2.3.13.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/junit-3.8.1.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/ognl-2.6.11.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/org.springframework.asm-3.0.0.M3.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/org.springframework.beans-3.0.0.M3.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/org.springframework.context-3.0.0.M3.jar"/&gt;
  &lt;classpathentry exported="true" kind="lib" path="D:/SpringWS/SpringStruts2/WebContent/WEB-INF/lib/org.springframework.core-3.0.0.M3.jar"/&gt;
  </code></pre>
  
  <p>
      
      
      
      
      
      
      
      </p>