grails - 访问 grails shiro 插件中的特定 Controller

标签 grails grails-plugin shiro

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

最佳答案

这很容易。如果您有标准的 shiro 设置,您会在项目 conf 文件夹中找到一个 ShiroSecurityFilters.groovy ,如下所示:

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() 
        }
      } 
    } 
  } 
}

这将使每个人都可以访问 bookControllerlistview 这两个操作。

希望有帮助...

关于grails - 访问 grails shiro 插件中的特定 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612498/

相关文章:

authorization - 如何从 Apache Shiro 中的主体获取角色?

java - Apache Shiro - 密码格式问题

grails - 链接到mailService中项目的根URL

grails - Grails javax.websocket问题

grails - 如何从Quartz作业访问域对象?

grails - 从 Config.groovy 触发 Quartz 作业

grails - Grails GSP:<g:widget…/>不会在嵌套Numbers上抛出这样的属性

grails - 防止 Grails Asset-Pipeline 更改文件名?

unit-testing - 使用rest插件的服务中的Grails模拟方法

permissions - Apache Shiro,isPermission() 不起作用