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..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 @@ -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,27 @@ 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)) {