实现自定义KeyCloak Authenticator SPI的问题



我正在尝试实现针对外部身份提供商的身份验证的自定义键盘验证者SPI。用户已经存在于KeyCloak商店中,我只需要与自定义SPI的连接来验证它们。

我正在遵循官方指南的第8.3节https://www.keycloak.org/docs/latest/server_development/index.html#_auth_spi_walkthrough,这与我需要的非常相似。

我遇到的问题是 身份验证流插入自定义身份验证者的"动作"方法,从AuthenticationProcessor类中抛出了一个例外,在检查后,该类别来自以下检查:

 // org.keycloak.authentication.AuthenticationProcessor - line 876
    if (authenticationSession.getAuthenticatedUser() == null) {
         throw new AuthenticationFlowException(AuthenticationFlowError.UNKNOWN_USER);
    } 

在看到这个问题后,我尝试解决该问题的想法是从KeyCloak商店中获取用户(已经针对外部身份提供者进行了验证(,并将其推入了authenticationsessess,例如:

// Connect against external Service Provider
// and asume "USER_ID" represents an already validated User
// AuthenticationFlowContext = afc is given as parameter
UserFederationManager ufm = afc.getSession().users();   // <-- PROBLEM
UserModel userFound = ufm.getUserById("USER_ID", afc.getRealm());
if (userFound != null) {
    // get reference to the authSession
    AuthenticationSessionModel asm = afc.getAuthenticationSession();
    // set authenticated user on the session
    asm.setAuthenticatedUser(userFound );
    return true;
}
return false;

上述代码的问题是,java nosuchmethodexceptionError在org.keaycloak.models.KeycloackSession类的users()方法上被抛出。这样:

11:26:32,628错误[org.keycloak.services.error.keycloakerrorhandler](默认任务-14(und offfich的服务器错误:/型号/UserFederationManager;

您可以提出的任何建议来帮助我解决这将不胜感激!

似乎问题是我正在使用org.keycloak.models.userfederationmanager实例,而不是org.keycloak.models.models.userprovider实例。UserFederationManager实现了UserProvider,并且似乎比注射机制中使用

的注射机制越多的类型效果越多。
 // UserFederationManager ufm = afc.getSession().users();   // <-- PROBLEM
 // UserProvider ufm = afc.getSession().users();            // <-- WORKS

即使现在起作用,您的两个建议都是有效的,因为我的构建版本确实与运行时的构建版本确实不同,我将解决此问题以避免进一步的错误。

感谢您的输入人!

正如亨利所说,这可能是一种版本冲突。我有一个类似的问题,可以通过此线程的帮助解决。它建议您降级一些依赖项版本,但就我而言,我们解决了将服务器更改为tomcat。

最新更新