Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
rest资源的GrailsSpring安全静态规则似乎无法正常工作_Rest_Grails_Spring Security_Url Mapping - Fatal编程技术网

rest资源的GrailsSpring安全静态规则似乎无法正常工作

rest资源的GrailsSpring安全静态规则似乎无法正常工作,rest,grails,spring-security,url-mapping,Rest,Grails,Spring Security,Url Mapping,我有一个Grails(2.0.4)应用程序,它使用Spring安全插件(版本1.2.7.3)和安全注释方法(默认方法,更多) 现在,我在UrlMapping.groovy中有这些URL,它们带有资源密钥或控制器/操作对,如下所示: "/$controller/$action?/$id?" { constraints { // apply constraints here } } // other rules, all workin

我有一个Grails(2.0.4)应用程序,它使用Spring安全插件(版本1.2.7.3)和安全注释方法(默认方法,更多)

现在,我在UrlMapping.groovy中有这些URL,它们带有资源密钥或控制器/操作对,如下所示:

"/$controller/$action?/$id?" {
        constraints {
            // apply constraints here
        }
    }

// other rules, all working properly

"/api/item/$id?"(resource: 'itemRest')
'/api/item/batch-delete'(controller: 'itemRest', action: 'batchDelete')
RESTful映射与ItemRestController完美配合:每个方法(show、update、save、delete)都正确映射为正确的HTTP方法。额外的方法(batchDelete)也可以工作

我保护了API url,执行以下操作:

grails.plugins.springsecurity.controllerAnnotations.staticRules = [
     // ...
     '/something/**': ['IS_AUTHENTICATED_FULLY']
     '/api/**': ['IS_AUTHENTICATED_FULLY']
]
现在,如果我调用:

http://host/context/something/bla_bla
但如果我呼叫(需要时,使用适当的有效负载):

我怀疑静态规则在用资源密钥映射rest控制器时工作不正常

还请注意,UrlMapping.groovy文件中不存在“something”url


有什么想法吗?

我想你得用

grails.plugins.springsecurity.controllerAnnotations.staticRules = [
     '/itemrest/**': ['IS_AUTHENTICATED_FULLY'],
      //this will be redundant after the above rule I guess
     '/api/**': ['IS_AUTHENTICATED_FULLY']
]
未在urlMapping中映射的URL必须在规则中直接引用
控制器
。查看文档中的
控制器注释.staticRules
下的内容

映射中映射的控制器的URL时 UrlMappings.groovy,您需要保护未映射url的url。对于 例如,如果您有一个映射到的FooBarController /foo/bar/$action,您必须在 ControllerNotations.staticRules为/foobar/**。这是不同的 而不是其他两种方法所使用的映射,并且 必需,因为ControllerNotations.staticRules条目是 将其视为相应控制器上的注释

grails.plugins.springsecurity.controllerAnnotations.staticRules = [
     '/itemrest/**': ['IS_AUTHENTICATED_FULLY'],
      //this will be redundant after the above rule I guess
     '/api/**': ['IS_AUTHENTICATED_FULLY']
]