VisibleOnRole for PrimeFaces Components

UI Components for JSF
vinayarammohan
Posts: 43
Joined: 09 Feb 2011, 20:41

09 Feb 2011, 20:45

Hi,

I just downloaded Primefaces2.2
I have used Tomohawk in the past and want to switch to Primefaces.
Is there a visibleOnRole attribute for the prime faces components to make them visible on the security role?
Is this something which will be added in near future?

Thanks
Vinaya
SWF 2.2.1/JSF 2.0/Jboss 6.0/Spring3.0/PrimeFace 3.2

User avatar
bumble.bee
Posts: 723
Joined: 29 Sep 2010, 21:39
Location: United States

10 Feb 2011, 15:46

You can use the rendered attribute to conditionally render a component.

PrimeFaces does provide a few EL functions that help with page authorization:

ifGranted(String role)
ifAllGranted(String roles)
ifAnyGranted(String roles)
ifNotGranted(String roles)
remoteUser()
userPrincipal()

See page 432 of Userguide.

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

10 Feb 2011, 17:10

Yes, we have the EL extensions for that;

http://cagataycivici.wordpress.com/2010 ... orization/

vinayarammohan
Posts: 43
Joined: 09 Feb 2011, 20:41

17 Mar 2011, 16:44

Hi Optimus.Prime,

I am using the ifGranted for the menu item in menubar as follows

Code: Select all

<p:menubar effect="NONE"  styleClass="wijmo-wijmenu-horizontal">
	<p:submenu label="Search" rendered="#{p:ifGranted('USERADMIN')}">
			<p:menuitem value="Stock" url="stock"  />
			<p:menuitem value="Supply" url="supply"/>		
	</p:submenu>	
	<p:menuitem value="Logout" url="logout"  />			
</p:menubar>
The user has the role USERADMIN, but #{p:ifGranted('USERADMIN')} is returning false.

Any suggestions??

Thanks
Vinaya
SWF 2.2.1/JSF 2.0/Jboss 6.0/Spring3.0/PrimeFace 3.2

priyaesh
Posts: 26
Joined: 07 Feb 2011, 03:37

24 Mar 2012, 11:03

Hi Vinaya/Optimus

I am facing the same issues. Did you get this to work? I have my authorization and authentication done in my application using SpringSecurity. I always am getting FALSE when using - #{p:ifGranted('ROLE_ADMIN') for rendering purpose. I have ROLE_ADMIN and Users defined in Spring appcontext config file.

Do you know how this Primefaces EL function knows about SpringSecurityContext ??

Appreciate any quick response

Regards
Priyaesh

Primefaces 3.2, Spring 3, SpringSecurity 3
priyaesh

Primefaces 4, JSF 2.1, Spring 3.2, SpringSecurity 3, JPA 2.0, Tomcat 7

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

24 Mar 2012, 15:33

See the following topic, and search stackoverflow/google for related content/topic.

http://stackoverflow.com/questions/5933 ... t-el-expre

I'm not using Spring, but I have been thinking about adding something like this at some point. If I was you, I would see what Spring has to offer for your xhtml/JSF, and reference some bean attribute value related to user role, etc...

Also see following (I like searching for BalusC responses to JSF topics):

stackoverflow balusc jsf el expression authorize role
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

priyaesh
Posts: 26
Joined: 07 Feb 2011, 03:37

25 Mar 2012, 08:29

First of all Thanks Smith for reading my post and sharing few thoughts..

I went through a post in the forum. Is all the p:xxx EL functions compatible with Spring security ??

viewtopic.php?f=3&t=4233

Also recently a bug has been fixed (in 3.2 version) on parsing issue in SecurityUtils.

http://code.google.com/p/primefaces/iss ... il?id=3499

Also Oleg has commented the use of container based authentication here

http://ovaraksin.blogspot.in/2011/03/js ... based.html

But what I couldnt find is How/Will these primefaces EL tags would work with spring security or JEE authentications ???

Any idea?

Optimus/Oleg

Your thoughts ??
priyaesh

Primefaces 4, JSF 2.1, Spring 3.2, SpringSecurity 3, JPA 2.0, Tomcat 7

cagatay.civici
Prime
Posts: 18616
Joined: 05 Jan 2009, 00:21
Location: Cybertron
Contact:

25 Mar 2012, 11:55

It has been a long time since I've used spring security but I remember if you have HTTPContextIntegrationfilter in filter chain it will work as this filter wraps httpservletrequest which these security el functions ask to see if user is in role.

javascope
Posts: 1
Joined: 01 Nov 2012, 16:04

01 Nov 2012, 16:21

Code: Select all

The user has the role USERADMIN, but #{p:ifGranted('USERADMIN')} is returning false.
when i implemented custom Authentication class, i encountered with the same case.

Later, i used the standard Authentication class like UsernamePasswordAuthenticationToken and then everything(ifGranted, ifAnyGranted,...) worked as it should be

regards,

User avatar
RodrigoSieja
Posts: 5
Joined: 21 Oct 2013, 18:03

28 Nov 2013, 01:44

And what's the solution for applications using JAAS for authentication and authorization?

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 29 guests