Spring Security defaultsuccessurl用于不同的角色?

时间:2017-07-24 12:45:34

标签: spring-boot spring-security thymeleaf

我有三个不同的角色,但我不知道如何在登录后为每个角色添加不同的页面,是否可以添加一些内容以将每个角色重定向到其页面? 我使用百里香和弹簧安全

1 个答案:

答案 0 :(得分:1)

您可以在页面中包含不同的内容以获取不同的角色

<div sec:authorize="hasRole('ROLE_ADMIN')">
    Content for administrators
</div>
<div sec:authorize="hasRole('ROLE_USER')">
    Content for users
</div>

例如,每个角色可以是不同的片段

<div th:include="pages/welcome :: welcome_admin" sec:authorize="hasRole('ROLE_ADMIN')></div> 

<div th:include="pages/welcome :: welcome_user" sec:authorize="hasRole('ROLE_USER')></div>
相关问题