Identity Management in Seam 2.1.1
Last week I persisted an user using the JPAIdentityStore delivered by Seam.
Following the documentation made me really fast getting some code to run.
Though there were some pitfalls:
- The entityManager problem
My app denied to persist the user although I declared a persistence context using<persistence:managed-persistence-context
persistence-unit-jndi-name="java:/myEntityManagerFactory"/>and had the jpa identity store config pointing towards my implemented classes
<security:jpa-identity-store
user-class="de.jicken…..entity.MyUser"
role-class="de.jicken…..entity.MyRole"/>in components.xml.
Debugging revealed that I had to give the PC a name of entityManager as of
if (entityManager == null)
{
entityManager = Expressions.instance().createValueExpression("#{entityManager}", EntityManager.class);
}in JpaIdentityStore.java.
Now the working config looks like
<persistence:managed-persistence-context
name="entityManager"
auto-create="true"
persistence-unit-jndi-name="java:/myEntityManagerFactory"/>
After thinking about my mistake I came to the conclusion that it would be a lot clearer if there’s some indirection like<persistence:managed-persistence-context
name="anotherNameForEntityManager"
auto-create="true"
persistence-unit-jndi-name="java:/myEntityManagerFactory"/><security:jpa-identity-store
entity-manager="anotherNameForEntityManager"
user-class="de.jicken…..entity.MyUser"
role-class="de.jicken…..entity.MyRole"/>so that you can map the identity store to whatever persistence context you’d like.
- The password hashing problem
I chose the following for hashing and validating the user’s password:
@NotNull
@Length( min = 5, max = 15 )
@UserPassword( hash = "md5" )
public String getPassword() {
return password;
}This led me to a validation exception because the validation was made upon the already hashed password and my given boundaries didn’t match anymore.
The only thing to do was extending the max value to 50.@Length( min = 5, max = 50 )
This requires further investigation as this is not my preferred solution. I am thinking about assigning the password to a temporary variable for validation and then setting the validated password to my @UserPassword annotated variable to get the hash.
Update:
I asked for problem #1 at the seam forums … result: there’s no problem. I haven’t found any word about that in the documentation but it’s there as suggested above: just use the attribute entity-manager of jpa-identity-store to point to another persistence context.
Read the answer here.
Powered by Qumana


