Rollback on exception

This commit is contained in:
Alex Morel 2024-06-21 15:25:47 +02:00
parent 5aa9410bac
commit 81d9f5424c
3 changed files with 9 additions and 5 deletions

View file

@ -44,12 +44,12 @@ public abstract class AbstractScimService<RMM extends RoleMapperModel, S extends
if (findById(id).isPresent()) { if (findById(id).isPresent()) {
return; return;
} }
ResourceNode scimForCreation = toScimForCreation(roleMapperModel); S scimForCreation = toScimForCreation(roleMapperModel);
EntityOnRemoteScimId externalId = scimClient.create(id, scimForCreation); EntityOnRemoteScimId externalId = scimClient.create(id, scimForCreation);
createMapping(id, externalId); createMapping(id, externalId);
} }
protected abstract ResourceNode toScimForCreation(RMM roleMapperModel); protected abstract S toScimForCreation(RMM roleMapperModel);
protected abstract KeycloakId getId(RMM roleMapperModel); protected abstract KeycloakId getId(RMM roleMapperModel);

View file

@ -4,7 +4,6 @@ import com.google.common.net.HttpHeaders;
import de.captaingoldfish.scim.sdk.client.ScimClientConfig; import de.captaingoldfish.scim.sdk.client.ScimClientConfig;
import de.captaingoldfish.scim.sdk.client.ScimRequestBuilder; import de.captaingoldfish.scim.sdk.client.ScimRequestBuilder;
import de.captaingoldfish.scim.sdk.client.response.ServerResponse; import de.captaingoldfish.scim.sdk.client.response.ServerResponse;
import de.captaingoldfish.scim.sdk.common.exceptions.ResponseException;
import de.captaingoldfish.scim.sdk.common.resources.ResourceNode; import de.captaingoldfish.scim.sdk.common.resources.ResourceNode;
import de.captaingoldfish.scim.sdk.common.response.ListResponse; import de.captaingoldfish.scim.sdk.common.response.ListResponse;
import io.github.resilience4j.core.IntervalFunction; import io.github.resilience4j.core.IntervalFunction;
@ -63,7 +62,7 @@ public class ScimClient<S extends ResourceNode> implements AutoCloseable {
return new ScimClient(scimRequestBuilder, scimResourceType); return new ScimClient(scimRequestBuilder, scimResourceType);
} }
public EntityOnRemoteScimId create(KeycloakId id, ResourceNode scimForCreation) { public EntityOnRemoteScimId create(KeycloakId id, S scimForCreation) {
if (scimForCreation.getId().isPresent()) { if (scimForCreation.getId().isPresent()) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"%s is already created on remote with id %s".formatted(id, scimForCreation.getId().get()) "%s is already created on remote with id %s".formatted(id, scimForCreation.getId().get())
@ -97,8 +96,9 @@ public class ScimClient<S extends ResourceNode> implements AutoCloseable {
return scimResourceType.getResourceClass(); return scimResourceType.getResourceClass();
} }
public void replace(EntityOnRemoteScimId externalId, ResourceNode scimForReplace) { public void replace(EntityOnRemoteScimId externalId, S scimForReplace) {
Retry retry = retryRegistry.retry("replace-%s".formatted(externalId.asString())); Retry retry = retryRegistry.retry("replace-%s".formatted(externalId.asString()));
logger.warn(scimForReplace);
ServerResponse<S> response = retry.executeSupplier(() -> scimRequestBuilder ServerResponse<S> response = retry.executeSupplier(() -> scimRequestBuilder
.update(getResourceClass(), getScimEndpoint(), externalId.asString()) .update(getResourceClass(), getScimEndpoint(), externalId.asString())
.setResource(scimForReplace) .setResource(scimForReplace)

View file

@ -0,0 +1,4 @@
package sh.libre.scim.core;
public class ScimPropagationException {
}