removeUser works well in this case (Method called during startup) :
public class BoostrapUsers {
@PersistenceContext(type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
@Inject
private IdentityManager identityManager;
/**
* <p>Loads some users during the first construction.</p>
*/
//TODO this entire initialization code will be removed
@PostConstruct
public void create() {
JPAIdentityStoreContext.set(this.entityManager);
User user = this.identityManager.createUser("admin");
User user1 = this.identityManager.createUser("user1");
this.identityManager.updateCredential(user, new PasswordCredential("admin"));
this.identityManager.updateCredential(user1, new PasswordCredential("user1"));
Role roleDeveloper = this.identityManager.createRole("simple");
Role roleAdmin = this.identityManager.createRole("admin");
Group groupCoreDeveloper = identityManager.createGroup("Default Users Group");
identityManager.grantRole(roleDeveloper, user, groupCoreDeveloper);
identityManager.grantRole(roleDeveloper, user1, groupCoreDeveloper);
identityManager.grantRole(roleAdmin, user, groupCoreDeveloper);
identityManager.removeUser("user1");
JPAIdentityStoreContext.clear();
}
}
but when calling removeUser in my project, it removes all the users :
public void removeUser(String name){
User user = identityManager.getUser(name);
if(user != null){
identityManager.removeUser(user); // all users are now deleted
}
}
I can see in the logs that the SQL delete statement is called for each user record