JSF 2.0 how to display an element depending on user rights?

I am writing an application using JSF 2.0, java ee and glassfish.

My user interface is a simple xhtml containing jsf.

I want my user to log in and, depending on their rights, display another element on the same pages.

is jaas possible?

Thanks in advance Loic

+3
source share
1 answer

If you donโ€™t want to write code like a framework to do it โ€œbehind the scenesโ€, you can bind the visualized attribute of the component to a method that checks the user's access rights, for example.

public boolean isUserAllowedAccess() {
        return FacesContext.getCurrentInstance().getExternalContext().
           isUserInRole("ROLE_ADMIN");
         // or whatever authorization code you want
    }

and then refer to it in the "rendered" attribute of your JSF tags, for example.

rendered="#{authBean.userAllowedAccess}"

, , .

<h:panelGroup rendered="#{authBean.userAllowedAccess}">
+6

All Articles