基于用户角色的JSF重定向页面
我有两种类型的管理员。 超级管理员和普通管理员 两者都从admin.xhtml页面开始 我想将超级管理员用户转发到super-admin.xhtml,将普通管理员转发到normal-admin.xhtml基于用户角色的JSF重定向页面,jsf,jsf-2,spring-security,Jsf,Jsf 2,Spring Security,我有两种类型的管理员。 超级管理员和普通管理员 两者都从admin.xhtml页面开始 我想将超级管理员用户转发到super-admin.xhtml,将普通管理员转发到normal-admin.xhtml 如何在JSF中做到这一点?我使用的是Spring Security?我不熟悉JSF,但假设它在后台运行,就像Spring MVC JSP应用程序一样,您可以让控制器根据用户所扮演的角色提供不同的页面: @RequestMapping("/admin.xhtml") @PreAuthorize(
如何在JSF中做到这一点?我使用的是Spring Security?我不熟悉JSF,但假设它在后台运行,就像Spring MVC JSP应用程序一样,您可以让控制器根据用户所扮演的角色提供不同的页面:
@RequestMapping("/admin.xhtml")
@PreAuthorize("hasAnyRole('ROLE_ADMIN', 'ROLE_SUPERADMIN')")
public String getAdminPage(Modelmap model, Principal principal) {
Collection<? extends GrantedAuthority> authorities = SecurityContextHolder.getContext().getAuthentication().getAuthorities();
for (GrantedAuthority authority : authorities) {
if (authority.toString() == "ROLE_SUPERADMIN") { return "superadminpage"; }
}
//no need to check for admin privileges, since the annotation took care of that
//if you're not using annotations (or @PostAuthorize), you'd have to capture the
//'admin' role as well, and adjust the return statements accordingly.
return "adminpage";
}
在admin.xhtml页面上,您希望重定向到不同页面的操作是什么?