JSF - Role Based Page Display

I am running a web application project using JSF 2.0 and PrimeFaces. One of the requirements would be to display different materials based on the user's role. For instance. only administrators should see the menu item - User Administration.

In safety I will ride for Spring security.

How can this be achieved in an elegant way? Should I create an xhtml template for everyone and then create different pages for each role with user interface elements for a specific role?

thanks

+4
source share
1 answer

Just use the rendered attribute + role checking in components, for example, for a submenu:

 <p:submenu label="#{msg['header.management']}" rendered="#{request.isUserInRole('INTERNO')}"> <p:submenu label="#{msg['header.roles']}" icon="ui-icon-contact"> <p:menuitem value="#{msg['header.newRole']}" url="/pages/addRole.jsf" /> <p:menuitem value="#{msg['header.mngRoles']}" url="/pages/viewRole.jsf" /> </p:submenu> 

Being the "INTERNO" role defined in Spring. I think it is quite elegant.

To disable navigation for this pafe (or set of pages), you still have to add a hook to your spring-security.xml , for example:

 <intercept-url pattern="/pages/*Role*" access="hasRole('INTERNO')" /> 
+10
source

Source: https://habr.com/ru/post/1437755/


All Articles