[keycloak-user] Providers with CDI

Stian Thorgersen stian at redhat.com
Fri Nov 28 05:10:43 EST 2014


No, there's no example for this, but you can look at the Keycloak source as we use JPA ourselves.

You have two options:

a) Shared EntityManager instance with internal Keycloak providers - if you're using the same db for both this is a good option
b) Separate EntityManager instance

For option a) you should look at extending the default connectionJpa provider to add your own persistence.xml (you need to copy/modify Keycloak's persistence.xml). Look at https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa and https://github.com/keycloak/keycloak/tree/master/model/jpa.

For option b) you can just have your ProviderFactory create the EntityManagerFactory and pass it to the Provider instance. For this you only need to look at https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa.

----- Original Message -----
> From: "Alexander Chriztopher" <alexander.chriztopher at gmail.com>
> To: "Stian Thorgersen" <stian at redhat.com>
> Cc: keycloak-user at lists.jboss.org
> Sent: Friday, 28 November, 2014 11:01:46 AM
> Subject: Re: [keycloak-user] Providers with CDI
> 
> ok ! Are there any examples of using JPA ?
> 
> On Fri, Nov 28, 2014 at 10:54 AM, Stian Thorgersen <stian at redhat.com> wrote:
> 
> > No, afraid we don't support CDI (or any other managed features such as
> > EJBs) in our providers. They are just POJO's and Keycloak manages their
> > life-cycle.
> >
> > In the future we may make it simpler to create providers, but this is not
> > a priority atm.
> >
> > ----- Original Message -----
> > > From: "Alexander Chriztopher" <alexander.chriztopher at gmail.com>
> > > To: keycloak-user at lists.jboss.org
> > > Sent: Friday, 28 November, 2014 10:14:32 AM
> > > Subject: [keycloak-user] Providers with CDI
> > >
> > > Hi All,
> > >
> > > I there a way to get providers to be managed by CDI.
> > >
> > > The aim is to get access to services such as entity manager injection and
> > > lifecycle management which would be done manually today.
> > >
> > > Thanks for any help.
> > >
> > > _______________________________________________
> > > keycloak-user mailing list
> > > keycloak-user at lists.jboss.org
> > > https://lists.jboss.org/mailman/listinfo/keycloak-user
> >
> 


More information about the keycloak-user mailing list