【问题标题】:Make Grails controller action have public access using Spring Security Rest Plugin使用 Spring Security Rest Plugin 使 Grails 控制器操作具有公共访问权限
【发布时间】:2017-05-22 13:39:25
【问题描述】:

我有一个使用 Spring Security Core & REST 插件Grails 3.2.4 应用程序。我的目标是使某些 Grails 控制器操作对公众可用且不被锁定。默认情况下,插件会锁定所有内容(“悲观锁定”)。

如果我使用 @Secured("IS_AUTHENTICATED_ANONYMOUSLY") 注释我的 Grails 控制器操作之一,那么在使用会话进行状态身份验证时我没有问题(由 Core提供> 插件)。

但是,如果控制器操作位于 REST 插件下,这似乎不起作用。

如果我使用无状态 REST 插件,我应该如何使 Grails 控制器操作公开而不锁定? (授权标头提供 Bearer 令牌)。

【问题讨论】:

  • 我发现“IS_AUTHENTICATED_ANONYMOUSLY”不起作用,因为在我的 filterChain.chainMap 定义中使用减号删除了 anonymousAuthenticationFilter。所以我刚刚删除了那个“-anonymousAuthenticationFilter”,它现在可以工作了。

标签: spring security grails authorization


【解决方案1】:

我发现IS_AUTHENTICATED_ANONYMOUSLY 不起作用,因为anonymousAuthenticationFilter 在我的filterChain.chainMap 定义中使用减号删除。所以我刚刚删除了那个“-anonymousAuthenticationFilter”,它现在可以工作了。

【讨论】:

    【解决方案2】:

    查看 application.groovy 中的过滤器模式:

    grails.plugin.springsecurity.controllerAnnotations.staticRules = [
    [pattern: '/',               access: ['permitAll']],
    [pattern: '/error' ,          access: ['permitAll']],
    
    [pattern: '/index.gsp',      access: ['permitAll']],
    [pattern: '/shutdown',       access: ['permitAll']],
    [pattern: '/assets/**',      access: ['permitAll']],
    [pattern: '/**/js/**',       access: ['permitAll']],
    [pattern: '/**/fonts/**',    access: ['permitAll']],
    [pattern: '/**/css/**',      access: ['permitAll']],
    [pattern: '/**/images/**',   access: ['permitAll']],
    [pattern: '/**/favicon.ico', access: ['permitAll']]
    

    ]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      • 2013-11-25
      • 2014-01-05
      • 2012-09-04
      • 2012-04-19
      相关资源
      最近更新 更多