From ffd59b1456db296b9103fe8cf3938c9a3a2c6463 Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Wed, 21 Oct 2026 12:14:12 +0530 Subject: [PATCH 1/6] Add custom role support in shared applications for sub-orgs --- .../ApplicationManagementConstants.java | 9 ++ .../management/v1/ApplicationListItem.java | 25 +++- .../management/v1/ApplicationModel.java | 24 +++- .../management/v1/ApplicationPatchModel.java | 28 +++- .../v1/ApplicationResponseModel.java | 26 +++- .../ServerApplicationManagementService.java | 125 +++++++++++++++++- .../ApiModelToServiceProvider.java | 2 + ...cationInfoWithRequiredPropsToApiModel.java | 1 + .../application/UpdateServiceProvider.java | 2 + .../src/main/resources/applications.yaml | 18 +++ 10 files changed, 252 insertions(+), 8 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java index a6e06d6887..057d41ba55 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java @@ -54,6 +54,7 @@ private ApplicationManagementConstants() { public static final String DEFAULT_CERTIFICATE_ALIAS = "wso2carbon"; public static final String ADVANCED_CONFIGURATIONS = "advancedConfigurations"; public static final String APPLICATION_ENABLED = "applicationEnabled"; + public static final String ORGANIZATION_CUSTOM_ROLES_ENABLED = "organizationCustomRolesEnabled"; public static final String TEMPLATE_ID = "templateId"; public static final String TEMPLATE_VERSION = "templateVersion"; public static final String NAME = "name"; @@ -203,6 +204,14 @@ public enum ErrorMessage { UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION("60521", "Enhanced organization authentication enabled property is not supported.", "The 'enhancedOrgAuthenticationEnabled' property is not yet supported."), + UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION("60522", + "Organization custom roles property is not supported.", + "The 'organizationCustomRolesEnabled' property requires enhanced organization authentication " + + "to be supported."), + ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP("60523", + "Organization custom roles property cannot be updated.", + "The 'organizationCustomRolesEnabled' property is read-only for shared applications. Update it " + + "on the main application."), // Server Errors. ERROR_RETRIEVING_SAML_METADATA("65001", diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationListItem.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationListItem.java index b0e08722e0..d27671782f 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationListItem.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationListItem.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-2026, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -83,6 +83,7 @@ public static AccessEnum fromValue(String value) { private String templateVersion; private AssociatedRolesConfig associatedRoles; private Boolean enhancedOrgAuthenticationEnabled; + private Boolean organizationCustomRolesEnabled; private Boolean applicationEnabled; /** @@ -374,6 +375,24 @@ public void setEnhancedOrgAuthenticationEnabled(Boolean enhancedOrgAuthenticatio this.enhancedOrgAuthenticationEnabled = enhancedOrgAuthenticationEnabled; } + /** + **/ + public ApplicationListItem organizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + return this; + } + + @ApiModelProperty(example = "false", value = "") + @JsonProperty("organizationCustomRolesEnabled") + @Valid + public Boolean getOrganizationCustomRolesEnabled() { + return organizationCustomRolesEnabled; + } + public void setOrganizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + } + /** **/ public ApplicationListItem applicationEnabled(Boolean applicationEnabled) { @@ -420,12 +439,13 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.templateVersion, applicationListItem.templateVersion) && Objects.equals(this.associatedRoles, applicationListItem.associatedRoles) && Objects.equals(this.enhancedOrgAuthenticationEnabled, applicationListItem.enhancedOrgAuthenticationEnabled) && + Objects.equals(this.organizationCustomRolesEnabled, applicationListItem.organizationCustomRolesEnabled) && Objects.equals(this.applicationEnabled, applicationListItem.applicationEnabled); } @Override public int hashCode() { - return Objects.hash(id, name, description, applicationVersion, image, accessUrl, clientId, issuer, realm, access, self, advancedConfigurations, templateId, templateVersion, associatedRoles, enhancedOrgAuthenticationEnabled, applicationEnabled); + return Objects.hash(id, name, description, applicationVersion, image, accessUrl, clientId, issuer, realm, access, self, advancedConfigurations, templateId, templateVersion, associatedRoles, enhancedOrgAuthenticationEnabled, organizationCustomRolesEnabled, applicationEnabled); } @Override @@ -450,6 +470,7 @@ public String toString() { sb.append(" templateVersion: ").append(toIndentedString(templateVersion)).append("\n"); sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n"); sb.append(" enhancedOrgAuthenticationEnabled: ").append(toIndentedString(enhancedOrgAuthenticationEnabled)).append("\n"); + sb.append(" organizationCustomRolesEnabled: ").append(toIndentedString(organizationCustomRolesEnabled)).append("\n"); sb.append(" applicationEnabled: ").append(toIndentedString(applicationEnabled)).append("\n"); sb.append("}"); return sb.toString(); diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationModel.java index d6da000f45..049b4acddb 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationModel.java @@ -49,6 +49,7 @@ public class ApplicationModel { private Boolean isManagementApp = false; private Boolean isB2BSelfServiceApp = false; private Boolean enhancedOrgAuthenticationEnabled; + private Boolean organizationCustomRolesEnabled; private Boolean applicationEnabled = true; private AssociatedRolesConfig associatedRoles; private ClaimConfiguration claimConfiguration; @@ -261,6 +262,25 @@ public void setEnhancedOrgAuthenticationEnabled(Boolean enhancedOrgAuthenticatio this.enhancedOrgAuthenticationEnabled = enhancedOrgAuthenticationEnabled; } + /** + * For a main application, decides whether organizations can create custom roles for its shared applications. + **/ + public ApplicationModel organizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + return this; + } + + @ApiModelProperty(example = "false", value = "For a main application, decides whether organizations can create custom roles for its shared applications.") + @JsonProperty("organizationCustomRolesEnabled") + @Valid + public Boolean getOrganizationCustomRolesEnabled() { + return organizationCustomRolesEnabled; + } + public void setOrganizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + } + /** * Decides whether the application is enabled. **/ @@ -411,6 +431,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.isManagementApp, applicationModel.isManagementApp) && Objects.equals(this.isB2BSelfServiceApp, applicationModel.isB2BSelfServiceApp) && Objects.equals(this.enhancedOrgAuthenticationEnabled, applicationModel.enhancedOrgAuthenticationEnabled) && + Objects.equals(this.organizationCustomRolesEnabled, applicationModel.organizationCustomRolesEnabled) && Objects.equals(this.applicationEnabled, applicationModel.applicationEnabled) && Objects.equals(this.associatedRoles, applicationModel.associatedRoles) && Objects.equals(this.claimConfiguration, applicationModel.claimConfiguration) && @@ -422,7 +443,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, description, imageUrl, accessUrl, logoutReturnUrl, templateId, templateVersion, isManagementApp, isB2BSelfServiceApp, enhancedOrgAuthenticationEnabled, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocolConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations); + return Objects.hash(id, name, description, imageUrl, accessUrl, logoutReturnUrl, templateId, templateVersion, isManagementApp, isB2BSelfServiceApp, enhancedOrgAuthenticationEnabled, organizationCustomRolesEnabled, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocolConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations); } @Override @@ -442,6 +463,7 @@ public String toString() { sb.append(" isManagementApp: ").append(toIndentedString(isManagementApp)).append("\n"); sb.append(" isB2BSelfServiceApp: ").append(toIndentedString(isB2BSelfServiceApp)).append("\n"); sb.append(" enhancedOrgAuthenticationEnabled: ").append(toIndentedString(enhancedOrgAuthenticationEnabled)).append("\n"); + sb.append(" organizationCustomRolesEnabled: ").append(toIndentedString(organizationCustomRolesEnabled)).append("\n"); sb.append(" applicationEnabled: ").append(toIndentedString(applicationEnabled)).append("\n"); sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n"); sb.append(" claimConfiguration: ").append(toIndentedString(claimConfiguration)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationPatchModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationPatchModel.java index 1fef5dd933..59390068f8 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationPatchModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationPatchModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-2026, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -46,6 +46,7 @@ public class ApplicationPatchModel { private String templateId; private String templateVersion; private Boolean enhancedOrgAuthenticationEnabled; + private Boolean organizationCustomRolesEnabled; private Boolean applicationEnabled; private AssociatedRolesConfig associatedRoles; private ClaimConfiguration claimConfiguration; @@ -217,6 +218,25 @@ public void setEnhancedOrgAuthenticationEnabled(Boolean enhancedOrgAuthenticatio this.enhancedOrgAuthenticationEnabled = enhancedOrgAuthenticationEnabled; } + /** + * For a main application, decides whether organizations can create custom roles for its shared applications. + **/ + public ApplicationPatchModel organizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + return this; + } + + @ApiModelProperty(example = "false", value = "For a main application, decides whether organizations can create custom roles for its shared applications.") + @JsonProperty("organizationCustomRolesEnabled") + @Valid + public Boolean getOrganizationCustomRolesEnabled() { + return organizationCustomRolesEnabled; + } + public void setOrganizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + } + /** * Decides whether the application is enabled. **/ @@ -340,12 +360,14 @@ public boolean equals(java.lang.Object o) { ApplicationPatchModel applicationPatchModel = (ApplicationPatchModel) o; return Objects.equals(this.name, applicationPatchModel.name) && Objects.equals(this.description, applicationPatchModel.description) && + Objects.equals(this.applicationVersion, applicationPatchModel.applicationVersion) && Objects.equals(this.imageUrl, applicationPatchModel.imageUrl) && Objects.equals(this.accessUrl, applicationPatchModel.accessUrl) && Objects.equals(this.logoutReturnUrl, applicationPatchModel.logoutReturnUrl) && Objects.equals(this.templateId, applicationPatchModel.templateId) && Objects.equals(this.templateVersion, applicationPatchModel.templateVersion) && Objects.equals(this.enhancedOrgAuthenticationEnabled, applicationPatchModel.enhancedOrgAuthenticationEnabled) && + Objects.equals(this.organizationCustomRolesEnabled, applicationPatchModel.organizationCustomRolesEnabled) && Objects.equals(this.applicationEnabled, applicationPatchModel.applicationEnabled) && Objects.equals(this.associatedRoles, applicationPatchModel.associatedRoles) && Objects.equals(this.claimConfiguration, applicationPatchModel.claimConfiguration) && @@ -356,7 +378,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(name, description, imageUrl, accessUrl, logoutReturnUrl, templateId, templateVersion, enhancedOrgAuthenticationEnabled, applicationEnabled, associatedRoles, claimConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations); + return Objects.hash(name, description, applicationVersion, imageUrl, accessUrl, logoutReturnUrl, templateId, templateVersion, enhancedOrgAuthenticationEnabled, organizationCustomRolesEnabled, applicationEnabled, associatedRoles, claimConfiguration, authenticationSequence, advancedConfigurations, provisioningConfigurations); } @Override @@ -367,12 +389,14 @@ public String toString() { sb.append(" name: ").append(toIndentedString(name)).append("\n"); sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" applicationVersion: ").append(toIndentedString(applicationVersion)).append("\n"); sb.append(" imageUrl: ").append(toIndentedString(imageUrl)).append("\n"); sb.append(" accessUrl: ").append(toIndentedString(accessUrl)).append("\n"); sb.append(" logoutReturnUrl: ").append(toIndentedString(logoutReturnUrl)).append("\n"); sb.append(" templateId: ").append(toIndentedString(templateId)).append("\n"); sb.append(" templateVersion: ").append(toIndentedString(templateVersion)).append("\n"); sb.append(" enhancedOrgAuthenticationEnabled: ").append(toIndentedString(enhancedOrgAuthenticationEnabled)).append("\n"); + sb.append(" organizationCustomRolesEnabled: ").append(toIndentedString(organizationCustomRolesEnabled)).append("\n"); sb.append(" applicationEnabled: ").append(toIndentedString(applicationEnabled)).append("\n"); sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n"); sb.append(" claimConfiguration: ").append(toIndentedString(claimConfiguration)).append("\n"); diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationResponseModel.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationResponseModel.java index ab1c7548f3..843b5d3f38 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationResponseModel.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/application/management/v1/ApplicationResponseModel.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2024, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-2026, WSO2 LLC. (http://www.wso2.com). * * WSO2 LLC. licenses this file to you under the Apache License, * Version 2.0 (the "License"); you may not use this file except @@ -55,6 +55,7 @@ public class ApplicationResponseModel { private Boolean isManagementApp; private Boolean isB2BSelfServiceApp; private Boolean enhancedOrgAuthenticationEnabled; + private Boolean organizationCustomRolesEnabled; private Boolean applicationEnabled; private AssociatedRolesConfig associatedRoles; private ClaimConfiguration claimConfiguration; @@ -374,6 +375,25 @@ public void setEnhancedOrgAuthenticationEnabled(Boolean enhancedOrgAuthenticatio this.enhancedOrgAuthenticationEnabled = enhancedOrgAuthenticationEnabled; } + /** + * For a main application, decides whether organizations can create custom roles for its shared applications. + **/ + public ApplicationResponseModel organizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + return this; + } + + @ApiModelProperty(example = "false", value = "For a main application, decides whether organizations can create custom roles for its shared applications.") + @JsonProperty("organizationCustomRolesEnabled") + @Valid + public Boolean getOrganizationCustomRolesEnabled() { + return organizationCustomRolesEnabled; + } + public void setOrganizationCustomRolesEnabled(Boolean organizationCustomRolesEnabled) { + this.organizationCustomRolesEnabled = organizationCustomRolesEnabled; + } + /** * Decides whether the application is enabled. **/ @@ -554,6 +574,7 @@ public boolean equals(java.lang.Object o) { Objects.equals(this.isManagementApp, applicationResponseModel.isManagementApp) && Objects.equals(this.isB2BSelfServiceApp, applicationResponseModel.isB2BSelfServiceApp) && Objects.equals(this.enhancedOrgAuthenticationEnabled, applicationResponseModel.enhancedOrgAuthenticationEnabled) && + Objects.equals(this.organizationCustomRolesEnabled, applicationResponseModel.organizationCustomRolesEnabled) && Objects.equals(this.applicationEnabled, applicationResponseModel.applicationEnabled) && Objects.equals(this.associatedRoles, applicationResponseModel.associatedRoles) && Objects.equals(this.claimConfiguration, applicationResponseModel.claimConfiguration) && @@ -566,7 +587,7 @@ public boolean equals(java.lang.Object o) { @Override public int hashCode() { - return Objects.hash(id, name, description, applicationVersion, imageUrl, accessUrl, logoutReturnUrl, clientId, issuer, realm, templateId, templateVersion, isManagementApp, isB2BSelfServiceApp, enhancedOrgAuthenticationEnabled, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access); + return Objects.hash(id, name, description, applicationVersion, imageUrl, accessUrl, logoutReturnUrl, clientId, issuer, realm, templateId, templateVersion, isManagementApp, isB2BSelfServiceApp, enhancedOrgAuthenticationEnabled, organizationCustomRolesEnabled, applicationEnabled, associatedRoles, claimConfiguration, inboundProtocols, authenticationSequence, advancedConfigurations, provisioningConfigurations, access); } @Override @@ -590,6 +611,7 @@ public String toString() { sb.append(" isManagementApp: ").append(toIndentedString(isManagementApp)).append("\n"); sb.append(" isB2BSelfServiceApp: ").append(toIndentedString(isB2BSelfServiceApp)).append("\n"); sb.append(" enhancedOrgAuthenticationEnabled: ").append(toIndentedString(enhancedOrgAuthenticationEnabled)).append("\n"); + sb.append(" organizationCustomRolesEnabled: ").append(toIndentedString(organizationCustomRolesEnabled)).append("\n"); sb.append(" applicationEnabled: ").append(toIndentedString(applicationEnabled)).append("\n"); sb.append(" associatedRoles: ").append(toIndentedString(associatedRoles)).append("\n"); sb.append(" claimConfiguration: ").append(toIndentedString(claimConfiguration)).append("\n"); 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java index a6309465a9..915826112a 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java @@ -141,6 +141,7 @@ import org.wso2.carbon.identity.core.model.FilterTreeBuilder; import org.wso2.carbon.identity.core.model.Node; import org.wso2.carbon.identity.core.model.OperationNode; +import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService; import org.wso2.carbon.identity.cors.mgt.core.constant.ErrorMessages; @@ -175,8 +176,10 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; @@ -201,11 +204,14 @@ import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_PROCESSING_REQUEST; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.FORBIDDEN_OPERATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.INBOUND_NOT_CONFIGURED; +import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_FAPI_PROFILE; +import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.USE_EXTERNAL_CONSENT_PAGE_NOT_SUPPORTED; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ISSUER; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.NAME; +import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ORGANIZATION_CUSTOM_ROLES_ENABLED; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.TEMPLATE_ID; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.TEMPLATE_VERSION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.VIEW_APPLICATION_CLIENT_SECRET_OPERATION; @@ -290,6 +296,7 @@ public ServerApplicationManagementService(ApplicationManagementService applicati SUPPORTED_REQUIRED_ATTRIBUTES.add(ISSUER); SUPPORTED_REQUIRED_ATTRIBUTES.add(APPLICATION_ENABLED); SUPPORTED_REQUIRED_ATTRIBUTES.add(IdentityApplicationConstants.ALLOWED_ROLE_AUDIENCE_REQUEST_ATTRIBUTE_NAME); + SUPPORTED_REQUIRED_ATTRIBUTES.add(ORGANIZATION_CUSTOM_ROLES_ENABLED); } @Deprecated @@ -462,7 +469,8 @@ private int validateAndGetLimit(Integer limit) { public ApplicationResponseModel getApplication(String applicationId) { ServiceProvider application = getServiceProvider(applicationId); - return new ServiceProviderToApiModel().apply(application); + return new ServiceProviderToApiModel().apply(application) + .organizationCustomRolesEnabled(resolveOrganizationCustomRolesEnabled(application, new HashMap<>())); } /** @@ -855,6 +863,12 @@ public String createApplication(ApplicationModel applicationModel, String templa UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION.getDescription()); } + if (!isEnhancedOrganizationAuthenticationFeatureEnabled() && + Boolean.TRUE.equals(applicationModel.getOrganizationCustomRolesEnabled())) { + throw buildBadRequestError(UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getCode(), + UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); + } + if (applicationModel.getEnhancedOrgAuthenticationEnabled() == null && isEnhancedOrganizationAuthenticationFeatureEnabled()) { applicationModel.setEnhancedOrgAuthenticationEnabled(isEnhancedOrgAuthEnabledByDefaultForNewApps()); @@ -928,6 +942,17 @@ public void patchApplication(String applicationId, ApplicationPatchModel applica UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION.getDescription()); } + if (applicationPatchModel != null && applicationPatchModel.getOrganizationCustomRolesEnabled() != null) { + if (isUnchangedForSharedApplication(appToUpdate, + applicationPatchModel.getOrganizationCustomRolesEnabled())) { + // A shared application resolves the value from its main application, so ignore an unchanged value. + applicationPatchModel.setOrganizationCustomRolesEnabled(null); + } else { + validateOrganizationCustomRolesUpdate(applicationId, + applicationPatchModel.getOrganizationCustomRolesEnabled()); + } + } + /* * Updating the adaptive script requires the internal_application_script_update scope. * Validate the permission before allowing the update. @@ -2016,9 +2041,16 @@ private List getApplicationListItems(List List requiredAttributes) { List applicationListItems = new ArrayList<>(); + boolean isOrganizationCustomRolesRequested = requiredAttributes.contains(ORGANIZATION_CUSTOM_ROLES_ENABLED); + // Main applications resolved for the shared applications in the list, keyed by the main application id. + Map resolvedMainApplications = new HashMap<>(); for (ServiceProvider serviceProvider : serviceProviderList) { ApplicationResponseModel applicationResponseModel = new ServiceProviderToApiModel().apply(serviceProvider); + if (isOrganizationCustomRolesRequested) { + applicationResponseModel.organizationCustomRolesEnabled( + resolveOrganizationCustomRolesEnabled(serviceProvider, resolvedMainApplications)); + } if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(TEMPLATE_ID))) { applicationResponseModel.templateId(null); } @@ -2444,6 +2476,97 @@ private boolean isApplicationBasedOutboundProvisioningEnabled() { return applicationBasedOutboundProvisioningEnabled; } + /** + * Validate an update to the organization custom roles configuration of an application. The configuration + * can only be updated on a main application, and enabling it requires enhanced organization authentication to be + * supported. + * + * @param applicationId ID of the application to be updated. + * @param organizationCustomRolesEnabled Updated value of the configuration. + */ + private void validateOrganizationCustomRolesUpdate(String applicationId, Boolean organizationCustomRolesEnabled) { + + if (!isEnhancedOrganizationAuthenticationFeatureEnabled() + && Boolean.TRUE.equals(organizationCustomRolesEnabled)) { + throw buildBadRequestError(UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getCode(), + UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); + } + try { + if (applicationManagementService.getMainAppId(applicationId) != null) { + throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP.getCode(), + ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP.getDescription()); + } + } catch (IdentityApplicationManagementException e) { + String msg = "Error while resolving the main application of the application with id: " + applicationId; + throw handleIdentityApplicationManagementException(e, msg); + } + } + + /** + * Check whether the given value equals the resolved value of a shared application. + * + * @param application Application to be updated. + * @param organizationCustomRolesEnabled Requested value of the configuration. + * @return True if the application is a shared application and the value is unchanged. + */ + private boolean isUnchangedForSharedApplication(ServiceProvider application, + Boolean organizationCustomRolesEnabled) { + + try { + if (applicationManagementService.getMainAppId(application.getApplicationResourceId()) == null) { + return false; + } + } catch (IdentityApplicationManagementException e) { + String msg = "Error while resolving the main application of the application with id: " + + application.getApplicationResourceId(); + throw handleIdentityApplicationManagementException(e, msg); + } + return organizationCustomRolesEnabled.equals( + resolveOrganizationCustomRolesEnabled(application, new HashMap<>())); + } + + /** + * Resolve whether organizations can create custom application roles for the shared applications of the given + * application. For a main application, this is its own configuration. For a shared application, this is resolved + * from its main application, which must have enhanced organization authentication enabled and must use application + * audience roles as well. + * + * @param application Application. + * @param resolvedMainApplications Main applications already resolved, keyed by the main application id. + * @return True if organization custom roles are enabled for the shared applications. + */ + private boolean resolveOrganizationCustomRolesEnabled(ServiceProvider application, + Map resolvedMainApplications) { + + String applicationId = application.getApplicationResourceId(); + try { + String mainAppId = applicationManagementService.getMainAppId(applicationId); + if (mainAppId == null) { + return application.isOrganizationCustomRolesEnabled(); + } + ServiceProvider mainApplication = resolvedMainApplications.get(mainAppId); + if (mainApplication == null) { + String mainAppTenantDomain = + IdentityTenantUtil.getTenantDomain(applicationManagementService.getTenantIdByApp(mainAppId)); + mainApplication = applicationManagementService.getApplicationByResourceId(mainAppId, + mainAppTenantDomain); + if (mainApplication == null) { + return false; + } + resolvedMainApplications.put(mainAppId, mainApplication); + } + return mainApplication.isEnhancedOrganizationAuthenticationEnabled() && + mainApplication.isOrganizationCustomRolesEnabled() && + mainApplication.getAssociatedRolesConfig() != null && + RoleConstants.APPLICATION.equalsIgnoreCase( + mainApplication.getAssociatedRolesConfig().getAllowedAudience()); + } catch (IdentityApplicationManagementException e) { + String msg = "Error while resolving the organization custom roles configuration of the " + + "application with id: " + applicationId; + throw handleIdentityApplicationManagementException(e, msg); + } + } + private boolean isEnhancedOrganizationAuthenticationFeatureEnabled() { boolean enhancedOrganizationAuthenticationEnabled = false; 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/ApiModelToServiceProvider.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/ApiModelToServiceProvider.java index 076cf5a796..d6cd479e10 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/ApiModelToServiceProvider.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/ApiModelToServiceProvider.java @@ -55,6 +55,8 @@ public ApplicationDTO apply(ApplicationModel applicationModel) throws IdentityAp setIfNotNull(applicationModel.getApplicationEnabled(), application::setApplicationEnabled); setIfNotNull(applicationModel.getEnhancedOrgAuthenticationEnabled(), application::setEnhancedOrganizationAuthenticationEnabled); + setIfNotNull(applicationModel.getOrganizationCustomRolesEnabled(), + application::setOrganizationCustomRolesEnabled); addAdvancedConfigurationToApplication(application, applicationModel.getAdvancedConfigurations()); addClaimConfigurationToApplication(application, applicationModel.getClaimConfiguration()); 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/ApplicationInfoWithRequiredPropsToApiModel.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/ApplicationInfoWithRequiredPropsToApiModel.java index e4202185b7..e67697917f 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/ApplicationInfoWithRequiredPropsToApiModel.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/ApplicationInfoWithRequiredPropsToApiModel.java @@ -61,6 +61,7 @@ public ApplicationListItem apply(ApplicationResponseModel applicationResponseMod .templateVersion(applicationResponseModel.getTemplateVersion()) .self(getApplicationLocation(applicationResponseModel.getId())) .applicationEnabled(applicationResponseModel.getApplicationEnabled()) + .organizationCustomRolesEnabled(applicationResponseModel.getOrganizationCustomRolesEnabled()) .associatedRoles(excludeAssociatedRoles(applicationResponseModel.getAssociatedRoles())); } 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/UpdateServiceProvider.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/UpdateServiceProvider.java index d9cd0a8631..9ef4598e92 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/UpdateServiceProvider.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/UpdateServiceProvider.java @@ -48,6 +48,8 @@ public void apply(ServiceProvider serviceProvider, ApplicationPatchModel applica setIfNotNull(applicationPatchModel.getApplicationEnabled(), serviceProvider::setApplicationEnabled); setIfNotNull(applicationPatchModel.getEnhancedOrgAuthenticationEnabled(), serviceProvider::setEnhancedOrganizationAuthenticationEnabled); + setIfNotNull(applicationPatchModel.getOrganizationCustomRolesEnabled(), + serviceProvider::setOrganizationCustomRolesEnabled); patchAssociatedRolesConfigurations(serviceProvider, applicationPatchModel.getAssociatedRoles()); patchClaimConfiguration(serviceProvider, applicationPatchModel.getClaimConfiguration()); diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/applications.yaml b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/applications.yaml index 6f2c3e1b8a..641f5166da 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/applications.yaml +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/applications.yaml @@ -3401,6 +3401,9 @@ components: enhancedOrgAuthenticationEnabled: type: boolean example: false + organizationCustomRolesEnabled: + type: boolean + example: false applicationEnabled: type: boolean example: true @@ -3449,6 +3452,11 @@ components: type: boolean example: false description: Decides whether the enhanced organization authentication is enabled for the application. + organizationCustomRolesEnabled: + type: boolean + example: false + description: For a main application, decides whether organizations can create custom roles for its + shared applications. applicationEnabled: default: true type: boolean @@ -3521,6 +3529,11 @@ components: type: boolean example: false description: Decides whether the enhanced organization authentication is enabled for the application. + organizationCustomRolesEnabled: + type: boolean + example: false + description: For a main application, decides whether organizations can create custom roles for its + shared applications. applicationEnabled: type: boolean example: true @@ -3575,6 +3588,11 @@ components: type: boolean example: false description: Decides whether the enhanced organization authentication is enabled for the application. + organizationCustomRolesEnabled: + type: boolean + example: false + description: For a main application, decides whether organizations can create custom roles for its + shared applications. applicationEnabled: type: boolean example: true From c272b4d3fc3b82a16cada1476beba42ce493e085 Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Tue, 27 Oct 2026 14:33:36 +0530 Subject: [PATCH 2/6] Reject enabling organization custom roles when the feature is disabled --- .../ApplicationManagementConstants.java | 4 ++++ .../ServerApplicationManagementService.java | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java index 057d41ba55..729d7997d8 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java @@ -212,6 +212,10 @@ public enum ErrorMessage { "Organization custom roles property cannot be updated.", "The 'organizationCustomRolesEnabled' property is read-only for shared applications. Update it " + "on the main application."), + ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED("60524", + "Organization custom roles property is not supported.", + "The 'organizationCustomRolesEnabled' property cannot be enabled as the organization custom roles " + + "feature is disabled in the server."), // Server Errors. ERROR_RETRIEVING_SAML_METADATA("65001", 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java index 915826112a..46a43363f6 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java @@ -127,6 +127,7 @@ import org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil; import org.wso2.carbon.identity.application.mgt.ApplicationConstants; import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; +import org.wso2.carbon.identity.application.mgt.ApplicationMgtUtil; import org.wso2.carbon.identity.application.mgt.AuthorizedAPIManagementService; import org.wso2.carbon.identity.application.mgt.inbound.dto.ApplicationDTO; import org.wso2.carbon.identity.application.mgt.inbound.dto.InboundProtocolConfigurationDTO; @@ -204,6 +205,7 @@ import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ERROR_PROCESSING_REQUEST; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.FORBIDDEN_OPERATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.INBOUND_NOT_CONFIGURED; +import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_FAPI_PROFILE; @@ -869,6 +871,12 @@ public String createApplication(ApplicationModel applicationModel, String templa UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); } + if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled() && + Boolean.TRUE.equals(applicationModel.getOrganizationCustomRolesEnabled())) { + throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getCode(), + ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getDescription()); + } + if (applicationModel.getEnhancedOrgAuthenticationEnabled() == null && isEnhancedOrganizationAuthenticationFeatureEnabled()) { applicationModel.setEnhancedOrgAuthenticationEnabled(isEnhancedOrgAuthEnabledByDefaultForNewApps()); @@ -2478,8 +2486,8 @@ private boolean isApplicationBasedOutboundProvisioningEnabled() { /** * Validate an update to the organization custom roles configuration of an application. The configuration - * can only be updated on a main application, and enabling it requires enhanced organization authentication to be - * supported. + * can only be updated on a main application, and enabling it requires enhanced organization authentication and + * the organization custom roles feature to be supported. * * @param applicationId ID of the application to be updated. * @param organizationCustomRolesEnabled Updated value of the configuration. @@ -2491,6 +2499,11 @@ private void validateOrganizationCustomRolesUpdate(String applicationId, Boolean throw buildBadRequestError(UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getCode(), UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); } + if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled() + && Boolean.TRUE.equals(organizationCustomRolesEnabled)) { + throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getCode(), + ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getDescription()); + } try { if (applicationManagementService.getMainAppId(applicationId) != null) { throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP.getCode(), @@ -2529,7 +2542,7 @@ private boolean isUnchangedForSharedApplication(ServiceProvider application, * Resolve whether organizations can create custom application roles for the shared applications of the given * application. For a main application, this is its own configuration. For a shared application, this is resolved * from its main application, which must have enhanced organization authentication enabled and must use application - * audience roles as well. + * audience roles as well. This is always false when the organization custom roles feature is disabled. * * @param application Application. * @param resolvedMainApplications Main applications already resolved, keyed by the main application id. @@ -2538,6 +2551,9 @@ private boolean isUnchangedForSharedApplication(ServiceProvider application, private boolean resolveOrganizationCustomRolesEnabled(ServiceProvider application, Map resolvedMainApplications) { + if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled()) { + return false; + } String applicationId = application.getApplicationResourceId(); try { String mainAppId = applicationManagementService.getMainAppId(applicationId); From 3d40823640f9fa491e4eca9901d0f22f0cb862f0 Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Thu, 12 Nov 2026 19:05:28 +0530 Subject: [PATCH 3/6] Bump carbon-identity-framework version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a07fb2d5dd..36c224f3dc 100644 --- a/pom.xml +++ b/pom.xml @@ -1164,7 +1164,7 @@ 1.4 1.2.4 1.11.103 - 7.11.261 + 7.11.267 3.0.5 4.9.8.2 4.9.8 From 71909bb6d000f747a6ca6de14036a8f03e28df5d Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Sat, 14 Nov 2026 23:01:30 +0530 Subject: [PATCH 4/6] Map organization custom roles config from the application inherited by the org management listener --- .../ServerApplicationManagementService.java | 67 ++----------------- .../ServiceProviderToApiModel.java | 1 + 2 files changed, 8 insertions(+), 60 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java index 46a43363f6..4fc0763dab 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java @@ -142,7 +142,6 @@ import org.wso2.carbon.identity.core.model.FilterTreeBuilder; import org.wso2.carbon.identity.core.model.Node; import org.wso2.carbon.identity.core.model.OperationNode; -import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.cors.mgt.core.CORSManagementService; import org.wso2.carbon.identity.cors.mgt.core.constant.ErrorMessages; @@ -177,10 +176,8 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.HashMap; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Optional; import java.util.Set; import java.util.function.BiFunction; @@ -471,8 +468,7 @@ private int validateAndGetLimit(Integer limit) { public ApplicationResponseModel getApplication(String applicationId) { ServiceProvider application = getServiceProvider(applicationId); - return new ServiceProviderToApiModel().apply(application) - .organizationCustomRolesEnabled(resolveOrganizationCustomRolesEnabled(application, new HashMap<>())); + return new ServiceProviderToApiModel().apply(application); } /** @@ -2049,16 +2045,9 @@ private List getApplicationListItems(List List requiredAttributes) { List applicationListItems = new ArrayList<>(); - boolean isOrganizationCustomRolesRequested = requiredAttributes.contains(ORGANIZATION_CUSTOM_ROLES_ENABLED); - // Main applications resolved for the shared applications in the list, keyed by the main application id. - Map resolvedMainApplications = new HashMap<>(); for (ServiceProvider serviceProvider : serviceProviderList) { ApplicationResponseModel applicationResponseModel = new ServiceProviderToApiModel().apply(serviceProvider); - if (isOrganizationCustomRolesRequested) { - applicationResponseModel.organizationCustomRolesEnabled( - resolveOrganizationCustomRolesEnabled(serviceProvider, resolvedMainApplications)); - } if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(TEMPLATE_ID))) { applicationResponseModel.templateId(null); } @@ -2082,6 +2071,9 @@ private List getApplicationListItems(List if (requiredAttributes.stream().noneMatch(attribute -> attribute.equals(APPLICATION_ENABLED))) { applicationResponseModel.applicationEnabled(null); } + if (!requiredAttributes.contains(ORGANIZATION_CUSTOM_ROLES_ENABLED)) { + applicationResponseModel.organizationCustomRolesEnabled(null); + } applicationListItems.add(new ApplicationInfoWithRequiredPropsToApiModel().apply(applicationResponseModel)); } return applicationListItems; @@ -2516,7 +2508,8 @@ private void validateOrganizationCustomRolesUpdate(String applicationId, Boolean } /** - * Check whether the given value equals the resolved value of a shared application. + * Check whether the given value equals the value of a shared application, which is inherited from its main + * application when the application is retrieved. * * @param application Application to be updated. * @param organizationCustomRolesEnabled Requested value of the configuration. @@ -2534,53 +2527,7 @@ private boolean isUnchangedForSharedApplication(ServiceProvider application, application.getApplicationResourceId(); throw handleIdentityApplicationManagementException(e, msg); } - return organizationCustomRolesEnabled.equals( - resolveOrganizationCustomRolesEnabled(application, new HashMap<>())); - } - - /** - * Resolve whether organizations can create custom application roles for the shared applications of the given - * application. For a main application, this is its own configuration. For a shared application, this is resolved - * from its main application, which must have enhanced organization authentication enabled and must use application - * audience roles as well. This is always false when the organization custom roles feature is disabled. - * - * @param application Application. - * @param resolvedMainApplications Main applications already resolved, keyed by the main application id. - * @return True if organization custom roles are enabled for the shared applications. - */ - private boolean resolveOrganizationCustomRolesEnabled(ServiceProvider application, - Map resolvedMainApplications) { - - if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled()) { - return false; - } - String applicationId = application.getApplicationResourceId(); - try { - String mainAppId = applicationManagementService.getMainAppId(applicationId); - if (mainAppId == null) { - return application.isOrganizationCustomRolesEnabled(); - } - ServiceProvider mainApplication = resolvedMainApplications.get(mainAppId); - if (mainApplication == null) { - String mainAppTenantDomain = - IdentityTenantUtil.getTenantDomain(applicationManagementService.getTenantIdByApp(mainAppId)); - mainApplication = applicationManagementService.getApplicationByResourceId(mainAppId, - mainAppTenantDomain); - if (mainApplication == null) { - return false; - } - resolvedMainApplications.put(mainAppId, mainApplication); - } - return mainApplication.isEnhancedOrganizationAuthenticationEnabled() && - mainApplication.isOrganizationCustomRolesEnabled() && - mainApplication.getAssociatedRolesConfig() != null && - RoleConstants.APPLICATION.equalsIgnoreCase( - mainApplication.getAssociatedRolesConfig().getAllowedAudience()); - } catch (IdentityApplicationManagementException e) { - String msg = "Error while resolving the organization custom roles configuration of the " + - "application with id: " + applicationId; - throw handleIdentityApplicationManagementException(e, msg); - } + return organizationCustomRolesEnabled.equals(application.isOrganizationCustomRolesEnabled()); } private boolean isEnhancedOrganizationAuthenticationFeatureEnabled() { 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 54dafaebc4..df3cb90617 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 @@ -140,6 +140,7 @@ public ApplicationResponseModel apply(ServiceProvider application) { .isManagementApp(application.isManagementApp()) .applicationEnabled(application.isApplicationEnabled()) .enhancedOrgAuthenticationEnabled(application.isEnhancedOrganizationAuthenticationEnabled()) + .organizationCustomRolesEnabled(application.isOrganizationCustomRolesEnabled()) .associatedRoles(buildAssociatedRoles(application)) .claimConfiguration(buildClaimConfiguration(application)) .inboundProtocols(buildInboundProtocols(application)) From a7eb76c493a0a9f039852aec3c2717021456637b Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Mon, 16 Nov 2026 09:51:12 +0530 Subject: [PATCH 5/6] Bump carbon-identity-framework --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f58ffe3668..568d9a729f 100644 --- a/pom.xml +++ b/pom.xml @@ -1164,7 +1164,7 @@ 1.4 1.2.4 1.11.103 - 7.11.267 + 7.11.269 3.0.5 4.9.8.2 4.9.8 From 450fc156316953f5c9004555a6faf7c52f275650 Mon Sep 17 00:00:00 2001 From: VIHANGAGIT Date: Mon, 16 Nov 2026 15:02:45 +0530 Subject: [PATCH 6/6] Ignore custom roles flag for shared apps --- .../ApplicationManagementConstants.java | 6 +- .../ServerApplicationManagementService.java | 74 +++---------------- 2 files changed, 11 insertions(+), 69 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java index 729d7997d8..7621ba3339 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/src/main/java/org/wso2/carbon/identity/api/server/application/management/common/ApplicationManagementConstants.java @@ -208,11 +208,7 @@ public enum ErrorMessage { "Organization custom roles property is not supported.", "The 'organizationCustomRolesEnabled' property requires enhanced organization authentication " + "to be supported."), - ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP("60523", - "Organization custom roles property cannot be updated.", - "The 'organizationCustomRolesEnabled' property is read-only for shared applications. Update it " + - "on the main application."), - ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED("60524", + ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED("60523", "Organization custom roles property is not supported.", "The 'organizationCustomRolesEnabled' property cannot be enabled as the organization custom roles " + "feature is disabled in the server."), 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java index 4fc0763dab..4a5c48ac6b 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/ServerApplicationManagementService.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/ServerApplicationManagementService.java @@ -203,7 +203,6 @@ import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.FORBIDDEN_OPERATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.INBOUND_NOT_CONFIGURED; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED; -import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_FAPI_PROFILE; import static org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage.UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION; @@ -946,15 +945,16 @@ public void patchApplication(String applicationId, ApplicationPatchModel applica UNSUPPORTED_ENHANCED_ORGANIZATION_AUTHENTICATION_ENABLED_CONFIGURATION.getDescription()); } - if (applicationPatchModel != null && applicationPatchModel.getOrganizationCustomRolesEnabled() != null) { - if (isUnchangedForSharedApplication(appToUpdate, - applicationPatchModel.getOrganizationCustomRolesEnabled())) { - // A shared application resolves the value from its main application, so ignore an unchanged value. - applicationPatchModel.setOrganizationCustomRolesEnabled(null); - } else { - validateOrganizationCustomRolesUpdate(applicationId, - applicationPatchModel.getOrganizationCustomRolesEnabled()); - } + if (!isEnhancedOrganizationAuthenticationFeatureEnabled() && applicationPatchModel != null && + Boolean.TRUE.equals(applicationPatchModel.getOrganizationCustomRolesEnabled())) { + throw buildBadRequestError(UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getCode(), + UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); + } + + if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled() && applicationPatchModel != null && + Boolean.TRUE.equals(applicationPatchModel.getOrganizationCustomRolesEnabled())) { + throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getCode(), + ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getDescription()); } /* @@ -2476,60 +2476,6 @@ private boolean isApplicationBasedOutboundProvisioningEnabled() { return applicationBasedOutboundProvisioningEnabled; } - /** - * Validate an update to the organization custom roles configuration of an application. The configuration - * can only be updated on a main application, and enabling it requires enhanced organization authentication and - * the organization custom roles feature to be supported. - * - * @param applicationId ID of the application to be updated. - * @param organizationCustomRolesEnabled Updated value of the configuration. - */ - private void validateOrganizationCustomRolesUpdate(String applicationId, Boolean organizationCustomRolesEnabled) { - - if (!isEnhancedOrganizationAuthenticationFeatureEnabled() - && Boolean.TRUE.equals(organizationCustomRolesEnabled)) { - throw buildBadRequestError(UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getCode(), - UNSUPPORTED_ORGANIZATION_CUSTOM_ROLES_CONFIGURATION.getDescription()); - } - if (!ApplicationMgtUtil.isOrganizationCustomRolesFeatureEnabled() - && Boolean.TRUE.equals(organizationCustomRolesEnabled)) { - throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getCode(), - ORGANIZATION_CUSTOM_ROLES_FEATURE_DISABLED.getDescription()); - } - try { - if (applicationManagementService.getMainAppId(applicationId) != null) { - throw buildBadRequestError(ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP.getCode(), - ORGANIZATION_CUSTOM_ROLES_READ_ONLY_FOR_SHARED_APP.getDescription()); - } - } catch (IdentityApplicationManagementException e) { - String msg = "Error while resolving the main application of the application with id: " + applicationId; - throw handleIdentityApplicationManagementException(e, msg); - } - } - - /** - * Check whether the given value equals the value of a shared application, which is inherited from its main - * application when the application is retrieved. - * - * @param application Application to be updated. - * @param organizationCustomRolesEnabled Requested value of the configuration. - * @return True if the application is a shared application and the value is unchanged. - */ - private boolean isUnchangedForSharedApplication(ServiceProvider application, - Boolean organizationCustomRolesEnabled) { - - try { - if (applicationManagementService.getMainAppId(application.getApplicationResourceId()) == null) { - return false; - } - } catch (IdentityApplicationManagementException e) { - String msg = "Error while resolving the main application of the application with id: " + - application.getApplicationResourceId(); - throw handleIdentityApplicationManagementException(e, msg); - } - return organizationCustomRolesEnabled.equals(application.isOrganizationCustomRolesEnabled()); - } - private boolean isEnhancedOrganizationAuthenticationFeatureEnabled() { boolean enhancedOrganizationAuthenticationEnabled = false;