From ad8be9cbb79effaea87babd63fdec82f8769e183 Mon Sep 17 00:00:00 2001 From: Hugo Renard Date: Thu, 22 Sep 2022 11:58:55 +0200 Subject: [PATCH] user displayname fall's back to username --- src/main/java/sh/libre/scim/core/UserAdapter.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/sh/libre/scim/core/UserAdapter.java b/src/main/java/sh/libre/scim/core/UserAdapter.java index b5d795edc8..dbfd2f0b09 100644 --- a/src/main/java/sh/libre/scim/core/UserAdapter.java +++ b/src/main/java/sh/libre/scim/core/UserAdapter.java @@ -12,6 +12,7 @@ import com.unboundid.scim2.common.types.Meta; import com.unboundid.scim2.common.types.Role; import com.unboundid.scim2.common.types.UserResource; +import org.apache.commons.lang.StringUtils; import org.jboss.logging.Logger; import org.keycloak.models.KeycloakSession; import org.keycloak.models.UserModel; @@ -85,13 +86,12 @@ public class UserAdapter extends Adapter { public void apply(UserModel user) { setId(user.getId()); setUsername(user.getUsername()); - if (user.getFirstName() != null && user.getLastName() != null) { - setDisplayName(String.format("%s %s", user.getFirstName(), user.getLastName())); - } else if (user.getFirstName() != null) { - setDisplayName(user.getFirstName()); - } else if (user.getLastName() != null) { - setDisplayName(user.getLastName()); + var displayName = String.format("%s %s", StringUtils.defaultString(user.getFirstName()), + StringUtils.defaultString(user.getLastName())).trim(); + if (StringUtils.isEmpty(displayName)) { + displayName = user.getUsername(); } + setDisplayName(displayName); setEmail(user.getEmail()); setActive(user.isEnabled()); var rolesSet = new HashSet();