我目前正在构建Grails 1.3.5应用。它使用现有的模型层(共享代码 - 没有GORM),我已经在conf / spring / resources.xml中为它成功配置了tomcat jndi连接,并且一切运行良好。但是,当我尝试配置Spring安全性时,我遇到了问题。我没有使用spring安全插件,因为我想使用我们已经运行的另一个项目的xml安全配置。这使用Spring 3安全性。我在各种博客上都遵循了以下步骤:
我将以下内容添加到templates / 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),但现在我遇到了问题。
答案 0 :(得分:1)
我让这个工作了一段时间,但它在1.3中采用了不同于1.2中的设置。我发现我只能通过将它们添加到web.xml中的contextConfigLocation context-param来访问外部XML文件:
<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'
}
}
}