pavithra rox
pavithra rox

Reputation: 1086

How to define custom user attributes in Keycloak 26's realm user profile via the Java Admin Client?

I'm working with Keycloak 26 and want to define custom user attributes (e.g. user_type ) at the realm level so they appear in the user profile.

Here's what I've tried in my Java (Spring Boot) service, which uses the Keycloak Admin Client:

   public void defineUserAttributes(String realmName) {
    RealmResource realmResource = keycloak.realm(realmName);
    RealmRepresentation realmRep = realmResource.toRepresentation();

    realmRep.getAttributes().put("userProfileEnabled", "true");

    String userProfileConfigJson = ""
    " {
        "attributes": [{
            "name": "user_type",
            "required": false
        }, ]
    }
    ""
    ";

    realmRep.getAttributes().put("userProfileConfiguration", userProfileConfigJson);
    realmResource.update(realmRep);
}

But it seems this is not working. Can someone help me with this? When I do it manually, I can update them from here in the Realm settings.

enter image description here

Upvotes: 0

Views: 269

Answers (0)

Related Questions