2 Replies Latest reply on Mar 19, 2009 8:23 AM by Phil Forum

    IdentityStore and EntityManager with JTA transactions

    Kuba Stepniak Newbie

      I've been trying to do a following thing: I have two persistance units one for regular data and the other one for authentication. My application is deployed on JBoss AS with default transaction managment so implicitly it's JTA. My question is: how can I specify in components.xml file which entityManager should be used by identityStore? Or maybe identityStore recognises it automagically? Maybe I missed sth but I couldn't find any information on this issue. And I think it's more general because I didnt come across any examples of injecting JTA entityManagers into components in components.xml. Let's assume of course that it's not possible to do using annotations.


        • 1. Re: IdentityStore and EntityManager with JTA transactions
          Shane Bryzak Master

          You can set it in components.xml:

          <security:jpa-identity-store entity-manager="#{myEntityManager}"/>

          • 2. Re: IdentityStore and EntityManager with JTA transactions
            Phil Forum Newbie

            I still cannot get IdentityManagement to persist anything in the database. Read access works fine.

            My components.xml:

            <persistence:managed-persistence-context name="entityManager"
            <security:rule-based-permission-resolver security-rules="#{securityRules}"/> 
            <security:jpa-identity-store user-class="xx.martens.rdf.model.User"

            The following simple test shows, that users present in the database can be accessed, but a new user is not persisted:

            public class IdentityManagementTest extends SeamTest {
                 private static LogProvider log = Logging.getLogProvider(IdentityManagementTest.class);
                 public EntityManager getEntityManager()
                    return (EntityManager) getInstance( "entityManager" );
                 public void createUser() throws Exception {
                      new ComponentTest() {
                           String newUsername = "user_created_by_createUser";
                           protected void testComponents() throws Exception {
                                IdentityManager identityManager = IdentityManager.instance();
                                Credentials credentials = (Credentials) Component.getInstance(Credentials.class); 
                                Identity identity = Identity.instance();
                                // this is for being able to perform the operations below.
                                // the test itself:
                                log.debug("createUser returned: " + createUser(newUsername, newUsername));
                           private boolean createUser(String name, String password) {
                                IdentityManager identityManager = IdentityManager.instance();
                                return identityManager.createUser(name, password);

            Running the test above, I get the following:

            • No Exceptions are thrown.

            • The log output shows, that createUser() returns true.

            • The assertion assertTrue(identityManager.userExists(newUsername)) fails.

            Thanks, Phil