fix: don't create entity with empty username

This commit is contained in:
Hugo Renard 2022-10-19 16:51:59 +02:00
parent 6649cc430d
commit bd39b29422
Signed by: hougo
GPG key ID: 3A285FD470209C59
3 changed files with 16 additions and 7 deletions

View file

@ -128,7 +128,7 @@ public abstract class Adapter<M extends RoleMapperModel, S extends com.unboundid
public abstract Boolean tryToMap();
public abstract void createEntity();
public abstract void createEntity() throws Exception;
public abstract Stream<M> getResourceStream();

View file

@ -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");

View file

@ -158,7 +158,10 @@ public class UserAdapter extends Adapter<UserModel, UserResource> {
}
@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);