Problema na configuração do Spring Security

2 respostas
F

Boa tarde pessoal!!!

Estou tentando configurar o Spring Security no meu projeto mas estou tomando o erro abaixo e não estou conseguindo achar uma solução.

org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: spring-security-web classes are not available. You need these to use <filter-chain-map>
Offending resource: ServletContext resource [/WEB-INF/spring-security.xml]
	at org.springframework.beans.factory.parsing.FailFastProblemReporter.fatal(FailFastProblemReporter.java:59)
	at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:68)
	at org.springframework.beans.factory.parsing.ReaderContext.fatal(ReaderContext.java:55)
	at org.springframework.security.config.SecurityNamespaceHandler.reportMissingWebClasses(SecurityNamespaceHandler.java:123)
	at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:80)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1435)
	at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1425)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:184)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:140)
	at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:111)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125)
	at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:94)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:131)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:537)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:383)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:283)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4797)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5291)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)

Fev 10, 2013 1:51:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
Fev 10, 2013 1:51:37 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Context [/Controlando] startup failed due to previous errors
Fev 10, 2013 1:51:37 PM org.apache.catalina.core.ApplicationContext log
INFO: Closing Spring root WebApplicationContext
Fev 10, 2013 1:51:37 PM org.apache.catalina.core.StandardContext listenerStop
SEVERE: Exception sending context destroyed event to listener instance of class org.springframework.web.context.ContextLoaderListener
java.lang.IllegalStateException: BeanFactory not initialized or already closed - call 'refresh' before accessing beans via the ApplicationContext
	at org.springframework.context.support.AbstractRefreshableApplicationContext.getBeanFactory(AbstractRefreshableApplicationContext.java:172)
	at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1090)
	at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1064)
	at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:1010)
	at org.springframework.web.context.ContextLoader.closeWebApplicationContext(ContextLoader.java:549)
	at org.springframework.web.context.ContextLoaderListener.contextDestroyed(ContextLoaderListener.java:143)
	at org.apache.catalina.core.StandardContext.listenerStop(StandardContext.java:4837)
	at org.apache.catalina.core.StandardContext.stopInternal(StandardContext.java:5484)
	at org.apache.catalina.util.LifecycleBase.stop(LifecycleBase.java:232)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:160)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
	at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
	at java.util.concurrent.FutureTask.run(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at java.lang.Thread.run(Unknown Source)
Segue meu ApplicationContext.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:context="http://www.springframework.org/schema/context" 
       xsi:schemaLocation="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">
       
	
	<context:annotation-config/> <!-- Scanner @Autowired -->
	<context:component-scan base-package="br.com.teste"/> <!-- Scanner @Repository @Service --> 
	
	<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
		<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
		<property name="url" value="jdbc:mysql://localhost:3306/teste"/>
		<property name="username" value="root"/>
		<property name="password" value="admin"/>
	</bean>
	
</beans>
Aqui está o spring-security.xml
<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">

	<http auto-config="true">
		<form-login login-page="/login.jsp"
			authentication-failure-url="/login.jsp?error=invalido" />
		<intercept-url pattern="pages/**" access="ROLE_USER" />
	</http>
	<authentication-manager>
		<authentication-provider>
			<jdbc-user-service data-source-ref="dataSource"
				users-by-username-query="SELECT email as username, senha as password, 'true' as enable FROM usuarios WHERE email=?"
				authorities-by-username-query="SELECT email as username, permissao as authority FROM usuarios WHERE email=?" />
		</authentication-provider>
	</authentication-manager>

</beans:beans>
e o 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_3_0.xsd" id="WebApp_ID" version="3.0">
	<display-name>Struts 2</display-name>
  	<welcome-file-list>
    	<welcome-file>/WEB-INF/redirect.jsp</welcome-file>
  	</welcome-file-list>
  	<listener>
    	<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
	</listener>
	
	<context-param>
    	<param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name>
    	<param-value>/WEB-INF/tiles.xml</param-value>
	</context-param>
	
  	<listener>
    	<listener-class>
        	org.springframework.web.context.ContextLoaderListener
      	</listener-class>
  	</listener>
  	<listener>
    	<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
	</listener>
  	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>
			/WEB-INF/spring-security.xml
		</param-value>
	</context-param>
  	<filter>
    	<filter-name>struts2</filter-name>
    	<filter-class>
         	org.apache.struts2.dispatcher.FilterDispatcher
      	</filter-class>
  	</filter>
  	<filter-mapping>
    	<filter-name>struts2</filter-name>
    	<url-pattern>/*</url-pattern>
  	</filter-mapping>
  	<filter>
    	<filter-name>action2</filter-name>
    	<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsExecuteFilter</filter-class>
  	</filter>
  	<filter-mapping>
    	<filter-name>action2</filter-name>
    	<url-pattern>/*</url-pattern>
  	</filter-mapping>
  	
  	<!-- 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>
</web-app>

Alguém pode me ajudar?

2 Respostas

L

dar uma olhada aqui e ver o que tem de diferente:
http://www.edsongoncalves.com.br/tag/spring-security/

F

Olá LPJava!!!

Estou usando esse mesmo tutorial para me guiar na base do spring security… inicialmente o projeto estava com struts 2 integrado com spring e com o tiles 2 e funcionava de boa…

Daí tentei integrar com o security e tá dando esse erro…

Eu não usei os mesmos jars q ele, eu baixei os jars do site.

Criado 10 de fevereiro de 2013
Ultima resposta 10 de fev. de 2013
Respostas 2
Participantes 2