From 802a2ae115dfeae3a1fe54f0a2ca3a7fb7e559f4 Mon Sep 17 00:00:00 2001 From: dewniMW Date: Wed, 18 Oct 2023 17:37:23 +0530 Subject: [PATCH 1/3] Handle email domain validation failures for org discovery --- .../identity/scim2/common/impl/SCIMUserManager.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java index 8148eec97..c45690990 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java @@ -150,6 +150,8 @@ public class SCIMUserManager implements UserManager { private static final String ERROR_CODE_INVALID_CREDENTIAL_DURING_UPDATE = "36001"; private static final String ERROR_CODE_PASSWORD_HISTORY_VIOLATION = "22001"; private static final String ERROR_CODE_INVALID_ROLE_NAME = "30011"; + private static final String ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION = "ORG-60090"; + private static final String ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION = "ORG-60091"; private static final Log log = LogFactory.getLog(SCIMUserManager.class); private AbstractUserStoreManager carbonUM; private ClaimManager carbonClaimManager; @@ -420,6 +422,14 @@ private void handleErrorsOnUserNameAndPasswordPolicy(Throwable e) throws BadRequ throw new BadRequestException(ERROR_CODE_PASSWORD_HISTORY_VIOLATION + " - " + e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } + if (e instanceof org.wso2.carbon.user.core.UserStoreException) { + String errorCode = ((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode(); + if (StringUtils.equals(errorCode, + (ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION)) || + StringUtils.equals(errorCode, ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION)) { + throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); + } + } e = e.getCause(); i++; } From 7b14b149dd0158c98a9d0d29240bc353732c8c59 Mon Sep 17 00:00:00 2001 From: dewniMW Date: Sat, 21 Oct 2023 21:25:30 +0530 Subject: [PATCH 2/3] Address review comment --- .../identity/scim2/common/impl/SCIMUserManager.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java index c45690990..08895096c 100644 --- a/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java +++ b/components/org.wso2.carbon.identity.scim2.common/src/main/java/org/wso2/carbon/identity/scim2/common/impl/SCIMUserManager.java @@ -127,6 +127,8 @@ import static org.apache.commons.collections.CollectionUtils.isNotEmpty; import static org.wso2.carbon.identity.core.util.IdentityCoreConstants.MULTI_ATTRIBUTE_SEPARATOR; +import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION; +import static org.wso2.carbon.identity.organization.management.service.constant.OrganizationManagementConstants.ErrorMessages.ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION; import static org.wso2.carbon.identity.scim2.common.utils.SCIMCommonUtils.buildCustomSchema; import static org.wso2.carbon.identity.scim2.common.utils.SCIMCommonUtils.getCustomSchemaURI; import static org.wso2.carbon.identity.scim2.common.utils.SCIMCommonUtils @@ -150,8 +152,6 @@ public class SCIMUserManager implements UserManager { private static final String ERROR_CODE_INVALID_CREDENTIAL_DURING_UPDATE = "36001"; private static final String ERROR_CODE_PASSWORD_HISTORY_VIOLATION = "22001"; private static final String ERROR_CODE_INVALID_ROLE_NAME = "30011"; - private static final String ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION = "ORG-60090"; - private static final String ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION = "ORG-60091"; private static final Log log = LogFactory.getLog(SCIMUserManager.class); private AbstractUserStoreManager carbonUM; private ClaimManager carbonClaimManager; @@ -425,8 +425,8 @@ private void handleErrorsOnUserNameAndPasswordPolicy(Throwable e) throws BadRequ if (e instanceof org.wso2.carbon.user.core.UserStoreException) { String errorCode = ((org.wso2.carbon.user.core.UserStoreException) e).getErrorCode(); if (StringUtils.equals(errorCode, - (ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION)) || - StringUtils.equals(errorCode, ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION)) { + (ERROR_CODE_EMAIL_DOMAIN_ASSOCIATED_WITH_DIFFERENT_ORGANIZATION.getCode())) || + StringUtils.equals(errorCode, ERROR_CODE_EMAIL_DOMAIN_NOT_MAPPED_TO_ORGANIZATION.getCode())) { throw new BadRequestException(e.getMessage(), ResponseCodeConstants.INVALID_VALUE); } } From 4ac29d242d05b376d841aefd3bbb4b3fc685e927 Mon Sep 17 00:00:00 2001 From: dewniMW Date: Sat, 21 Oct 2023 21:28:54 +0530 Subject: [PATCH 3/3] Bump org mgt core version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 13896331f..c728a33c3 100644 --- a/pom.xml +++ b/pom.xml @@ -267,7 +267,7 @@ 20030203.000129 1.8.12 4.0.10 - 1.0.70 + 1.0.76