'Keycloak java admin client proxy configuration

i need to set the proxy in a java software that use keycloak-admin-client library (that use org.jboss.resteasy and apache.http).

It seems to ignore the -DproxyHost=127.0.0.1 -DproxyPort=8888 JVM configurations. I also tries with org.jboss.resteasy.jaxrs.client.proxy.host property.

Can you help me?

Version of KC dependency:

    <dependency>
        <groupId>org.keycloak</groupId>
        <artifactId>keycloak-admin-client</artifactId>
        <version>9.0.4</version>
    </dependency>

Here the code to generate KC instance:

    private Keycloak getKeycloakInstance() {
    return KeycloakBuilder.builder()
            .serverUrl(KEYCLOAK_SERVER_URL)
            .realm(KEYCLOAK_REALM)
            .username(KEYCLOAK_USERNAME)
            .password(KEYCLOAK_PASSWORD)
            .grantType(OAuth2Constants.PASSWORD)
            .clientId(KEYCLOAK_ADMIN_CLI)
            .clientSecret(KEYCLOAK_ADMIN_SECRET)
            .build();
}

And here same examples of utilization:

    Keycloak keycloak = getKeycloakInstance();
    RealmResource realmResource = keycloak.realm(KEYCLOAK_REALM);
    List<ClientRepresentation> findByClientId = realmResource.clients().findByClientId(KEYCLOAK_ADMIN_CLI);

    UsersResource userRessource = realmResource.users();

    List<UserRepresentation> userToModifyList = userRessource.search(USERNAME);


Solution 1:[1]

i found a solution, just pass a Resteasyclient to the KeycloakBuilderas follows:

    private Keycloak getKeycloakInstance() {
    return KeycloakBuilder.builder()
            .serverUrl(KEYCLOAK_SERVER_URL)
            .realm(KEYCLOAK_REALM)
            .username(KEYCLOAK_USERNAME)
            .password(KEYCLOAK_PASSWORD)
            .grantType(OAuth2Constants.PASSWORD)
            .clientId(KEYCLOAK_ADMIN_CLI)
            .clientSecret(KEYCLOAK_ADMIN_SECRET)
            .resteasyClient(new ResteasyClientBuilder().defaultProxy("localhost", 8888, "http").build())
            .build();
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1