How do I obtain the 'reason' for a forbidden()?

六眼飞鱼酱① 提交于 2019-12-25 05:17:13

问题


I'm designing my 403 page and I can't seem to obtain the 'reason' string which I am populating on various forbidden pages to give a more relative response to the issue at hand. If I type ${response.reason} in the template, the whole page gets replaced with just the text of the response.


回答1:


In the code it seems that you can get this value in your template by doing

${result.getMessage()}

result is your Forbidden object that inherits from RuntimeException and the description you provide is passed to the base class as the exception message




回答2:


You don't want to provide any more reason the "Forbidden". From a security standpoint, the user has attempted an unauthorized operation, and the last thing you want do is tell them exactly what's wrong (unknown user, invalid password, etc). If you do this you are giving away information that could help the user penetrate your system.

For example, if you distinguish between unknown user and invalid password, you give away whether or not the userid exists.



来源:https://stackoverflow.com/questions/12630672/how-do-i-obtain-the-reason-for-a-forbidden

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