I am trying add attribute to existing user at Keycloak:10.0.1.
@Override
public void addAttribute(String userId, String value) throws UserDoesNotExistException {
log.info("Trying add attribute to user: " + userId);
Keycloak keycloak = getClient();
RealmResource realmResource = keycloak.realm(configuration.getKeycloakRealm());
final UserResource userResource = realmResource.users().get(userId);
final UserRepresentation user = userResource.toRepresentation();
if (user.getAttributes() == null) {
user.setAttributes(new HashMap<>());
}
user.getAttributes().put(Const.SOME_ATTRIBUTE, Collections.singletonList(value));
userResource.update(user);
log.info("Attribute to user: " + userId + " added successfully");
}
and i get error HTTP-409:
Caused by: javax.ws.rs.ClientErrorException: HTTP 409 Conflict
at org.jboss.resteasy.resteasy-jaxrs@3.6.3.Final//org.jboss.resteasy.client.jaxrs.internal.ClientInvocation.handleErrorStatus(ClientInvocation.java:237)
at org.jboss.resteasy.resteasy-jaxrs@3.6.3.Final//org.jboss.resteasy.client.jaxrs.internal.proxy.extractors.DefaultEntityExtractorFactory$3.extractEntity(DefaultEntityExtractorFactory.java:50)
at org.jboss.resteasy.resteasy-jaxrs@3.6.3.Final//org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invokeSync(ClientInvoker.java:150)
at org.jboss.resteasy.resteasy-jaxrs@3.6.3.Final//org.jboss.resteasy.client.jaxrs.internal.proxy.ClientInvoker.invoke(ClientInvoker.java:112)
at org.jboss.resteasy.resteasy-jaxrs@3.6.3.Final//org.jboss.resteasy.client.jaxrs.internal.proxy.ClientProxy.invoke(ClientProxy.java:76)
SOLUTION: Attribute value was too long. U have to change size at keycloak database.
ALTER TABLE user_attribute ALTER COLUMN value TYPE TEXT;
Default type is VARCHAR(255)