如何检查用户是否有Spring Security的权限?
我检查了这个问题,我知道如何在java中获取和检查用户角色。
但是,我想要的是,当用户单击页面中的某些链接时,如果用户没有权限,我如何获取它并在消息字段中返回一些消息,例如“无权限”?目前,会有一个例外。
我没有在页面中使用 spring 标签,我知道只有用户具有某种角色时显示此链接的标签。但由于某些原因我不想使用这些标签。
I checked this question, and I know how to get and check user role in java.
But, what I want is, when user clicks some links in page, if user has no right on that, how can I get it and return some message like "no rights" in a message fields? Currently, there will be an exception.
I didn't use spring tags in page, I know the tags that display this link if only user has some role. But I don't want to user those tags for some reasons.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 JavaScript,处理链接上的单击事件并查看服务器响应。如果不行 - 显示错误消息。如果没问题 - 重定向。
像这样的东西:(
使用 jQuery 库)。
You can use JavaScript, handle the click event on the link and see the server response. If it's not ok - show error message. If it is OK - redirect.
Something like this:
(jQuery library is used).