From a1b11b6e9e073fea9a7e3cff90e6ce24bac9c98d Mon Sep 17 00:00:00 2001 From: Hasanthi Dissanayake Date: Thu, 31 Aug 2023 11:05:08 +0530 Subject: [PATCH 1/2] Fix 16482 --- .../ServiceProviderToApiModel.java | 25 ++++++++++++++++--- pom.xml | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java index e71a826e55..3d7ff2c06f 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java @@ -83,6 +83,7 @@ public class ServiceProviderToApiModel implements Function systemApplications = ApplicationManagementServiceHolder .getApplicationManagementService().getSystemApplications(); private static final String IS_FRAGMENT_APP = "isFragmentApp"; + private static final String useUserIdForDefaultSubject = "useUserIdForDefaultSubject"; @Override public ApplicationResponseModel apply(ServiceProvider application) { @@ -283,9 +284,7 @@ private SubjectConfig buildSubjectClaimConfig(ServiceProvider application) { subjectConfig.includeUserDomain(localAndOutboundAuthConfig.isUseUserstoreDomainInLocalSubjectIdentifier()); if (StringUtils.isBlank(localAndOutboundAuthConfig.getSubjectClaimUri())) { - if (isLocalClaimDialectUsedBySp(application)) { - subjectConfig.claim(buildClaimModel(FrameworkConstants.USERNAME_CLAIM)); - } + assignClaimForSubjectValue(application, subjectConfig); } else { subjectConfig.claim(buildClaimModel(localAndOutboundAuthConfig.getSubjectClaimUri())); } @@ -294,6 +293,26 @@ private SubjectConfig buildSubjectClaimConfig(ServiceProvider application) { return subjectConfig; } + private void assignClaimForSubjectValue(ServiceProvider application, SubjectConfig subjectConfig) { + if (isLocalClaimDialectUsedBySp(application)) { + if (isUserIdUsedAsDefaultSubject(application.getSpProperties())) { + subjectConfig.claim(buildClaimModel(FrameworkConstants.USER_ID_CLAIM)); + } else { + subjectConfig.claim(buildClaimModel(FrameworkConstants.USERNAME_CLAIM)); + } + } + } + + private boolean isUserIdUsedAsDefaultSubject (ServiceProviderProperty[] spProperties) { + + for (ServiceProviderProperty spProperty : spProperties) { + if (useUserIdForDefaultSubject.equals(spProperty.getName())) { + return true; + } + } + return false; + } + private ClaimConfiguration.DialectEnum getDialect(ServiceProvider application) { if (isLocalClaimDialectUsedBySp(application)) { diff --git a/pom.xml b/pom.xml index 2e5c4acce7..0813b9db3b 100644 --- a/pom.xml +++ b/pom.xml @@ -689,7 +689,7 @@ 1.4 1.2.4 1.8.57 - 5.25.198 + 5.25.302 3.0.5 5.2.0 **/gen/**/* From e381bed34a7cc91203b0fa32fe6eef95c98b99a2 Mon Sep 17 00:00:00 2001 From: Hasanthi Date: Fri, 1 Sep 2023 16:21:34 +0530 Subject: [PATCH 2/2] Update ServiceProviderToApiModel.java --- .../v1/core/functions/application/ServiceProviderToApiModel.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java index 3d7ff2c06f..d23707a319 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/java/org/wso2/carbon/identity/api/server/application/management/v1/core/functions/application/ServiceProviderToApiModel.java @@ -294,6 +294,7 @@ private SubjectConfig buildSubjectClaimConfig(ServiceProvider application) { } private void assignClaimForSubjectValue(ServiceProvider application, SubjectConfig subjectConfig) { + if (isLocalClaimDialectUsedBySp(application)) { if (isUserIdUsedAsDefaultSubject(application.getSpProperties())) { subjectConfig.claim(buildClaimModel(FrameworkConstants.USER_ID_CLAIM));