JpaIdentityStore throws IllegalArgumentException
vincent.crepin Mar 11, 2009 3:43 PMHello all. I have a strange problem using the JPAIdentityStore. I'm using seam 2.1.1.GA with Jboss 4.3 (jbdevstudio).
I followed the documentation into setting up the store. In components.xml, I declared it:
<security:jpa-identity-store user-class="com.tm.mfx.securitymanager.domain.User" role-class="com.tm.mfx.securitymanager.domain.UserRole" entity-manager="#{securityManagerEntityManager}" >
The referenced classes reside in a jar at the root of the ear.
User is annotated as it should be
@UserPrincipal @Column(name = "USERNAME", nullable = false, length = 50) @NotNull @Length(max = 50) @Pattern(regex="^\\w*$", message="Not a valid username") public String getUsername() { return this.username; } public void setUsername(String username) { this.username = username; } @UserPassword(hash="md5") @Column(name = "PASSWORD", nullable = false, length = 100) @NotNull @Length(max = 100) public String getPassword() { return this.password; } public void setPassword(String password) { this.password = password; } @UserRoles @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user") public Set<UserRole> getUserRoles() { return this.userRoles; } public void setUserRoles(Set<UserRole> userRoles) { this.userRoles = userRoles; }
When I try to login, The JPAIdentityStore is correctly instantiated (I debugged it) and the user is fetched from the database but when trying to access the username property
protected String getUserAccountSalt(Object user)
{
return userPrincipalProperty.getValue(user).toString();
}
It always throws java.lang.IllegalArgumentException: Could not invoke method by reflection: User.getUsername() on: com.tm.mfx.securitymanager.domain.User.
I traced it to the reflection call
public static Object invoke(Method method, Object target, Object... args) throws Exception { try { return method.invoke( target, args ); } catch (IllegalArgumentException iae) { String message = "Could not invoke method by reflection: " + toString(method); if (args!=null && args.length>0) { message += " with parameters: (" + Strings.toClassNameString(", ", args) + ')'; } message += " on: " + target.getClass().getName(); throw new IllegalArgumentException(message, iae); } catch (InvocationTargetException ite) { if ( ite.getCause() instanceof Exception ) { throw (Exception) ite.getCause(); } else { throw ite; } } }
and the documentation says that for an IllegalArgumentException to be thrown, the target must be of the wrong type. I inspected the provided userClass and target at runtime and they are exactly of the same class (User). I even created a small test in which I reproduce what the store is doing (fetching a user and trying to get the username property on it using
AnnotatedBeanProperty<UserPrincipal> userPrincipalProperty
and it worked.
Anybody has an idea ?