Skip to content

Commit

Permalink
Remove redundant validation logic in resource manager
Browse files Browse the repository at this point in the history
  • Loading branch information
pavinduLakshan committed Nov 17, 2024
1 parent e14608b commit b4788cb
Showing 1 changed file with 0 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,24 +349,6 @@ public SCIMResponse updateWithPATCH(String existingId, String scimObjectString,
copyOfOldUser = (User) CopyUtil.deepCopy(newUser);
}
} else if (operation.getOperation().equals(SCIMConstants.OperationalConstants.REPLACE)) {

// Convert the object to a JSON string if needed
String jsonString = operation.getValues().toString();

// Parse the JSON string using JSONObject
JSONObject jsonObject = new JSONObject(jsonString);

// Check if the "locale" key exists
if (jsonObject.has("locale")) {
String locale = jsonObject.getString("locale");
System.out.println("Locale: " + locale);

// Perform validation
if (!isValidLocale(locale)) {
throw new BadRequestException("Invalid locale value: ", ResponseCodeConstants.INVALID_SYNTAX);
}
}

if (newUser == null) {
newUser = (User) PatchOperationUtil.doPatchReplace
(operation, getDecoder(), oldUser, copyOfOldUser, schema);
Expand Down Expand Up @@ -429,41 +411,6 @@ public SCIMResponse updateWithPATCH(String existingId, String scimObjectString,
}
}

public static boolean isValidLocale(String localeStr) {
if (localeStr == null || localeStr.isEmpty()) {
return false;
}

// Split the locale string into parts (language and country)
String[] parts = localeStr.split("[-_]");
if (parts.length != 2) {
return false; // Must have exactly two parts: language and country
}

String language = parts[0];
String country = parts[1];

// Validate language code: must be 2 lowercase letters
if (!language.matches("^[a-z]{2}$")) {
return false;
}

// Validate country code: must be 2 uppercase letters
if (!country.matches("^[A-Z]{2}$")) {
return false;
}

// Check if the locale is available in the system
for (Locale availableLocale : Locale.getAvailableLocales()) {
if (availableLocale.getLanguage().equals(language) &&
availableLocale.getCountry().equals(country)) {
return true;
}
}

return false; // If no matching locale is found
}

public String getUserName(String scimObjectString) throws CharonException {

try {
Expand Down

0 comments on commit b4788cb

Please sign in to comment.