使用Shiro插件保护Grails应用程序中的一些但不是全部页面 [英] Secure some, but not all pages in a Grails application with the Shiro plugin

查看:147
本文介绍了使用Shiro插件保护Grails应用程序中的一些但不是全部页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能只是我,但我很难理解如何使用Shiro插件保护Grails应用程序中的某些页面。

Might be just me, but I have a hard time understanding how to secure just some of the pages in a Grails application with the Shiro Plugin.

我使用这个在我的安全过滤器中:

I use this in my security filter:

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 ( auth:false)
      }
    }
  }
}



<

and I have created a user in my bootstrap:


    def adminRole = new Role(name: "Administrator")
    adminRole.addToPermissions("secured1")
    adminRole.addToPermissions("secured2:create,save,edit,update")
    adminRole.save()

    def user = new User(username: "admin", passwordHash: new Sha512Hash("***").toHex())
    user.addToRoles Role.findByName('Administrator')
    user.save()

,它可以工作。问题是,它也保证了所有的控制器/操作。

and it works. Problem is, that it also secures all controllers/actions.

我希望,可以不指定我想在我的SecurityFilter中保护的操作,但只有在权限..但这是可能的吗?

I was hoping, that it would be possible to NOT specify the actions I want to protect in my SecurityFilter, but only in the permissions.. But is this possible?

推荐答案

静态属性'过滤器'允许您定义多个过滤模式。您可以使用'uri'参数或'controller'参数。如果你使用'控制器',你也可以添加一个'action'参数。这些参数中的每一个都需要一个正则表达式,因此您可以执行以下操作:

The static property 'filter' allows you to define multiple filtering patterns. You can use the 'uri' parameter or the 'controller' parameter. If you use 'controller' you can also add an 'action' parameter. Each of these parameters takes a regular expression so you can do stuff like:

admin(uri:"/admin/**")
...
browseStore(controller:"store", action:"(show|list)")
...
shopStore(controller:"store", action:"*")
...

查看 http://www.grails.org/Filters 了解更多信息。

这篇关于使用Shiro插件保护Grails应用程序中的一些但不是全部页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆