0

我正在尝试向 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");
}

我收到错误 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)
4

1 回答 1

0

SOLUTION: 属性值太长。你必须在 keycloak 数据库中更改大小。

ALTER TABLE user_attribute ALTER COLUMN value TYPE TEXT;

默认类型是VARCHAR(255)

于 2020-08-11T09:37:41.610 回答