Multiple Seam Identities
cbkihong.cbkihong.hotmail.com Jul 20, 2008 4:09 AMI am trying to build a webapp with Seam but am apparently faced with a need to create multiple Seam identities. This is because there are at least two types of users logging in with different sets of credentials:
- Group I: Company ID + password
- Group II: Company ID + Staff ID + password
and there is likely more groups added in the future, but I don't have the details yet.
So, the immediate thought is to create multiple identity components like this:
<security:identity class="com.xxx.Group1Identity" name="g1Identity" authenticate-method="#{g1_authen.authenticate}" />
<security:identity class="com.xxx.Group2Identity" name="g2Identity" authenticate-method="#{g2_authen.authenticate}" />
The index.jsp, the login page, is just something ordinary. This is an example of login form (simplified) for Group I user:
Company: <h:inputText value="g1Identity.companyId" />
Password: <h:inputText value="g1Identity.password" />
<a4j:commandButton action="#{g1Identity.login}" />
Before I changed the command button action to this, I used the authenticator #{g1_authen.authenticate} directly and things appear to be fine and seeing the Hibernate SQL dumped in the console, but once I changed to the identity.login for action I am no longer able to see those and authentication always failed. I saw:
No authentication method defined - please define authenticate-method for <security:identity/> in components.xml
Appears like Seam cannot resolve the authentication method and probably not even the authenticator class at all.
package com.xxx;
import org.jboss.seam.security.Identity;
import org.jboss.seam.annotations.*;
@Name(value="g1Identity")
@Install(false)
public class Group1Identity extends Identity {
// Omitted
}
@Name("g1_authen")
@Scope(APPLICATION)
public class Group1Authenticator {
@In(create=true)
private EntityManager entityManager;
@In(value="g1Identity")
private Group1Identity identity;
public boolean authenticate() {
java.util.List dm = entityManager.createNativeQuery("...").getResultList();
return (dm.size() > 0);
}
}
Would anyone lend me a hand? It's Seam 2.0.3 CR1 I believe. Thank you.