Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best practice for the user authentication on JSF 2.0?

i search for the best way how i can make a user authentication in my JSF Webproject. I have found this very good Example from BalusC at stockoverflow (by the way Thank you BalusC). But i dont understand this System.

I have written a registration page. After the registration the user is into my database. But who can i use the j_security_check to check the the user from my database?

In my webproject i don't have a site for users and for non-users. When a user is loged in so he see more options for example he can post a text. Who can i check this? Can i save the User Class with the userdata at the login and check:

if(user != null){
 <h:inputText value="User Only Text" id="text"  />
}

But i think this way is not very elegant. Also my Question is what is the best way to make a user login and show the valid user more options on the webpage than a non-user.

Thank you and sorry for my bad english.

like image 285
ThreeFingerMark Avatar asked Feb 27 '23 12:02

ThreeFingerMark


2 Answers

Just declare user as a session scoped managed bean and make use of the component's rendered attribute.

<h:inputText value="User Only Text" id="text" rendered="#{user != null}" />
like image 56
BalusC Avatar answered Mar 04 '23 02:03

BalusC


But how can I use the j_security_check to check the the user from my database?

This article explains how to use HTTP FORM based authentication in conjunction with JDBC realms within Glassfish.

what is the best way to make a user login and show the valid user more options on the webpage than a non-user.

Basically, you need to check if the user has the appropriate role to see the "options". Have a look at ExternalContext#isUserInRole(String)

like image 45
Pascal Thivent Avatar answered Mar 04 '23 00:03

Pascal Thivent