Form based authentication in JSF

Is form based authentication available in JSF?
[53 byte] By [Y_NOTa] at [2007-10-2 7:30:55]
# 1

Not directly... But it is quite possible. It's not even technically a work-around, it's just not immediately obvious on how to do it.

What you basically want to create is a validation method that will check all the appropriate fields on your form.

There's basically two ways to do full form authentication. The first is to use the "validator" attribute on the last component on your form. It has to be the last one! The reason is that the rest of the fields will get validated and updated from the top down. Then, on your last component, you can refer the validator attribute to the method that checks all your form data.

The second method of doing this, which is the one I prefer, is to create a hidden field after all other input components on the page. Again, this has to be the last component in the form on your page (except for buttons or links). Set the hidden fields validator attribute to the method that checks the form. You hidden field should look like this:

<h:inputHidden id="whatever" value="required" validator="#{backingBean.method}" required="true" />

There's security reasons (apparently) for setting the field value and making the field required.

This is a FAQ. Try searching the forums for more information.

CowKing

IamCowKinga at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
No Bro, you have been misunderstood, what I mean is through <login-config><auth-method>FORM</auth-method>I am using this, but it working in JSP, but unfortunately not working in JSF.Is anybody have any idea?
Y_NOTa at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
use verbatim tags and output HTML directly. its not ideal but it will get the job done.
silkcutultraa at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
the problem is that JSF will render a foo:bar:prefix syntax inforont of the input fields, J2EE security requires you to post to a servlet also, and it is not easy to do using the JSF navigation model.
silkcutultraa at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

I'm using form based authentication in a JSF app. The simplest way is to leave the login and login_error pages outside of the jsf scope.. of course you will lose some functionality, but IMO it could be accepted for those two pages only.

I don't know if it works for all servlet containers, but using client-side state saving my JSF app is also session timeout tollerant (the components tree state is restored even after a timeout->login->return to page).

Cosmaa at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6
See the J2EE Security - A JSF based Login Form article by Duncan Mills.See his blog. http://groundside.com/blog/DuncanMills.php?s=Container+Managed+Security+for+JSF&submit.x=0&submit.y=0
mhavrdaa at 2007-7-16 21:10:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...