We have a requirement to replace our current login, for a web-application written in JSF using single sign-on. Currently our login.jsp invokes the authenticate method on a backing bean to achieve this and perform additional role validations. Now authentication will be done by my single sign-on server, but how do i invoke the authenticate method on the backing bean to perform the role validations
A:
Set request parameters as managed properties and use the @PostConstruct
annotation to execute some code immediately after bean construction and managed property setting.
You can set GET or POST request parameters as managed properties as follows:
<managed-bean>
<managed-bean-name>bean</managed-bean-name>
<managed-bean-class>mypackage.Bean</managed-bean-class>
<managed-bean-scope>request</managed-bean-scope>
<managed-property>
<property-name>name1</property-name>
<value>#{param.name1}</value>
</managed-property>
<managed-property>
<property-name>name2</property-name>
<value>#{param.name2}</value>
</managed-property>
</managed-bean>
Or if you're already on JSF 2.0, then you can just use @ManagedProperty
:
@ManagedProperty(value="#{param.name1}")
private String name1;
@ManagedProperty(value="#{param.name2}")
private String name2;
Those parameters will be set when the enduser fires a GET or POST request with a name1=value1&name2=value2
query string. The #{param.name1}
EL expression basically stands for the result of request.getParameter("name1")
.
Now create a @PostConstruct
method like follows:
@PostConstruct
public void init() {
if (name1 != null && name2 != null) {
// Both request parameters are been set. Do your thing here!
}
}
BalusC
2010-07-08 11:10:30