Facing new challenges everyday

bodyguard – Facelets EL functions for Spring Security

November 9th, 2008

Yesterday I wrote a small set of EL functions to use with spring security, now I can get easy access to spring security roles and authentication info as well.

Here’s an example of how bodyguard can be used in your facelets code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<html xmlns="http://www.w3.org/1999/xhtml"
   xmlns:bg="http://faces.eti.br/bodyguard">
 <body>
   <!-- Display logged message if the user is authenticated -->
   <t:div rendered="#{bg:isAuthenticated()}">
       <h:outputText rendered="#{bg:remoteUser()}" value="Logged!"/>
   </t:div>

   <!-- Display a message indicating if the user is a user or admin -->
   <t:div rendered="#{bg:isUserInAnyRoles('ROLE_USER,ROLE_ADMIN')}">
       <h:outputText
         value="The user #{bg:remoteUser()} is a user or admin."/>
   </t:div>

   <!-- Display a message indicating if the user isn't a user or admin -->
   <t:div rendered="#{bg:isUserNotInRoles('ROLE_USER,ROLE_ADMIN')}">
       <h:outputText
         value="The user #{bg:remoteUser()} isn't a user or admin."/>
   </t:div>

   <!-- Display a message indicating if the user is a user and admin -->
   <t:div rendered="#{bg:isUserInAllRoles('ROLE_USER,ROLE_ADMIN')}">
       <h:outputText
          value="The user #{bg:remoteUser()} is a user and admin."/>
   </t:div>
 </body>
</html>

You can download the bodyguard by clicking here and sources here.

Post to Twitter

6 Comments »

  1. Rafael Ponte says

    Interesting Rogerio!

    The friend of mine has implemented same thing too :) But, your implementation seems a little more complete!

    By any way, i\\\’ll show your code for him!
    Congratulations!

    November 9th, 2008 | #

  2. Wagner Santos says

    Very good! This is open source?
    Congratulations!

    November 11th, 2008 | #

  3. Chandima Janakantha says

    This is great!. I earlier tried to use acegi-jsf.jar to get this done.(with the modified one see http://vigilbose.blogspot.com/2008/06/integrating-spring-security-with.html) But when using 3rd party controls sometimes it’s not allowed to put additional tags around, when using nested components. But this approach works.

    I found only one mistake in the sample xhtml file
    {bg:isUserInAnyRoles(’ROLE_USER,ROLE_ADMIN’)} should be changed to
    {bg:isUserInAnyRole(’ROLE_USER,ROLE_ADMIN’)}

    November 18th, 2008 | #

  4. rogerio says

    I made some fixes on the post and in code too, thx for your comment Chandima!!!

    November 18th, 2008 | #

  5. duduzerah says

    O loco! Eu estava olhando o widget alí do lado.. bastante visitas ao redor do mundo. Que massa, parabéns!

    November 30th, 2008 | #

  6. marko says

    simply rocks
    thanks man,

    i permitted myself to adapt the code, nothing publishable as most of what did was very specific.

    thanks again,

    February 23rd, 2009 | #

Leave a comment

:mrgreen: :neutral: :twisted: :shock: :smile: :???: :cool: :evil: :grin: :oops: :razz: :roll: :wink: :cry: :eek: :lol: :mad: :sad:
Imagem CAPTCHA CAPTCHA Audio
Reapresentar imagem

RSS feed for these comments. | TrackBack URI

Visitors Around the World

Polls

How Is My Site?

View Results

Loading ... Loading ...

Categories

Meta

Links

hosted by easy2use.net