fix: don't create entity with empty username
This commit is contained in:
parent
6649cc430d
commit
bd39b29422
3 changed files with 16 additions and 7 deletions
|
@ -128,7 +128,7 @@ public abstract class Adapter<M extends RoleMapperModel, S extends com.unboundid
|
||||||
|
|
||||||
public abstract Boolean tryToMap();
|
public abstract Boolean tryToMap();
|
||||||
|
|
||||||
public abstract void createEntity();
|
public abstract void createEntity() throws Exception;
|
||||||
|
|
||||||
public abstract Stream<M> getResourceStream();
|
public abstract Stream<M> getResourceStream();
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,8 @@ public class ScimClient {
|
||||||
M kcModel) {
|
M kcModel) {
|
||||||
var adapter = getAdapter(aClass);
|
var adapter = getAdapter(aClass);
|
||||||
adapter.apply(kcModel);
|
adapter.apply(kcModel);
|
||||||
if (adapter.skip) return;
|
if (adapter.skip)
|
||||||
|
return;
|
||||||
// If mapping exist then it was created by import so skip.
|
// If mapping exist then it was created by import so skip.
|
||||||
if (adapter.query("findById", adapter.getId()).getResultList().size() != 0) {
|
if (adapter.query("findById", adapter.getId()).getResultList().size() != 0) {
|
||||||
return;
|
return;
|
||||||
|
@ -103,7 +104,8 @@ public class ScimClient {
|
||||||
var adapter = getAdapter(aClass);
|
var adapter = getAdapter(aClass);
|
||||||
try {
|
try {
|
||||||
adapter.apply(kcModel);
|
adapter.apply(kcModel);
|
||||||
if (adapter.skip) return;
|
if (adapter.skip)
|
||||||
|
return;
|
||||||
var resource = adapter.query("findById", adapter.getId()).getSingleResult();
|
var resource = adapter.query("findById", adapter.getId()).getSingleResult();
|
||||||
adapter.apply(resource);
|
adapter.apply(resource);
|
||||||
var retry = registry.retry("replace-" + adapter.getId());
|
var retry = registry.retry("replace-" + adapter.getId());
|
||||||
|
@ -200,9 +202,13 @@ public class ScimClient {
|
||||||
switch (this.model.get("sync-import-action")) {
|
switch (this.model.get("sync-import-action")) {
|
||||||
case "CREATE_LOCAL":
|
case "CREATE_LOCAL":
|
||||||
LOGGER.info("Create local resource");
|
LOGGER.info("Create local resource");
|
||||||
|
try {
|
||||||
adapter.createEntity();
|
adapter.createEntity();
|
||||||
adapter.saveMapping();
|
adapter.saveMapping();
|
||||||
syncRes.increaseAdded();
|
syncRes.increaseAdded();
|
||||||
|
} catch (Exception e) {
|
||||||
|
LOGGER.error(e);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "DELETE_REMOTE":
|
case "DELETE_REMOTE":
|
||||||
LOGGER.info("Delete remote resource");
|
LOGGER.info("Delete remote resource");
|
||||||
|
|
|
@ -158,7 +158,10 @@ public class UserAdapter extends Adapter<UserModel, UserResource> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
var user = session.users().addUser(realm, username);
|
||||||
user.setEmail(email);
|
user.setEmail(email);
|
||||||
user.setEnabled(active);
|
user.setEnabled(active);
|
||||||
|
|
Loading…
Reference in a new issue