0

I need to create a webapp that has a login system. the user should authenticate against a database. I want to save the userrole in session - or are there other (better) ways?

Furthermore there are areas for user access. Guest area, user area, admin area.

The question now is. How can I easily implement the authorization with jsf2.0? I don't want to test on each site, if the user is permitted to acces the site or not.

Is there a configuration in web.xml or faces-config.xml that test the cases?

Can someone show me a tutorial or sample code?

Thanks and best regards veote

veote
  • 1,400
  • 9
  • 33
  • 62
  • Websphere Application Server 8.0 – veote Mar 16 '12 at 13:44
  • "I don't want to test on each site, if the user is permitted to acces the site or not." can you elaborate 'each site', are you looking single point authentication for multiple sites? or did you mean checking on each page/link ?? – baba.kabira Mar 16 '12 at 13:59
  • [link @ SO might help](http://stackoverflow.com/questions/1187949/jsf-authentication-and-authorization) – baba.kabira Mar 16 '12 at 14:04

3 Answers3

2

You can also look at options (Framewroks)

  1. Spring Security
  2. Apache Shiro
  3. Java EE Security Tutorial
  4. As already suggested Application Server provided Authentication/Authorization.
  5. Implement a Filter (Custom home grown logic for Authentication/Authorization)

Blogs covering AnA in JSF

  1. User session filter
  2. Access Control in JSF using a PhaseListener

Hope this helps

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
baba.kabira
  • 3,111
  • 2
  • 26
  • 37
0

You can try this approach, it uses PhaseListener to check if user has rights for accessing current site during the RESTORE_VIEW phase. It is quite easy to implement it and it's portable between different servers(opposite from realms)

Petr Mensik
  • 26,874
  • 17
  • 90
  • 115
  • Thanks, that seems nice. Is there maybe another way to configure this in web.xml / faces-config? – veote Mar 16 '12 at 13:54
  • Well, not really in such a good manner. You can specify the restricted pages and how to log the user, but it usually works fine only with realms(and that is sometimes hard to set it all up and wire it together). And BTW, why do you want use just these xml files?Seems to me more cleaner and readeble to stick with classic programming style instead of bothering yourself with XML – Petr Mensik Mar 16 '12 at 14:01
0

I am not familiar with Websphere, but since it is a Java EE 6 compliant application server, you can create a JDBCRealm for this purpose. See this chapter of the Java EE 6 tutorial.

Matt Handy
  • 29,855
  • 2
  • 89
  • 112
  • Thank you, but I for me it's not the best way I think, because maybe I want to change the db with a ldap. – veote Mar 16 '12 at 13:53
  • 1
    @veote I use weblogic but changing authentication provider in a realm is not that hard you can switch technologies with ease. – baba.kabira Mar 16 '12 at 14:02
  • If you look at the example in the tutorial (and from my experience), I agree with gbagga that switching should not be that complicated. – Matt Handy Mar 16 '12 at 14:04