diff --git a/src/main/java/sh/libre/scim/core/Adapter.java b/src/main/java/sh/libre/scim/core/Adapter.java index 1747063082..f7581a1bec 100644 --- a/src/main/java/sh/libre/scim/core/Adapter.java +++ b/src/main/java/sh/libre/scim/core/Adapter.java @@ -128,7 +128,7 @@ public abstract class Adapter getResourceStream(); diff --git a/src/main/java/sh/libre/scim/core/ScimClient.java b/src/main/java/sh/libre/scim/core/ScimClient.java index fc2610c13a..67e15acfa6 100644 --- a/src/main/java/sh/libre/scim/core/ScimClient.java +++ b/src/main/java/sh/libre/scim/core/ScimClient.java @@ -78,7 +78,8 @@ public class ScimClient { M kcModel) { var adapter = getAdapter(aClass); adapter.apply(kcModel); - if (adapter.skip) return; + if (adapter.skip) + return; // If mapping exist then it was created by import so skip. if (adapter.query("findById", adapter.getId()).getResultList().size() != 0) { return; @@ -103,7 +104,8 @@ public class ScimClient { var adapter = getAdapter(aClass); try { adapter.apply(kcModel); - if (adapter.skip) return; + if (adapter.skip) + return; var resource = adapter.query("findById", adapter.getId()).getSingleResult(); adapter.apply(resource); var retry = registry.retry("replace-" + adapter.getId()); @@ -200,9 +202,13 @@ public class ScimClient { switch (this.model.get("sync-import-action")) { case "CREATE_LOCAL": LOGGER.info("Create local resource"); - adapter.createEntity(); - adapter.saveMapping(); - syncRes.increaseAdded(); + try { + adapter.createEntity(); + adapter.saveMapping(); + syncRes.increaseAdded(); + } catch (Exception e) { + LOGGER.error(e); + } break; case "DELETE_REMOTE": LOGGER.info("Delete remote resource"); diff --git a/src/main/java/sh/libre/scim/core/UserAdapter.java b/src/main/java/sh/libre/scim/core/UserAdapter.java index df6676e628..f511f9a578 100644 --- a/src/main/java/sh/libre/scim/core/UserAdapter.java +++ b/src/main/java/sh/libre/scim/core/UserAdapter.java @@ -158,7 +158,10 @@ public class UserAdapter extends Adapter { } @Override - public void createEntity() { + public void createEntity() throws Exception { + if (StringUtils.isEmpty(username)) { + throw new Exception("can't create user with empty username"); + } var user = session.users().addUser(realm, username); user.setEmail(email); user.setEnabled(active);