[英]Problem Implementing a custom Keycloak Authenticator SPI
我正在嘗試實現自定義密鑰克隆Authenticator SPI,以針對外部身份提供程序進行身份驗證。 用戶已經存在於密鑰庫存儲中,我只需要連接到自定義SPI即可對其進行身份驗證。
我正在遵循官方指南的8.3節https://www.keycloak.org/docs/latest/server_development/index.html#_auth_spi_walkthrough ,這與我所需要的非常相似。
我遇到的問題是, 在身份驗證流運行到自定義Authenticator的“ action”方法之后, AuthenticationProcessor
類引發了異常,該類經過檢查后來自以下檢查:
// org.keycloak.authentication.AuthenticationProcessor - line 876
if (authenticationSession.getAuthenticatedUser() == null) {
throw new AuthenticationFlowException(AuthenticationFlowError.UNKNOWN_USER);
}
看到此問題后,我嘗試解決此問題的想法是從密鑰斗篷存儲中獲取用戶(已通過外部身份提供者驗證),然后將其推送到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;
上面的代碼的問題是,就org.keaycloak.models.KeycloackSession
類的users()
方法引發了Java NoSuchMethodExceptionError。 像這樣:
11:26:32,628錯誤[org.keycloak.services.error.KeycloakErrorHandler](默認任務14)未捕獲的服務器錯誤:java.lang.NoSuchMethodError:org.keycloak.models.KeycloakSession.users()Lorg / keycloak / models / UserFederationManager;
您可以提出任何幫助我解決此問題的建議,將不勝感激!
正如Henry所說,這很可能是版本沖突。 我有一個類似的問題, 該線程的幫助已解決。 它建議您降級某些依賴項版本,但就我而言,我們解決了將其改回Tomcat的問題。
似乎問題是我使用的是org.keycloak.models.UserFederationManager實例,而不是org.keycloak.models.UserProvider實例。 UserFederationManager實現了UserProvider,並且在此keycloak使用的注入機制下,似乎更通用的類型比更特定的類型更好。
// UserFederationManager ufm = afc.getSession().users(); // <-- PROBLEM
// UserProvider ufm = afc.getSession().users(); // <-- WORKS
即使現在可以使用,但您的兩個建議都是有效的,因為我的構建版本確實與運行時版本不同,我將解決該問題以避免進一步的Bug。
謝謝大家的投入!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.