It doesn't work what @Irmin said.
How I managed this:
Implement you custom 'dir' provider:
factory : CustomDirProviderFactory implements ImportProviderFactory {
provider: public class CustomDirProvider implements ImportProvider {
And there override method called
public void importRealm(KeycloakSessionFactory factory, final String realmName, final Strategy strategy) throws IOException {
There before Realmreporesentation import, you can replace values from you json file:
// Import realm first
FileInputStream is = new FileInputStream(realmFile);
final RealmRepresentation realmRep = JsonSerialization.readValue(replacePlaceHolders(enabledClient, clientSecret, is).getBytes(), RealmRepresentation.class);
replacing variables:
private String replacePlaceHolders(String enabledClient, String clientSecret, FileInputStream is) throws IOException {
Charset charset = StandardCharsets.UTF_8;
String context = new String(is.readAllBytes(), charset);
context = context.replaceAll("\\$\\{" + ENV_VAR_ENABLE_CLIENTS + "}", enabledClient);
context = context.replaceAll("\\$\\{" + ENV_VAR_CLIENT_SECRET + "}", clientSecret);
return context;
}
Of course add this file in resource folder and locate your provider:
resources/META-INF/services/org.keycloak.exportimport.ImportProviderFactory
In run jvm settings (in my compose) add this:
-Dkeycloak.migration.provider=custom-dir (provider ID)