如何根据spring-security用户权限生成内容

发布于 2024-09-26 05:43:04 字数 193 浏览 0 评论 0原文

我想根据使用spring-security登录的用户的用户权限生成一些html内容。到目前为止,我在互联网上找不到太多关于这个主题的信息,我想知道什么是实现这个主题的好方法。

到目前为止,我正在考虑制作一个自定义标签,将其附加到一个控制器,该控制器链接到一个可以生成菜单等的类。我只是不确定如何从 spring-security 获取用户的用户角色/权限。

I want to generate some html content based on the user rights of a user who logged in with spring-security. I can't find much about this subject on the internet so far and i'm wondering what would be a good way to implement this.

So far i was thinking about making a custom tag, attach it to a controller who links to a class that can generate, for example, the menu. I'm just not sure how get the user roles/rights of the user from spring-security.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无悔心 2024-10-03 05:43:04

检查 spring security 标签以根据用户角色创建动态内容。 Spring Security Taglibs 参考

Check the spring security tags to create dynamic content based on user roles. Spring Security Taglibs reference.

深陷 2024-10-03 05:43:04

像这样的事情怎么样:

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
...
<body>

Shared content for all roles.
<sec:authorize access="hasRole('roleName1')">
    content for roleName1
</sec:authorize>
<sec:authorize access="hasRole('roleName2')">
    content for roleName2
</sec:authorize>
More shared content for all roles.
</body>

How about something like this:

<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
...
<body>

Shared content for all roles.
<sec:authorize access="hasRole('roleName1')">
    content for roleName1
</sec:authorize>
<sec:authorize access="hasRole('roleName2')">
    content for roleName2
</sec:authorize>
More shared content for all roles.
</body>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文