【问题标题】:Apache Shiro using "unauthorizedUrl"Apache Shiro 使用“unauthorizedUrl”
【发布时间】:2021-06-07 12:47:56
【问题描述】:

我想用权限保护我的所有 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

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

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

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

【问题讨论】:

    标签: jsf shiro


    【解决方案1】:

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

    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
    

    随时通知我们!

    【讨论】:

    • 谢谢....我试过了,看来它也可以工作:anyofpermission = com.app.util.CustomPermissionsAuthorizationFilter # Protected URLs [urls] /portal/absenceReasonEdit** = authc, anyofpermission[customer:create, customer:showDetail]
    猜你喜欢
    • 2018-01-14
    • 2015-03-05
    • 2015-07-29
    • 2017-09-20
    • 2016-05-07
    • 2017-01-04
    • 2017-09-04
    • 2017-01-22
    • 2017-09-28
    相关资源
    最近更新 更多