Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于用户角色的JSF重定向页面_Jsf_Jsf 2_Spring Security - Fatal编程技术网

基于用户角色的JSF重定向页面

基于用户角色的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(

我有两种类型的管理员。 超级管理员和普通管理员

两者都从admin.xhtml页面开始

我想将超级管理员用户转发到super-admin.xhtml,将普通管理员转发到normal-admin.xhtml


如何在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页面上,您希望重定向到不同页面的操作是什么?