Shiro error redirection

折月煮酒 提交于 2020-01-07 03:53:09

问题


How can I make Shiro redirect errors in a Web app?

I have configured my web.xml

<error-page>
    <error-code>500</error-code>
    <location...</location>
</error-page>
<error-page>
    <error-code>404</error-code>
    <location>...</location>
</error-page>

And it works fine. But when Shiro is active and I raise a 500 error on purpose the page stays blank.


回答1:


I think I got it... It was blank because the method onAccessDenied() was returning false wherever a problem happened.

To fix it, one possible solution is this:

@Override
protected boolean onAccessDenied(ServletRequest request, ServletResponse response)
        throws Exception {
    if(!executeLogin(request, response)){
        //throw exception
    } else {
        return true;
    }
}

Of course make sure your error pages defined in web.xml are anon in your shiro.ini

e.g.

[urls]
/error500.xhtml = anon


来源:https://stackoverflow.com/questions/44848142/shiro-error-redirection

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!