How can I update a existing Keycloak client attribute in a realm?

ni_kill12

I've added few attributes for each client in keycloak, and now I need to update the existing client attribute to new value without deleting the client.

List<ClientRepresentation> list = realm.clients().findByClientId(client.getClientId());
ClientResource resource = realm.clients().get(client.getClientId());

ClientRepresentation clientRepresentation = list.get(0);
        //clientRepresentation.getAttributes().put(KeyCloakAttribute.OBJECT_BASED_ACCESS.getLabel(), application.getAttributes().getObjectBasedModel());
clientRepresentation.setName("updated-name");
resource.update(clientRepresentation); <- This line is throwing error

I could see client resource is providing update method, but when i use it i'm getting 404 error.

2022-01-22 19:07:29.057  -ERROR 15870 [SpringApplication.java] [reportFailure] [org.springframework.boot.SpringApplication]:826 --- [restartedMain] ngp-dev-env o.s.boot.SpringApplication : Application run failed javax.ws.rs.NotFoundException: HTTP 404 Not Found
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:225)
at org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.extractResult(ClientInvocation.java:195)
at org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.BodyEntityExtractor.extractEntity(BodyEntityExtractor.java:62)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:151)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
at com.sun.proxy.$Proxy229.getServiceAccountUser(Unknown Source)
at com.service.KeycloakApplication.updateAttributes(KeycloakApplication.java:89)
at com.service.RegisterService.register(RegisterService.java:32)
at com.OpenAPI2SpringBoot.registerApplication(OpenAPI2SpringBoot.java:88)
at com.OpenAPI2SpringBoot.onApplicationEvent(OpenAPI2SpringBoot.java:80)
at com.OpenAPI2SpringBoot.onApplicationEvent(OpenAPI2SpringBoot.java:1)
at com.OpenAPI2SpringBoot$$EnhancerBySpringCGLIB$$a66f061b.onApplicationEvent(<generated>)
at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:403)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:360)
at org.springframework.boot.context.event.EventPublishingRunListener.running(EventPublishingRunListener.java:103)
at org.springframework.boot.SpringApplicationRunListeners.running(SpringApplicationRunListeners.java:77)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:330)
at com.OpenAPI2SpringBoot.main(OpenAPI2SpringBoot.java:50)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)

keycloak client resource update docs

am I doing it in the wrong way or is there any other way to do it ?

dreamcrash

According to the API documentation realm.clients() returns a ClientsResource interface. The method findByClientId requests the clientId as parameter but the method get:

@Path(value="{id}")
ClientResource get(@PathParam(value="id")
                                       String id)

requests the id of the client, not the client ID.

So you need to replace:

realm.clients().get(client.getClientId());

with

realm.clients().get(client.getId());

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Keycloak Realm VS Keycloak Client

How can i add new table in existing realm database?

How can I update existing notifications in Android ?

Keycloak creating user for an existing realm?

How can I update an attribute in a through table?

How to update existing value on realm database swift?

how can i set "realm-public-key" in application.properties (keycloak v1.9.8)?

How can I read a value from header in Azure API Management and pass it to a path param in keycloak realm?

How can I add or update a Realm object in Swift?

Heroku- How can I update an existing Heroku app?

How can I fit this UPDATE query into this existing SELECT statement?

How can I update an existing table with an array of objects?

How can I update dart version in existing flutter project?

How can i update my existing image in react native

Using realm how can i update data,It should not create new object only update object

How can i restrict client access to only one group of users in keycloak?

How can I update an angular directive attribute dynamically?

how can i update ManyToManyField child attribute in Django forms?

How can I use XQuery to update an attribute value in an XML variable?

How can I update a DynamoDB item's attribute based on a condition?

Keycloak - understanding client roles and realm roles

keycloak starts with a new realm and some client configurations

Realm Update Deleting existing data

How can I update protobuf file for client when server changed

Can I use Realm + Parceler with public attribute ( without getter / setter)?

How can I know the Keycloak version?

On Android, how can I build a Realm Adapter from a Realm List?

Keycloak: How can user be filtered for a specific OIDC client by role?

I am converting my existing firebase/react project to typescript. How can I batch.update?