IdentitySessionFactory identitySessionFactory = EnvironmentImpl.getFromCurrent(IdentitySessionFactory.class);
try {
IdentitySession identitySession = identitySessionFactory.createIdentitySession(realmName);
EnvironmentImpl environment = EnvironmentImpl.getCurrent();
StandardTransaction transaction = environment.get(StandardTransaction.class);
if (transaction != null) {
IdentitySessionResource identitySessionResource = new IdentitySessionResource(identitySession);
transaction.enlistResource(identitySessionResource);
}
return new JBossIdmIdentitySessionImpl(identitySession);
} catch (IdentityException e) {
throw new JbpmException("couldn't create the identity session for realm [" + realmName + "]");