Spring boot 如何在Grails4集成测试中禁用spring安全性?
我有一个Grails3应用程序,包括SpringSecurity,我最近升级到Grails4 我的Spring boot 如何在Grails4集成测试中禁用spring安全性?,spring-boot,grails,spring-security,integration-testing,grails-4,Spring Boot,Grails,Spring Security,Integration Testing,Grails 4,我有一个Grails3应用程序,包括SpringSecurity,我最近升级到Grails4 我的应用程序.yml包括以下内容: environments: test: grails: plugin: springsecurity: active: false security: ignored: '/**' ba
应用程序.yml
包括以下内容:
environments:
test:
grails:
plugin:
springsecurity:
active: false
security:
ignored: '/**'
basic:
enabled: false
spring:
security:
enabled: false
为什么这在Grails4中不起作用?什么是好的替代方案
Grails4似乎忽略了这个配置。运行集成测试时,我收到一个403错误,并显示一条消息:
无法验证提供的CSRF令牌,因为找不到您的会话。
它似乎启用了spring安全性,并且正在使用SecurityFilterAutoConfiguration
,这在我的应用程序中通常被排除在外
更新
我正在使用以下依赖项:
compile('org.grails.plugins:spring-security-core:3.2.3') {
exclude group: 'org.springframework.security'
}
compile ('org.springframework.security:spring-security-core:4.2.13.RELEASE') {
force = true
}
compile 'org.springframework.security:spring-security-web:4.2.13.RELEASE'
compile 'org.springframework.security:spring-security-config:4.2.13.RELEASE'
更新2:
在我的调试器中,我发现spring安全核心插件实际上已被禁用。执行插件类中的以下代码:
SpringSecurityUtils.resetSecurityConfig()
def conf = SpringSecurityUtils.securityConfig
boolean printStatusMessages = (conf.printStatusMessages instanceof Boolean) ? conf.printStatusMessages : true
if (!conf || !conf.active) {
if (printStatusMessages) {
// <-- the code in this block is executed; active flag is false
String message = '\n\nSpring Security is disabled, not loading\n\n'
log.info message
println message
}
return
}
这并没有解决问题。尽管我的匿名WSCA bean正在构建中,但spring仍在使用MWSCA默认bean。请在中尝试
grails-app/conf/application.groovy
试试这个
grails-app/conf/application.groovy
您使用的是哪个版本的spring安全插件?谢谢您的回复!grails插件版本是3.2.3。我已经将gradle依赖项中的一个片段添加到了OP中。对于grails4,您将希望使用插件的4.x。目前,我认为4.0.0可能是最新版本。您是否在Config.groovy中尝试了以下版本?grails.plugin.springsecurity.active=false“我可以尝试将此设置放在我的application.yml中,看看它是否拾取它。”-原始问题包括“我的application.yml包括以下内容”。我以为你已经有了设置。你使用的是什么版本的spring安全插件?谢谢你的回复!grails插件版本是3.2.3。我已经将gradle依赖项中的一个片段添加到了OP中。对于grails4,您将希望使用插件的4.x。目前,我认为4.0.0可能是最新版本。您是否在Config.groovy中尝试了以下版本?grails.plugin.springsecurity.active=false“我可以尝试将此设置放在我的application.yml中,看看它是否拾取它。”-原始问题包括“我的application.yml包括以下内容”。我以为您已经有了设置。@JeffScottBrown是正确的,这个设置已经在我的YML文件中了app@JeffScottBrown是正确的,此设置已存在于我的应用程序的YML文件中
if (grailsApplication.config.disableSecurity == true && !Environment.isWarDeployed()) {
webSecurityConfigurerAdapter(new WebSecurityConfigurerAdapter(true) {})
}
environments {
development {
}
test {
grails.plugin.springsecurity.active = false
}
production {
}
}