我一直在尝试为网络应用程序的 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/