Search code examples
jakarta-eejbosskeycloak

Keycloak and JBoss: Edit location of config file keycloak.json


I'm using JBoss EAP 6.2, JavaEE 6.0 and keycloak-eap6-adapter-dist 6.0.1 for authentication against Keycloak.

The keycloak.json is currently packed in the deployed war archive (under WEB-INF), so it is not interchangeable for each customer.

Do you know how to change the path of keycloak.json to a external path to make it interchangeable by each installation/stage (e.g. using Docker)?


Solution: Thanks to ravthiru we implemented a custom config resolver like this:

public class CustomKeycloakResolver implements KeycloakConfigResolver {

    private KeycloakDeployment deployment;

    @Override
    public KeycloakDeployment resolve(OIDCHttpFacade.Request request) {
        if (deployment != null) {
            return deployment;
        }

        InputStream is;
        try {
            is = new FileInputStream(System.getenv("KEYCLOAK_CONFIG_FILE"));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
        deployment = KeycloakDeploymentBuilder.build(is);
        return deployment;
    }
}

and registered it in the WEB-INF/web.xml like this:

<context-param>
    <param-name>keycloak.config.resolver</param-name>
    <param-value>my.package.CustomKeycloakResolver</param-value>
</context-param>

Now you can specify the path directly with an environment variable in your Docker-Container.


Solution

  • One option is to resolve keycloak configuration dynamically using keycloak.config.resolver context-param in your web.xml You can find more about this configuration in keycloak document and sample implementation here