diff --git a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/UserService.java b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/UserService.java index 9aae201a8c1..79b3a05a1c9 100644 --- a/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/UserService.java +++ b/jans-config-api/server/src/main/java/io/jans/configapi/service/auth/UserService.java @@ -138,31 +138,33 @@ public User getUserBasedOnInum(String inum) { private User updateCustomAttributes(User user, List customAttributes) { logger.debug("Custom Attributes to update for - user:{}, customAttributes:{} ", user, customAttributes); - if (customAttributes != null && !customAttributes.isEmpty()) { - for (CustomObjectAttribute attribute : customAttributes) { - CustomObjectAttribute existingAttribute = getCustomAttribute(user, attribute.getName()); - logger.debug("Existing CustomAttributes with existingAttribute:{} ", existingAttribute); - - // add - if (existingAttribute == null) { - boolean result = addUserAttribute(user, attribute.getName(), attribute.getValues(), - attribute.isMultiValued()); - logger.debug("Result of adding CustomAttributes attribute:{} , result:{} ", attribute, result); - } - // remove attribute - else if (attribute.getValue() == null || attribute.getValues() == null) { - - user.removeAttribute(attribute.getName()); - } - // replace attribute - else { - existingAttribute.setMultiValued(attribute.isMultiValued()); - existingAttribute.setValues(attribute.getValues()); - } - // Final attribute - logger.debug("Finally user CustomAttributes user.getCustomAttributes:{} ", user.getCustomAttributes()); + if (customAttributes == null || customAttributes.isEmpty()) { + return user; + } + for (CustomObjectAttribute attribute : customAttributes) { + CustomObjectAttribute existingAttribute = getCustomAttribute(user, attribute.getName()); + logger.debug("Existing CustomAttributes with existingAttribute:{} ", existingAttribute); + + // add + if (existingAttribute == null) { + boolean result = addUserAttribute(user, attribute.getName(), attribute.getValues(), + attribute.isMultiValued()); + logger.debug("Result of adding CustomAttributes attribute:{} , result:{} ", attribute, result); } + // remove attribute + else if (attribute.getValue() == null || attribute.getValues() == null) { + + user.removeAttribute(attribute.getName()); + } + // replace attribute + else { + existingAttribute.setMultiValued(attribute.isMultiValued()); + existingAttribute.setValues(attribute.getValues()); + } + // Final attribute + logger.debug("Finally user CustomAttributes user.getCustomAttributes:{} ", user.getCustomAttributes()); + } return user; @@ -171,6 +173,11 @@ else if (attribute.getValue() == null || attribute.getValues() == null) { public List excludeAttributes(List users, String commaSeparatedString) throws IllegalAccessException, InvocationTargetException { logger.debug("Attributes:{} to be excluded from users:{} ", commaSeparatedString, users); + + if (users == null || users.isEmpty() || StringUtils.isEmpty(commaSeparatedString)) { + return users; + } + for (User user : users) { excludeAttributes(user, commaSeparatedString); } @@ -182,9 +189,11 @@ public List excludeAttributes(List users, String commaSeparatedStrin public User excludeAttributes(User user, String commaSeparatedString) throws IllegalAccessException, InvocationTargetException { logger.debug("Attributes:{} to be excluded from user:{} ", commaSeparatedString, user); + if (user == null || StringUtils.isEmpty(commaSeparatedString)) { return user; } + List excludedAttributes = Arrays.asList(commaSeparatedString.split(",")); logger.debug("Attributes List:{} to be excluded ", excludedAttributes); @@ -251,7 +260,9 @@ public String checkMandatoryFields(User user) } } logger.debug("Checking mandatory missingAttributes:{} ", missingAttributes); - missingAttributes.replace(missingAttributes.lastIndexOf(","), missingAttributes.length(), ""); + if (missingAttributes != null && missingAttributes.length() > 0) { + missingAttributes.replace(missingAttributes.lastIndexOf(","), missingAttributes.length(), ""); + } logger.debug("Returning missingAttributes:{} ", missingAttributes); return missingAttributes.toString();