I am testing the following component using SeamTest:
@Name("createUserService")
@AutoCreate
public class CreateUserService {
@In private IdentityManager identityManager;
public void createUser(
final String username,
final String password,
final String role) {
new RunAsOperation() {
public void execute() {
identityManager.createUser(username, password);
identityManager.grantRole(username, role);
}
}.addRole("admin")
.run();
}
}
Unfortunately, identityManager.grantRole() is failing with the following error:
org.jboss.seam.security.management.NoSuchUserException: Could not grant role, no such user 'jdoe' at org.jboss.seam.security.management.JpaIdentityStore.grantRole(JpaIdentityStore.java:277) at org.jboss.seam.security.management.IdentityManager.grantRole(IdentityManager.java:134) at org.archfirst.bullsfirst.domain.security.CreateUserService$1.execute(CreateUserService.java:45) at org.jboss.seam.security.Identity.runAs(Identity.java:734) at org.jboss.seam.security.RunAsOperation.run(RunAsOperation.java:84) at myApp.CreateUserService.createUser(CreateUserService.java:42)
Since the component is working perfectly well in the real app, can someone suggest what might be going wrong here? Is persistence not working in the test environment? I am using the same persistence.xml in test and app (using HSQL). I was seeing a warning earlier in the test environment about not having a persistent-permission-resolver which I cleared by putting the following in components.xml (in the test environment):
<security:persistent-permission-resolver permission-store="#{jpaPermissionStore}"/>
Still no luck!