Keycloak provider and user storage

旧城冷巷雨未停 提交于 2020-01-01 18:57:05

问题


I have a running java ee application and now i want to integrate keycloak as authentication server. The only thing i have troubles is the user storage. I want to have all the user data in my java application.

The problem now: If the user registers on the keycloak frontend, my java application doesn´t know that the user has registered, so i cannot create a new entity. I found out that keycloak is able to load some custom modules (https://keycloak.github.io/docs/userguide/keycloak-server/html/providers.html) but i haven´t found any examples.

Is there any solution where keycloak notifys my java application when the user registered?


回答1:


I have had the same problem and I have resolved it using a filter. I just check if the principal exist and if not I insert it into my application DB:

KeycloakSecurityContext ctx = (KeycloakSecurityContext)request.getAttribute(KeycloakSecurityContext.class.getName()); User userEntity = em.find(User.class, ctx.getToken().getSubject()); if (userEntity == null) { ....create user... } You can also use an event listener (keycloak events listener) as shown in Example Event Listener that prints events to System.out, but for this exact use case that solution was easier and faster.




回答2:


You have to implement a custom Authentication SPI (inside success() method you create user on your app), deployed it , and add it to the registration flow

Keycloak documentation : Link



来源:https://stackoverflow.com/questions/37053594/keycloak-provider-and-user-storage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!