Keycloak提供商和用户存储 [英] Keycloak provider and user storage

查看:235
本文介绍了Keycloak提供商和用户存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个正在运行的java ee应用程序,现在我想将keycloak集成为身份验证服务器。我唯一遇到麻烦的是用户存储。我想在我的java应用程序中拥有所有用户数据。

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.

现在的问题:
如果用户在keycloak前端注册,我的java应用程序不知道用户已注册,所以我无法创建新实体。我发现keycloak能够加载一些自定义模块( https: //keycloak.github.io/docs/userguide/keycloak-server/html/providers.html )但我没有找到任何例子。

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.

有没有解决方案,当用户注册时,keycloak通知我的java应用程序?

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

推荐答案

我遇到了同样的问题,我已经解决了它使用过滤器。我只是检查主体是否存在,如果没有,我将其插入我的应用程序数据库:

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());
用户userEntity = em.find(User.class,ctx.getToken()。getSubject());
if(userEntity == null){
....创建用户...
}

您还可以使用事件监听器( keycloak events listener )如< a href =https://github.com/keycloak/keycloak/tree/master/examples/providers/event-listener-sysout\"rel =nofollow>将事件打印到System.out的事件监听器示例 ,但对于这个确切的用例,解决方案更容易,更快。

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.

这篇关于Keycloak提供商和用户存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆