[keycloak-user] Custom Keycloak UserStorageProvider not used when using a Local interface

Niels Bertram nielsbne at gmail.com
Sat Feb 10 20:34:11 EST 2018


Strange thing, if I create a Local interface for the UserStorageProvider
and then register a corresponding Stateful bean I can return it with the
provider factory but Keycloak refuses to use it, even though the actual EJB
implements all the other required interfaces.

Obviously I cannot extend the local interface with all the SPI interfaces
but I would have thought that it is enough for me to return a ? extends
UserStorageProvider from the provider factory and KC would be able to run
with this. Whacking a @Local on the actual EJB bean as in the keycloak
example
<https://github.com/keycloak/keycloak/blob/2b65adc15fe617fe0a61c49e7c99f39bab144985/examples/providers/user-storage-jpa/src/main/java/org/keycloak/examples/storage/user/EjbExampleUserStorageProvider.java#L58>
a) does not allow the programming to interfaces and b) generates a big fat
warning in Intellj that it is bad practice.

Any comments, thoughts or ideas on how fix this?

*Local interface*

@Local
public interface CustomUserStorageProvider extends UserStorageProvider {

  KeycloakSession getSession();

  void setSession(KeycloakSession session);

  ComponentModel getModel();

  void setModel(ComponentModel model);

}

*The EJB*

@Stateful
@Local( CustomUserStorageProvider.class)
public class CustomUserStorageProviderBean implements
  CustomUserStorageProvider,
  UserLookupProvider,
  CredentialInputValidator,
  CredentialInputUpdater,
  UserRegistrationProvider,
  UserQueryProvider {

  ...

}

Another thing I noticed, even if following the JPA example to the letter, a
properly annotated EJB lifecycle method @PreDestroy is never called as the
EJB is yanked from the context by (container) unmanaged code. I can sort of
see why but not sure this is ideal. Wouldn't it be possible to "weld" the
providers together in Keycloak ... something along the lines of
CDI.current().getBeanManager() in the provider factory?


More information about the keycloak-user mailing list