Java 实现自定义密钥斗篷验证器SPI时出现问题

Java 实现自定义密钥斗篷验证器SPI时出现问题,java,keycloak,Java,Keycloak,我正在尝试实现一个自定义KeyClock身份验证器SPI,用于针对外部身份提供程序进行身份验证。用户已经存在于keydepeat存储中,我只需要连接到定制SPI就可以对他们进行身份验证 我遵循官方指南的第8.3节,这与我所需要的非常相似 我遇到的问题是,在身份验证流运行到自定义身份验证程序的“action”方法之后,AuthenticationProcessor类抛出异常,检查后,该异常来自以下检查: // org.keycloak.authentication.AuthenticationP

我正在尝试实现一个自定义KeyClock身份验证器SPI,用于针对外部身份提供程序进行身份验证。用户已经存在于keydepeat存储中,我只需要连接到定制SPI就可以对他们进行身份验证

我遵循官方指南的第8.3节,这与我所需要的非常相似

我遇到的问题是,身份验证流运行到自定义身份验证程序的“action”方法之后,
AuthenticationProcessor
类抛出异常,检查后,该异常来自以下检查:

 // org.keycloak.authentication.AuthenticationProcessor - line 876
    if (authenticationSession.getAuthenticatedUser() == null) {
         throw new AuthenticationFlowException(AuthenticationFlowError.UNKNOWN_USER);
    } 
在看到这个问题后,我尝试解决它的想法是从KeyClope存储中获取用户(已经针对externl身份提供程序进行了验证),并将其推入AuthenticationSession,如下所示:

// 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;
//连接到外部服务提供商
//asume“USER_ID”表示已经验证的用户
//AuthenticationFlowContext=afc作为参数提供

UserFederationManager ufm=afc.getSession().users();// 正如亨利所说,这很可能是版本冲突。我有一个类似的问题,在他的帮助下解决了。它建议您降级某些依赖项版本,但在我的例子中,我们解决了它,将服务器改回Tomcat。

问题似乎是我使用的是org.keydape.models.UserFederationManager实例,而不是org.keydape.models.UserProvider实例。UserFederationManager实现UserProvider,在这个KeyClope使用的注入机制下,更通用的类型似乎比更具体的类型工作得更好

 // UserFederationManager ufm = afc.getSession().users();   // <-- PROBLEM
 // UserProvider ufm = afc.getSession().users();            // <-- WORKS

//UserFederationManager ufm=afc.getSession().users();//看起来像是库版本冲突。您尝试使用与用于生成程序的库版本不同的库版本运行。