1

I have two types of admin. Super admin and normal admin.

Both start on the page admin.xhtml.

I want to forward super admin users to super-admin.xhtml and normal admin to normal-admin.xhtml.

How do I do this in JSF (I'm using Spring Security)?

DD.
  • 21,498
  • 52
  • 157
  • 246

1 Answers1

0

I'm unfamiliar with JSF, but assuming it functions under the hood just like a Spring MVC JSP application, you can have your controller deliver a different page depending on the role(s) held by the user:

@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";
}
cabbagery
  • 909
  • 7
  • 16