diff --git a/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoAuthorizationStoreFactory.java b/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoAuthorizationStoreFactory.java index 9a484ad49d..df4cfc9bd3 100644 --- a/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoAuthorizationStoreFactory.java +++ b/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoAuthorizationStoreFactory.java @@ -32,8 +32,7 @@ public class MongoAuthorizationStoreFactory implements AuthorizationStoreFactory @Override public StoreFactory create(KeycloakSession session) { MongoConnectionProvider connection = session.getProvider(MongoConnectionProvider.class); - AuthorizationProvider provider = session.getProvider(AuthorizationProvider.class); - return new MongoStoreFactory(connection.getInvocationContext(), provider); + return new MongoStoreFactory(connection.getInvocationContext(), session); } @Override diff --git a/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoStoreFactory.java b/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoStoreFactory.java index 7a94ba5687..398b3d4418 100644 --- a/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoStoreFactory.java +++ b/model/mongo/src/main/java/org/keycloak/authorization/mongo/store/MongoStoreFactory.java @@ -25,6 +25,7 @@ import org.keycloak.authorization.store.ResourceStore; import org.keycloak.authorization.store.ScopeStore; import org.keycloak.authorization.store.StoreFactory; import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext; +import org.keycloak.models.KeycloakSession; /** * @author Pedro Igor @@ -32,31 +33,35 @@ import org.keycloak.connections.mongo.api.context.MongoStoreInvocationContext; public class MongoStoreFactory implements StoreFactory { private final MongoStoreInvocationContext invocationContext; - private final AuthorizationProvider authorizationProvider; + private final KeycloakSession session; - public MongoStoreFactory(MongoStoreInvocationContext invocationContext, AuthorizationProvider authorizationProvider) { + public MongoStoreFactory(MongoStoreInvocationContext invocationContext, KeycloakSession session) { this.invocationContext = invocationContext; - this.authorizationProvider = authorizationProvider; + this.session = session; } @Override public PolicyStore getPolicyStore() { - return new MongoPolicyStore(this.invocationContext, this.authorizationProvider); + return new MongoPolicyStore(this.invocationContext, getAuthorizationProvider()); } @Override public ResourceServerStore getResourceServerStore() { - return new MongoResourceServerStore(this.invocationContext, this.authorizationProvider); + return new MongoResourceServerStore(this.invocationContext, getAuthorizationProvider()); } @Override public ResourceStore getResourceStore() { - return new MongoResourceStore(this.invocationContext, this.authorizationProvider); + return new MongoResourceStore(this.invocationContext, getAuthorizationProvider()); } @Override public ScopeStore getScopeStore() { - return new MongoScopeStore(this.invocationContext, this.authorizationProvider); + return new MongoScopeStore(this.invocationContext, getAuthorizationProvider()); + } + + private AuthorizationProvider getAuthorizationProvider() { + return session.getProvider(AuthorizationProvider.class); } @Override