views:

434

answers:

2

Hello, 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.

+2  A: 

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)

Pascal Thivent
Thank you, i will try it.
ThreeFingerMark
+2  A: 

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}" />
BalusC
And how do i say that the User Class is load into the session scoped after login?
ThreeFingerMark
Either using sort of `UserManager` session bean with `login()` method and `user` property so that you can use `#{userManager.user != null}`, or by doing `externalContext.getSessionMap().put("user", user)` in login method of a bean.
BalusC
Thank you for your detailed answer. I will try this.
ThreeFingerMark