1
votes

I am using Keycloak 11.0 and looking for an approach to get all the user federation providers associated to a given Realm. On my setup I have created a dummy Realm and added to it a dummy Federation.

I used the Keycloak Admin Rest API to get the Realm and then looking into the json userFederationProviders field, but nothing is there. I have also tried with the following Java code:

import org.keycloak.admin.client.Keycloak;
import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.representations.idm.UserFederationProviderRepresentation;

public class Key {
    public static void main(String[] args){
        Keycloak keycloak = Keycloak.getInstance(
                "http://localhost:8080/auth/",
                "dummyRealm",
                "admin",
                "a",
                "admin-cli");
        RealmRepresentation realm = keycloak.realm("dummyRealm").toRepresentation();
        for(UserFederationProviderRepresentation s : realm.getUserFederationProviders())
            System.out.println(s.getDisplayName());
    }
}

However, I get a NPE because the realm.getUserFederationProviders() is null.

Is there any way to get the list of all userFederationProviders associated to a Realm without having to use the Keycloak Admin console?

1

1 Answers

2
votes

List realm components and filter type=org.keycloak.storage.UserStorageProvider&parent=<realm name>. Check browser network console and you will see that this API request is also made by Keycloak Admin console, when you visit User Federation configuration.