最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Migrating java Spring Boot app to Keycloak 26.1 and I cannot instantiate a Keycloak Session for testing - Stack Overflow

programmeradmin0浏览0评论

During migration of a Java Spring Boot project to Keycloak 26.1.0, I encountered a problem while trying to migrate the tests that use KeycloakSession. The following is how it was in the code (for version 20.0.5):

public static KeycloakSession prepareKeycloakSession() {
    KeycloakSession session = KeycloakSessionUtil.getKeycloakSession();
    RealmModel realm = Mockito.mock(RealmModel.class);
    session.getContext().setRealm(realm);
    return session;
}

I tried instantiating the session from DefaultKeycloakSessionFactory, but it is abstract. KeycloakSessionUtil.getKeycloakSession() returns null. I also tried injecting it using @Context to no avail. Also, I considered mocking it, but it is used in great many use cases and mocking all of it would require a very profound knowledge of Keycloak, which I lack completely.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论