diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManager.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManager.java index 9f5714f8..732046d2 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManager.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/protocol/endpoints/MeResourceManager.java @@ -409,7 +409,6 @@ public SCIMResponse updateWithPATCH(String existingId, String scimObjectString, } } - public String getUserName(String scimObjectString) throws CharonException { try { diff --git a/modules/charon-core/src/main/java/org/wso2/charon3/core/schema/ServerSideValidator.java b/modules/charon-core/src/main/java/org/wso2/charon3/core/schema/ServerSideValidator.java index f9405dd8..5706f682 100644 --- a/modules/charon-core/src/main/java/org/wso2/charon3/core/schema/ServerSideValidator.java +++ b/modules/charon-core/src/main/java/org/wso2/charon3/core/schema/ServerSideValidator.java @@ -15,6 +15,8 @@ */ package org.wso2.charon3.core.schema; +import org.apache.commons.lang.StringUtils; +import org.wso2.charon3.core.attributes.Attribute; import org.wso2.charon3.core.attributes.SimpleAttribute; import org.wso2.charon3.core.exceptions.BadRequestException; import org.wso2.charon3.core.exceptions.CharonException; @@ -30,6 +32,8 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; +import java.util.Map; import java.util.UUID; /** @@ -248,11 +252,57 @@ public static AbstractSCIMObject validateUpdatedSCIMObject(AbstractSCIMObject ol // Check for required attributes. validateSCIMObjectForRequiredAttributes(newObject, resourceSchema); } + + Map attributes = validatedObject.getAttributeList(); + + for (Map.Entry entry : attributes.entrySet()) { + String key = entry.getKey(); + Attribute value = entry.getValue(); + + if (value instanceof SimpleAttribute && StringUtils.equals(key, SCIMConstants.UserSchemaConstants.LOCALE)) { + String localeAttributeValue = ((SimpleAttribute) value).getValue().toString(); + + if (!isValidLocale(localeAttributeValue)) { + throw new BadRequestException + ("Provided locale value " + localeAttributeValue + " is invalid"); + } + + break; + } + } + // Check for schema list. validateSchemaList(validatedObject, resourceSchema); return validatedObject; } + private static boolean isValidLocale(String localeStr) { + + if (localeStr == null || StringUtils.isEmpty(localeStr)) { + 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]; + + // 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 + } + /* * This method is to add meta data to the resource type resource *