Grails 远程控制插件 - Spring 安全配置

Grails remote control plugin - Spring Security Configuration

每当我尝试使用 Grails 远程控制插件时,我都会收到以下异常。

groovyx.remote.RemoteControlException: Error sending command chain to 'http://localhost:8080/******/grails-remote-control'
    [test] at groovyx.remote.transport.http.HttpTransport.send(HttpTransport.groovy:65)
    [test] at groovyx.remote.client.RemoteControl.sendCommandChain(RemoteControl.groovy:114)
    [test] at groovyx.remote.client.RemoteControl.exec(RemoteControl.groovy:73)
    [test] at groovyx.remote.client.RemoteControl.exec(RemoteControl.groovy:67)
    [test] at cgw.login.AbstractCGWGebSpec.msg(AbstractCGWGebSpec.groovy:35)
    [test] at cgw.login.AbstractCGWGebSpec.Login to cgw application(AbstractCGWGebSpec.groovy:25)
[test] Caused by: java.io.StreamCorruptedException: invalid stream header: 3C68746D
    [test] at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:782)
    [test] at java.io.ObjectInputStream.(ObjectInputStream.java:279)
    [test] at groovyx.remote.util.ClassLoaderConfigurableObjectInputStream.(ClassLoaderConfigurableObjectInputStream.groovy:26)
    [test] at groovyx.remote.Result.readFrom(Result.groovy:150)
    [test] at groovyx.remote.transport.http.HttpTransport.send_closure1(HttpTransport.groovy:62)
    [test] at groovyx.remote.transport.http.HttpTransport.send(HttpTransport.groovy:53)

一个简单的 Google 搜索显示它很可能是由于与 Spring 安全插件的冲突。你可以看到它here。不幸的是,如果不深入 Spring 安全插件文档,我找不到任何关于如何正确配置它的信息。

如何为 grails-remote-control url 配置 spring 安全核心以允许全部?

将下面的代码放入您的 config.groovy

grails.plugin.springsecurity.securityConfigType = 'InterceptUrlMap'

grails.plugin.springsecurity.interceptUrlMap = [
        '/grails-remote-control/**':       ['IS_AUTHENTICATED_ANONYMOUSLY']
]

如果您使用带有 staticRules + controllerAnnotations 的 spring security 2,它也可以工作:

grails.plugin.springsecurity.controllerAnnotations.staticRules = [
        '/grails-remote-control/**': ["permitAll"]
]