我有一个 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()
}
}
}
}
}
这将使每个人都可以访问 bookController
的 list
和 view
这两个操作。
希望有帮助...
关于grails - 访问 grails shiro 插件中的特定 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20612498/