Search

4.6. Identifying User Roles

download PDF
RichFaces also lets you check whether the logged-in user belongs to a certain user role with the rich:isUserInRole(Object) function. This function takes a String or a comma-delineated list of Strings, a Collection, etc. as arguments and returns a Boolean value.
As an example, imagine that you need to render some controls only for administrators. To do so, create an administrator role (admin) in your web.xml file. Then implement authorization that assigns the admin role to the user that has logged in as an administrator. Once this has been done, you can use the rich:isUserInRole(Object) function with the rendered attribute of any component. For example:
...
<rich:editor value="#{bean.text}"  rendered="#{rich:isUserInRole('admin')}" />
...
Here, only a logged-in user with an admin role can see the text editor, which will not be rendered for users with other roles.
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.