Hi,
Im trying to incorporate Spring Security to my website, but I have some problems.
These are my xml files:
======== servlet-context.xml: ========
======== security-context.xml ========Code:<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/mvc" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:cloud="http://schema.cloudfoundry.org/spring" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jee="http://www.springframework.org/schema/jee" xmlns:util="http://www.springframework.org/schema/util" xmlns:mvc="http://www.springframework.org/schema/mvc" xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://schema.cloudfoundry.org/spring http://schema.cloudfoundry.org/spring/cloudfoundry-spring-0.8.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd "> <!-- <import resource="classpath:security-context.xml" /> --> <!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure --> <!-- Enables the Spring MVC @Controller programming model --> <annotation-driven/> <mvc:annotation-driven /> <beans:bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/> <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <beans:property name="prefix" value="/WEB-INF/views/" /> <beans:property name="suffix" value=".jsp" /> </beans:bean> <beans:bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> <beans:property name="entityManagerFactory" ref="entityManagerFactory" /> </beans:bean> <beans:bean id="datasource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/> <beans:property name="url" value="jdbc:mysql://mysql.stud.ntnu.no"/> <beans:property name="username" value="jonfr_master"/> <beans:property name="password" value="lokeper2"/> </beans:bean> <jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/application"/> <tx:jta-transaction-manager/> <context:annotation-config /> <tx:annotation-driven /> <context:load-time-weaver /> <beans:bean id="userDAO" class="no.ntnu.jf.dao.UserDAOImpl"/> <beans:bean id="userService" class="no.ntnu.jf.service.UserServiceImpl"/> <beans:bean id="schoolDAO" class="no.ntnu.jf.dao.SchoolDAOImpl"/> <beans:bean id="schoolService" class="no.ntnu.jf.service.SchoolServiceImpl"/> <beans:bean id="adminDAO" class="no.ntnu.jf.dao.AdminDAOImpl" /> <beans:bean id="adminService" class="no.ntnu.jf.service.AdminServiceImpl" /> <beans:bean id="courseDAO" class="no.ntnu.jf.dao.CourseDAOImpl" /> <beans:bean id="courseService" class="no.ntnu.jf.service.CourseServiceImpl" /> <beans:bean id="customUserDetailsService" class="no.ntnu.jf.service.SpringLoginService" /> <!-- Var controller --> <context:component-scan base-package="no.ntnu.jf.controller"/> <context:component-scan base-package="no.ntnu.jf.service"/> </beans:beans>
========= web.xml =========Code:<?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.3.xsd"> <global-method-security pre-post-annotations="enabled" /> <!-- <http auto-config="true"> --> <!-- <intercept-url pattern="/abc/**" access="ROLE_ADMIN" /> --> <!-- </http> --> <http use-expressions="true"> <!-- <intercept-url pattern="/abc/**" access="ROLE_USER" /> --> <intercept-url pattern="/abc/**" access="hasRole('ROLE_ADMIN')" /> <intercept-url pattern="/**" access="denyAll" /> <form-login /> <logout /> </http> <authentication-manager> <authentication-provider user-service-ref="customUserDetailsService"> <password-encoder hash="sha" /> </authentication-provider> </authentication-manager> </beans:beans>
And these are my dependencies in pom.xml:Code:<?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" version="2.5"> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/appServlet/servlet-context.xml </param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/spring/root-context.xml /WEB-INF/security-context.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> <servlet-mapping> <servlet-name>appServlet</servlet-name> <url-pattern>/</url-pattern> <url-pattern>*.html</url-pattern> <url-pattern>*.json</url-pattern> <url-pattern>*.xml</url-pattern> </servlet-mapping> <persistence-unit-ref> <persistence-unit-ref-name>persistence/application</persistence-unit-ref-name> <persistence-unit-name>application</persistence-unit-name> </persistence-unit-ref> </web-app>
The error I get is the following:Code:<dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-web</artifactId> <version>3.0.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-config</artifactId> <version>3.0.5.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-taglibs</artifactId> <version>3.0.5.RELEASE</version> </dependency>
Does anybody know what is going on? Any help is much appreciated!Code:Exception Occurred :Error occurred during deployment: Exception while loading the app : java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.ProviderManager#0': Cannot create inner bean '(inner bean)' of type [org.springframework.security.config.authentication.AuthenticationManagerFactoryBean] while setting bean property 'parent'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#6': FactoryBean threw exception on object creation; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authenticationManager': Cannot resolve reference to bean 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0' while setting bean property 'providers' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.security.authentication.dao.DaoAuthenticationProvider#0': Cannot resolve reference to bean 'customUserDetailsService' while setting bean property 'userDetailsService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'customUserDetailsService' is defined. Please see server.log for more details.


Reply With Quote
