java - 如何在 apache shiro 中为不同的角色使用不同的未经授权的 url

标签 java jsf-2.2 shiro

我一直在尝试为网络应用程序的 shiro.ini 文件的 url 部分中的不同角色分配不同的未经授权的 url,但我似乎无法做到这一点。下面是我尝试过的代码。

shiro.ini 文件

[main]

    authc1 = org.apache.shiro.web.filter.authc.FormAuthenticationFilter
    authc2 = org.apache.shiro.web.filter.authc.FormAuthenticationFilter

    authc1.loginUrl = /login.xhtml
    authc2.loginUrl = /secLoginPage.xhtml 


[urls]
    /login.xhtml = authc1
    /secLoginPage.xhtml  = authc2
    /testapp/** = authc1, roles[admin,unauthorizedUrl=/adminAuthPage.xhtml]
    /userfld/**=authc2,roles[user,unauthorizedUrl=/abortPage.xhtml]
    /** = authc1
    /** = authc2

登录到应用程序后,它重定向到授权页面并出现错误 Error 401: SRVE0295E: Error reported: 401

此错误发生在我添加 unauthorizedUrl=/adminAuthPage.xhtml 之后。 如果代码中有任何错误,请提出建议。

最佳答案

你如何制作一个未经授权的页面,现在在他的页面上充当入口点,重定向到所需页面

403.jsp

<shiro:hasRole name="admin">
    <c:redirect url="adminAuthPage.xhtml"/>
</shiro:hasRole>

<shiro:hasRole name="user">
    <c:redirect url="abortPage.xhtml"/>
</shiro:hasRole>

或者如果你只是想让管理员有另一个页面,那就更好了

 <shiro:hasRole name="admin">
        <c:redirect url="adminAuthPage.xhtml"/>
 </shiro:hasRole>
<shiro:lacksRole name="admin">
    <c:redirect url="abortPage.xhtml"/>
</shiro:lacksRole>

关于java - 如何在 apache shiro 中为不同的角色使用不同的未经授权的 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27392979/

相关文章:

java - 如何在jsp中迭代一组代码?

java - 从文本文件中读取数据以计算并将数据写入另一个文本文件中

java - 使用嵌套 For 循环初始化 2D 数组的值

css - 如何修复 <p :panelGrid>? 的列宽

security - 检索 Shiro 主体

java - Tess4J Mac : NoClassDefFoundError

mojarra - JSF : Mojarra 2. 1 到 2.2 迁移导致 ViewExpiredException

javascript - 从javascript中的托管bean获取返回值

java - 无法在自定义 Apache Shiro AuthorizingRealm 中 @Inject 我的 DAO

grails - Grails 应用程序中的 shiro 配置错误