JBoss.orgCommunity Documentation

Chapter 7. Identity Management - Working with JPA

7.1. JPAIdentityStoreConfiguration
7.1.1. Recommended Database Schema
7.1.2. Default Database Schema
7.1.3. Configuring an EntityManager
7.1.4. Configuring the Identity class
7.1.5. Configuring the Attribute class
7.1.6. Configuring the Credential class
7.1.7. Configuring the Credential Attribute class
7.1.8. Configuring the Relationship class
7.1.9. Configuring the Relationship Identity class
7.1.10. Configuring the Relationship Attribute class
7.1.11. Configuring the Partition class
7.1.12. Providing a EntityManager

The JPA identity store uses a relational database to store identity state. The configuration for this identity store provides control over which entity beans are used to store identity data, and how their fields should be used to store various identity-related state. The entity beans that store the identity data must be configured using the annotations found in the org.picketlink.jpa.annotations package. All identity configuration annotations listed in the tables below are from this package.

The Identity class is the entity bean that is used to store the record for users, roles and groups. It should be annotated with @IdentityType and declare the following field values:


The following code shows an example of an entity class configured to store Identity instances:


Sometimes you may need to configure how the EntityManager is provided to the JPAIdentityStore, like when your application is using CDI and you must run the operations in the scope of the current transaction by using a injected EntityManager instance.

In cases like that, you need to initialize the SecurityContext by providing a ContextInitializer implementation, as discussed in Security Context Configuration. The JPAContextInitializer is provided by PicketLink and can be used to initialize the security context with a specific EntityManager instance. You can always extend this class and provide your own way to obtain the EntityManager from your application's environment.

IdentityConfigurationBuilder builder = new IdentityConfigurationBuilder();


builder
  .stores()
    .file()
      .addContextInitializer(new JPAContextInitializer(emf) {
        @Override
        public EntityManager getEntityManager() {
          // logic goes here
        }
      });
}

By default, the JPAContextInitializer creates a EntityManager from the EntityManagerFacatory provided when creating a new instance.