From 08915fbf0cc9a245fd6293873b11cc5dfc48e2e7 Mon Sep 17 00:00:00 2001 From: asha15 <165079T@uom.lk> Date: Wed, 18 Sep 2024 00:54:21 +0530 Subject: [PATCH 1/5] For the sub-org get discoverable application info from OrgApplicationManager --- .../pom.xml | 5 ++ .../common/ApplicationServiceHolder.java | 22 +++++++++ ...anizationManagementOSGIServiceFactory.java | 37 +++++++++++++++ .../pom.xml | 5 ++ .../v1/core/ApplicationService.java | 46 +++++++++++++++++-- .../META-INF/cxf/application-user-v1-cxf.xml | 3 ++ pom.xml | 6 +++ 7 files changed, 119 insertions(+), 5 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml index f90b9a300..b3e720505 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml @@ -38,5 +38,10 @@ org.wso2.carbon.identity.application.mgt provided + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.management.application + compile + diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/ApplicationServiceHolder.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/ApplicationServiceHolder.java index 9195a3fde..421900634 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/ApplicationServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/ApplicationServiceHolder.java @@ -19,12 +19,14 @@ package org.wso2.carbon.identity.api.user.application.common; import org.wso2.carbon.identity.application.mgt.DiscoverableApplicationManager; +import org.wso2.carbon.identity.organization.management.application.OrgApplicationManager; /** * Application management service holder. */ public class ApplicationServiceHolder { + private static OrgApplicationManager orgApplicationManager; private static DiscoverableApplicationManager discoverableApplicationManager; /** @@ -47,4 +49,24 @@ public static void setDiscoverableApplicationManager(DiscoverableApplicationMana ApplicationServiceHolder.discoverableApplicationManager = discoverableApplicationManager; } + + /** + * Get organization application management service. + * + * @return OrgApplicationManager + */ + public static OrgApplicationManager getOrgApplicationManager() { + + return orgApplicationManager; + } + + /** + * Set organization application management service. + * + * @param orgApplicationManager + */ + public static void setOrgApplicationManager(OrgApplicationManager orgApplicationManager) { + + ApplicationServiceHolder.orgApplicationManager = orgApplicationManager; + } } diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java new file mode 100644 index 000000000..a681aff34 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java @@ -0,0 +1,37 @@ +package org.wso2.carbon.identity.api.user.application.common.factory; + +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.organization.management.application.OrgApplicationManager; + +/** + * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to + * instantiate the OrganizationManagementOSGIServiceFactory class and used to get OrganizationManagementOSGIService OSGI + * service. + */ +public class OrganizationManagementOSGIServiceFactory extends AbstractFactoryBean { + + private OrgApplicationManager orgApplicationManager; + + @Override + public Class getObjectType() { + + return null; + } + + @Override + protected OrgApplicationManager createInstance() throws Exception { + + if (this.orgApplicationManager == null) { + OrgApplicationManager applicationManagementService = (OrgApplicationManager) + PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(OrgApplicationManager.class, null); + if (applicationManagementService != null) { + this.orgApplicationManager = applicationManagementService; + } else { + throw new Exception("Unable to retrieve OrgApplicationManager service."); + } + } + return this.orgApplicationManager; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml index 45e0e9224..5b6d24950 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml @@ -180,5 +180,10 @@ org.wso2.carbon.identity.core provided + + org.wso2.carbon.identity.organization.management.core + org.wso2.carbon.identity.organization.management.service + compile + diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java index 056e8f30d..4eae1cfdf 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java @@ -34,6 +34,8 @@ import org.wso2.carbon.identity.core.model.FilterTreeBuilder; import org.wso2.carbon.identity.core.model.Node; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; +import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; +import org.wso2.carbon.identity.organization.management.service.util.OrganizationManagementUtil; import org.wso2.carbon.identity.rest.api.user.application.v1.core.function.ApplicationBasicInfoToApiModel; import org.wso2.carbon.identity.rest.api.user.application.v1.model.ApplicationListResponse; import org.wso2.carbon.identity.rest.api.user.application.v1.model.ApplicationResponse; @@ -108,11 +110,9 @@ public ApplicationListResponse getApplications(String attributes, Integer limit, String tenantDomain = IdentityTenantUtil.resolveTenantDomain(); String filterFormatted = buildFilter(filter); try { - List applicationBasicInfos = ApplicationServiceHolder - .getDiscoverableApplicationManager().getDiscoverableApplicationBasicInfo(limit, offset, - filterFormatted, sortOrder, sortBy, tenantDomain); - int totalApps = ApplicationServiceHolder.getDiscoverableApplicationManager() - .getCountOfDiscoverableApplications(filterFormatted, tenantDomain); + List applicationBasicInfos = getDiscoverableApplicationBasicInfo(limit, offset, + filterFormatted, sortOrder, sortBy, tenantDomain); + int totalApps = getCountOfDiscoverableApplications(filterFormatted, tenantDomain); return buildApplicationListResponse(limit, offset, totalApps, applicationBasicInfos); } catch (IdentityApplicationManagementException e) { @@ -123,6 +123,42 @@ public ApplicationListResponse getApplications(String attributes, Integer limit, } } + private List getDiscoverableApplicationBasicInfo(int limit, int offset, String filter, + String sortOrder, String sortBy, + String tenantDomain) + throws IdentityApplicationManagementException { + + try { + if (OrganizationManagementUtil.isOrganization(tenantDomain)) { + return ApplicationServiceHolder.getOrgApplicationManager().getDiscoverableApplicationBasicInfo( + limit, offset, filter, sortOrder, sortBy, tenantDomain); + } + + return ApplicationServiceHolder.getDiscoverableApplicationManager().getDiscoverableApplicationBasicInfo( + limit, offset, filter, sortOrder, sortBy, tenantDomain); + + } catch (OrganizationManagementException e) { + throw new IdentityApplicationManagementException(e.getMessage(), e); + } + } + + private int getCountOfDiscoverableApplications(String filter, String tenantDomain) + throws IdentityApplicationManagementException { + + try { + if (OrganizationManagementUtil.isOrganization(tenantDomain)) { + return ApplicationServiceHolder.getOrgApplicationManager() + .getCountOfDiscoverableApplications(filter, tenantDomain); + } + + return ApplicationServiceHolder.getDiscoverableApplicationManager() + .getCountOfDiscoverableApplications(filter, tenantDomain); + + } catch (OrganizationManagementException e) { + throw new IdentityApplicationManagementException(e.getMessage(), e); + } + } + private ApplicationResponse buildApplicationResponse(ApplicationBasicInfo applicationBasicInfo) { return new ApplicationBasicInfoToApiModel().apply(applicationBasicInfo); diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/resources/META-INF/cxf/application-user-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/resources/META-INF/cxf/application-user-v1-cxf.xml index e3e295d57..675278ed0 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/resources/META-INF/cxf/application-user-v1-cxf.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/resources/META-INF/cxf/application-user-v1-cxf.xml @@ -24,7 +24,10 @@ + + diff --git a/pom.xml b/pom.xml index 213012875..10904cdfd 100644 --- a/pom.xml +++ b/pom.xml @@ -295,6 +295,11 @@ org.wso2.carbon.extension.identity.verification.provider ${identity.verification.version} + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.management.application + ${identity.organization.management.version} + org.wso2.carbon.extension.identity.verification org.wso2.carbon.extension.identity.verification.mgt @@ -491,6 +496,7 @@ 2.6.0.wso2v1 findbugs-exclude-filter.xml 1.0.13 + 1.4.45 From 6dca18ecc0c32816094bc0b58b07bba1652eca6d Mon Sep 17 00:00:00 2001 From: asha15 <165079T@uom.lk> Date: Wed, 18 Sep 2024 00:58:20 +0530 Subject: [PATCH 2/5] Add license header --- ...ganizationManagementOSGIServiceFactory.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java index a681aff34..8129c35ab 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://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 + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package org.wso2.carbon.identity.api.user.application.common.factory; import org.springframework.beans.factory.config.AbstractFactoryBean; From 9c424c29272d347ffc3a7afc57a9101952db2ca2 Mon Sep 17 00:00:00 2001 From: asha15 <165079T@uom.lk> Date: Wed, 18 Sep 2024 01:00:14 +0530 Subject: [PATCH 3/5] Remove additional line --- .../rest/api/user/application/v1/core/ApplicationService.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java index 4eae1cfdf..7e105dbde 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java @@ -133,10 +133,8 @@ private List getDiscoverableApplicationBasicInfo(int limit return ApplicationServiceHolder.getOrgApplicationManager().getDiscoverableApplicationBasicInfo( limit, offset, filter, sortOrder, sortBy, tenantDomain); } - return ApplicationServiceHolder.getDiscoverableApplicationManager().getDiscoverableApplicationBasicInfo( limit, offset, filter, sortOrder, sortBy, tenantDomain); - } catch (OrganizationManagementException e) { throw new IdentityApplicationManagementException(e.getMessage(), e); } @@ -150,10 +148,8 @@ private int getCountOfDiscoverableApplications(String filter, String tenantDomai return ApplicationServiceHolder.getOrgApplicationManager() .getCountOfDiscoverableApplications(filter, tenantDomain); } - return ApplicationServiceHolder.getDiscoverableApplicationManager() .getCountOfDiscoverableApplications(filter, tenantDomain); - } catch (OrganizationManagementException e) { throw new IdentityApplicationManagementException(e.getMessage(), e); } From 531094659874557f7aab52c2c606a2cfcb772a27 Mon Sep 17 00:00:00 2001 From: asha15 <165079T@uom.lk> Date: Wed, 18 Sep 2024 12:06:37 +0530 Subject: [PATCH 4/5] Update the method name --- .../pom.xml | 2 +- .../pom.xml | 7 ++++++- .../api/user/application/v1/core/ApplicationService.java | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml index b3e720505..57dfaafcd 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml @@ -41,7 +41,7 @@ org.wso2.carbon.identity.organization.management org.wso2.carbon.identity.organization.management.application - compile + provided diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml index 5b6d24950..aa3d48151 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/pom.xml @@ -183,7 +183,12 @@ org.wso2.carbon.identity.organization.management.core org.wso2.carbon.identity.organization.management.service - compile + provided + + + org.wso2.carbon.identity.organization.management + org.wso2.carbon.identity.organization.management.application + provided diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java index 7e105dbde..9ac7b0231 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/core/ApplicationService.java @@ -130,7 +130,7 @@ private List getDiscoverableApplicationBasicInfo(int limit try { if (OrganizationManagementUtil.isOrganization(tenantDomain)) { - return ApplicationServiceHolder.getOrgApplicationManager().getDiscoverableApplicationBasicInfo( + return ApplicationServiceHolder.getOrgApplicationManager().getDiscoverableSharedApplicationBasicInfo( limit, offset, filter, sortOrder, sortBy, tenantDomain); } return ApplicationServiceHolder.getDiscoverableApplicationManager().getDiscoverableApplicationBasicInfo( @@ -146,7 +146,7 @@ private int getCountOfDiscoverableApplications(String filter, String tenantDomai try { if (OrganizationManagementUtil.isOrganization(tenantDomain)) { return ApplicationServiceHolder.getOrgApplicationManager() - .getCountOfDiscoverableApplications(filter, tenantDomain); + .getCountOfDiscoverableSharedApplications(filter, tenantDomain); } return ApplicationServiceHolder.getDiscoverableApplicationManager() .getCountOfDiscoverableApplications(filter, tenantDomain); From 84eb30c0dde1e831268df350241d464ba6b20f7d Mon Sep 17 00:00:00 2001 From: Asha Sulaiman <165079T@uom.lk> Date: Wed, 18 Sep 2024 19:11:40 +0530 Subject: [PATCH 5/5] Upgrade organization management dependency version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 10904cdfd..9fc23fc3d 100644 --- a/pom.xml +++ b/pom.xml @@ -496,7 +496,7 @@ 2.6.0.wso2v1 findbugs-exclude-filter.xml 1.0.13 - 1.4.45 + 1.4.47