Fix NPE when defining retry name for creation

This commit is contained in:
Brendan Le Ny 2024-06-21 10:45:08 +02:00 committed by Alex Morel
parent bee8d1f39b
commit 0b24401def
2 changed files with 10 additions and 5 deletions

View file

@ -45,7 +45,7 @@ public abstract class AbstractScimService<RMM extends RoleMapperModel, S extends
return; return;
} }
ResourceNode scimForCreation = toScimForCreation(roleMapperModel); ResourceNode scimForCreation = toScimForCreation(roleMapperModel);
EntityOnRemoteScimId externalId = scimClient.create(scimForCreation); EntityOnRemoteScimId externalId = scimClient.create(id, scimForCreation);
createMapping(id, externalId); createMapping(id, externalId);
} }

View file

@ -63,8 +63,13 @@ public class ScimClient<S extends ResourceNode> implements AutoCloseable {
return new ScimClient(scimRequestBuilder, scimResourceType); return new ScimClient(scimRequestBuilder, scimResourceType);
} }
public EntityOnRemoteScimId create(ResourceNode scimForCreation) { public EntityOnRemoteScimId create(KeycloakId id, ResourceNode scimForCreation) {
Retry retry = retryRegistry.retry("create-" + scimForCreation.getId().get()); if (scimForCreation.getId().isPresent()) {
throw new IllegalArgumentException(
"%s is already created on remote with id %s".formatted(id, scimForCreation.getId().get())
);
}
Retry retry = retryRegistry.retry("create-%s".formatted(id.asString()));
ServerResponse<S> response = retry.executeSupplier(() -> { ServerResponse<S> response = retry.executeSupplier(() -> {
try { try {
return scimRequestBuilder return scimRequestBuilder
@ -98,7 +103,7 @@ public class ScimClient<S extends ResourceNode> implements AutoCloseable {
} }
public void replace(EntityOnRemoteScimId externalId, ResourceNode scimForReplace) { public void replace(EntityOnRemoteScimId externalId, ResourceNode scimForReplace) {
Retry retry = retryRegistry.retry("replace-" + scimForReplace.getId().get()); Retry retry = retryRegistry.retry("replace-%s".formatted(externalId.asString()));
ServerResponse<S> response = retry.executeSupplier(() -> { ServerResponse<S> response = retry.executeSupplier(() -> {
try { try {
return scimRequestBuilder return scimRequestBuilder
@ -113,7 +118,7 @@ public class ScimClient<S extends ResourceNode> implements AutoCloseable {
} }
public void delete(EntityOnRemoteScimId externalId) { public void delete(EntityOnRemoteScimId externalId) {
Retry retry = retryRegistry.retry("delete-" + externalId.asString()); Retry retry = retryRegistry.retry("delete-%s".formatted(externalId.asString()));
ServerResponse<S> response = retry.executeSupplier(() -> { ServerResponse<S> response = retry.executeSupplier(() -> {
try { try {
return scimRequestBuilder.delete(getResourceClass(), getScimEndpoint(), externalId.asString()) return scimRequestBuilder.delete(getResourceClass(), getScimEndpoint(), externalId.asString())