Apache Shiro 使用“unauthorizedUrl”

问题描述

我想用权限保护我所有的 JSF 页面。 例如。 portal/customerEdit.jsf 可以打开,前提是用户有“customer:create”权限。

这是我当前的 shiro-web.ini

    # Using default form based security filter org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc = org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc.loginUrl = /common/login.jsf
authc.successUrl = /portal/dashboard.jsf


# Redirect to an access denied page if user does not have access rights
[roles]
roles.unauthorizedUrl = /common/access-denied.jsf

# Protected URLs
[urls]
/portal/customerEdit** = authc,perms["customer:create"]

/WEB-INF/layout/portal/** = authc
/portal/** = authc
/admin/** = authc

安全性正在工作(用户只能打开页面,如果他有权限),但我只有一个带有简单文本的空白屏幕..

enter image description here

我想做的是将用户重定向到 access-denied.jsf 页面(如我定义的那样),但这不起作用....
一个信息:我没有使用“角色”...我所有的角色都是来自数据库的动态...

知道如何解决这个问题吗,用户将被重定向到 access-denied.jsf 页面

解决方法

您可能希望针对您在顶部(而不是 unauthorizedUrl 部分)中使用的过滤器设置 roles

perms.unauthorizedUrl = ...

或使用 shiro.unauthorizedUrl

全局设置

我的猜测是这样的:

# Using default form based security filter org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc = org.apache.shiro.web.filter.authc.FormAuthenticationFilter
authc.loginUrl = /common/login.jsf
authc.successUrl = /portal/dashboard.jsf

# Redirect to an access denied page if user does not have access rights
perms.unauthorizedUrl = /common/access-denied.jsf

# Protected URLs
[urls]
/portal/customerEdit** = authc,perms["customer:create"]

/WEB-INF/layout/portal/** = authc
/portal/** = authc
/admin/** = authc

随时关注我们!