我有一个 Grails (2.0.4) 应用程序,它使用 Spring Security 插件(版本 1.2.7.3)和安全注释方法(默认方法,更多here)。
现在,我在 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 完美配合:每个方法(显示、更新、保存、删除)都使用正确的 HTTP 方法正确映射。额外的方法 (batchDelete) 也有效。
我保护了 API url,这样做:
grails.plugins.springsecurity.controllerAnnotations.staticRules = [
// ...
'/something/**': ['IS_AUTHENTICATED_FULLY']
'/api/**': ['IS_AUTHENTICATED_FULLY']
]
现在,如果我打电话,我会被重定向到登录页面:
http://host/context/something/bla_bla
但如果我调用(在需要时使用适当的有效负载)则不会:
http://host/context/api/item/batchDelete
http://host/context/api/item/1
http://host/context/api/item
我的怀疑是在将其余控制器与资源键映射时,静态规则无法正常工作。
另请注意,UrlMapping.groovy 文件中不存在“某物”网址。
有任何想法吗?