我目前正在构建Grails 1.3.5应用程序。它使用了现有的模型层(共享代码-没有GORM),并且我已经在conf / spring / resources.xml中为它成功配置了tomcat jndi连接,并且一切正常。但是,当我尝试配置Spring安全性时遇到了问题。我不使用spring安全插件,因为我想使用我们已经在运行的另一个项目中的xml安全配置。这使用Spring 3安全性。我在各种博客上都遵循了以下步骤:
我在模板/war/web.xml中添加了以下内容:
<filter> <filter-name>Spring Security Filter Chain Proxy</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> <init-param> <param-name>targetBeanName</param-name> <param-value>filterChainProxy</param-value> </init-param> </filter> <filter-mapping> <filter-name>Spring Security Filter Chain Proxy</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class> </listener>
当我运行“ grails run-app”时,web.xml出现一个非常奇怪的异常:
2010-11-26 12:16:02,512 INFO [startup.ContextConfig] No default web.xml 2010-11-26 12:16:02,518 ERROR [digester.Digester] End event threw exception java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:925) ... Caused by: java.lang.IllegalArgumentException: Filter mapping specifies an unknown filter name hiddenHttpMethod at org.apache.catalina.core.StandardContext.addFilterMap(StandardContext.java:2251) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at org.apache.tomcat.util.IntrospectionUtils.callMethod1(IntrospectionUtils.java:925) at org.apache.tomcat.util.digester.SetNextRule.end(SetNextRule.java:193) at org.apache.tomcat.util.digester.Rule.end(Rule.java:229) at org.apache.tomcat.util.digester.Digester.endElement(Digester.java:1140) ... 437 more
我还从其他博客中复制了建议的过滤器代码:
<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>
但是我仍然遇到同样的问题。
有人对我接下来应该尝试的方法有任何建议吗?令人讨厌的事情是,我所有这些工作都在带有安全模块2版本的Grails(1.1.1)的旧版本上进行,但是现在遇到了问题。
我在一段时间前完成了此工作,但在1.3中进行的设置与在1.2中进行的设置不同。我发现只能通过将外部XML文件添加到web.xml中的contextConfigLocation context-param中来访问它们:
<context-param> <param-name>contextConfigLocation</param-name> <param-value> /WEB-INF/applicationContext.xml /WEB-INF/applicationContext-security.xml </param-value> </context-param>
除此之外,该配置与非Grails应用程序的配置相同。您可能还需要配置jar。
另外,不要将jar复制到您的lib目录中,而应使用BuildConfig.groovy中的IVy配置,这样您的计算机上每个jar都只有一个副本。这是应该工作的一种:
grails.project.class.dir = 'target/classes' grails.project.test.class.dir = 'target/test-classes' grails.project.test.reports.dir = 'target/test-reports' grails.project.dependency.resolution = { inherits 'global' log 'warn' repositories { grailsPlugins() grailsHome() grailsCentral() ebr() // SpringSource http://www.springsource.com/repository } dependencies { runtime('org.springframework.security:org.springframework.security.core:3.0.3.RELEASE') { excludes 'com.springsource.org.aopalliance', 'com.springsource.org.apache.commons.logging', 'org.springframework.beans', 'org.springframework.context', 'org.springframework.core' } runtime('org.springframework.security:org.springframework.security.config:3.0.3.RELEASE') runtime('org.springframework.security:org.springframework.security.web:3.0.3.RELEASE') { excludes 'com.springsource.javax.servlet', 'com.springsource.org.aopalliance', 'com.springsource.org.apache.commons.logging', 'org.springframework.aop', 'org.springframework.beans', 'org.springframework.context', 'org.springframework.core', 'org.springframework.web' } } }