Skip to content

Commit

Permalink
add support for custom classloaders in the default configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aivinog1 authored and augi committed Apr 27, 2022
1 parent 504e34f commit e13a28f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
import org.keycloak.admin.client.KeycloakBuilder;

public final class KeycloakFactory {
public static Config DefaultConfig =
ConfigFactory.defaultReference().getConfig("keycloakDefaults");

public static final String KEYCLOAK_DEFAULTS_CONFIG_NAME = "keycloakDefaults";

public static Keycloak fromConfig(Config config) {
Config fc = config.withFallback(DefaultConfig);
return fromConfig(config, Thread.currentThread().getContextClassLoader());
}

public static Keycloak fromConfig(Config config, ClassLoader contextClassLoader) {
Config fc = config.withFallback(getDefaultConfig(contextClassLoader));
return KeycloakBuilder.builder()
.clientId(fc.getString("clientId"))
.clientSecret(fc.getString("clientSecret"))
Expand All @@ -22,5 +26,9 @@ public static Keycloak fromConfig(Config config) {
.build();
}

public static Config getDefaultConfig(final ClassLoader classLoader) {
return ConfigFactory.defaultReference(classLoader).getConfig(KEYCLOAK_DEFAULTS_CONFIG_NAME);
}

private KeycloakFactory() {}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.avast.grpc.jwt.keycloak.server;

import static com.avast.grpc.jwt.keycloak.KeycloakFactory.DefaultConfig;
import static com.avast.grpc.jwt.keycloak.KeycloakFactory.getDefaultConfig;

import com.avast.grpc.jwt.server.JwtServerInterceptor;
import com.avast.grpc.jwt.server.JwtTokenParser;
Expand All @@ -14,7 +14,12 @@ public KeycloakJwtServerInterceptor(JwtTokenParser<AccessToken> tokenParser) {
}

public static KeycloakJwtServerInterceptor fromConfig(Config config) {
Config fc = config.withFallback(DefaultConfig);
return fromConfig(config, Thread.currentThread().getContextClassLoader());
}

public static KeycloakJwtServerInterceptor fromConfig(
Config config, ClassLoader contextClassLoader) {
Config fc = config.withFallback(getDefaultConfig(contextClassLoader));
KeycloakPublicKeyProvider publicKeyProvider =
new DefaultKeycloakPublicKeyProvider(
fc.getString("serverUrl"),
Expand Down

0 comments on commit e13a28f

Please sign in to comment.