【问题标题】:Accessing specific controller in grails shiro plugin访问 grails shiro 插件中的特定控制器
【发布时间】:2013-12-16 13:46:59
【问题描述】:

我有一个 grails 应用程序,我在其中使用 shiro 插件来增加安全性。我不会在未登录任何用户的情况下访问任何网址。一切顺利。现在我想知道是否有任何方法可以允许在不登录的情况下访问某些 url?有些链接无需登录即可使用。

【问题讨论】:

  • 如果没有一些遵循链接的自动化软件,我无论如何都不会这样做。但是当您为所有控制器和所有操作设置了安全过滤器时,您可以确定没有任何控制器/操作可以在没有登录的情况下访问
  • 我只想让一些控制器/操作无需登录即可访问;目前我的所有控制器/操作在没有登录的情况下都无法访问

标签: grails grails-plugin shiro


【解决方案1】:

这很容易。如果你有一个标准的 shiro 设置,你会在你的项目中找到一个 ShiroSecurityFilters.groovy conf-文件夹,看起来像这样:

class SecurityFilters {
  def filters = {
    all(uri: "/**") {
      before = {
        // Ignore direct views (e.g. the default main index page).
        if (!controllerName) return true
        // Access control by convention. 
        accessControl() 
      } 
    } 
  } 
}

只需将其替换为以下内容:

class SecurityFilters {
  def filters = {
    all(uri: "/**") {
      before = {
        // Ignore direct views (e.g. the default main index page).
        if (!controllerName) return true
        // Access control by convention. 
        if ((controllerName+':'+actionName) in ['book:view', 'book:list']) {
          return true
        } else {
          accessControl() 
        }
      } 
    } 
  } 
}

这将使每个人都可以访问bookController 中的listview 这两个操作。

希望对您有所帮助...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-24
    • 2012-04-19
    • 2012-01-27
    • 2012-02-14
    • 2012-05-30
    • 1970-01-01
    • 1970-01-01
    • 2012-06-18
    相关资源
    最近更新 更多