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