Skip to content

Commit

Permalink
Merge pull request #202 from asha15/b2b
Browse files Browse the repository at this point in the history
Retrieve Discoverable Applications for Sub-Org from the Organization Application Management Service
  • Loading branch information
asha15 authored Sep 18, 2024
2 parents 28771c4 + 84eb30c commit ffbc68a
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,10 @@
<artifactId>org.wso2.carbon.identity.application.mgt</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.application</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* 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;
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<OrgApplicationManager> {

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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,5 +180,15 @@
<artifactId>org.wso2.carbon.identity.core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management.core</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.service</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.application</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,11 +110,9 @@ public ApplicationListResponse getApplications(String attributes, Integer limit,
String tenantDomain = IdentityTenantUtil.resolveTenantDomain();
String filterFormatted = buildFilter(filter);
try {
List<ApplicationBasicInfo> applicationBasicInfos = ApplicationServiceHolder
.getDiscoverableApplicationManager().getDiscoverableApplicationBasicInfo(limit, offset,
filterFormatted, sortOrder, sortBy, tenantDomain);
int totalApps = ApplicationServiceHolder.getDiscoverableApplicationManager()
.getCountOfDiscoverableApplications(filterFormatted, tenantDomain);
List<ApplicationBasicInfo> applicationBasicInfos = getDiscoverableApplicationBasicInfo(limit, offset,
filterFormatted, sortOrder, sortBy, tenantDomain);
int totalApps = getCountOfDiscoverableApplications(filterFormatted, tenantDomain);
return buildApplicationListResponse(limit, offset, totalApps, applicationBasicInfos);

} catch (IdentityApplicationManagementException e) {
Expand All @@ -123,6 +123,38 @@ public ApplicationListResponse getApplications(String attributes, Integer limit,
}
}

private List<ApplicationBasicInfo> getDiscoverableApplicationBasicInfo(int limit, int offset, String filter,
String sortOrder, String sortBy,
String tenantDomain)
throws IdentityApplicationManagementException {

try {
if (OrganizationManagementUtil.isOrganization(tenantDomain)) {
return ApplicationServiceHolder.getOrgApplicationManager().getDiscoverableSharedApplicationBasicInfo(
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()
.getCountOfDiscoverableSharedApplications(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<bean id="applicationHolderBean"
class="org.wso2.carbon.identity.api.user.application.common.ApplicationServiceHolder">
<property name="discoverableApplicationManager" ref="identityApplicationServiceFactoryBean"/>
<property name="orgApplicationManager" ref="organizationManagementServiceFactoryBean"/>
</bean>
<bean id="identityApplicationServiceFactoryBean"
class="org.wso2.carbon.identity.api.user.application.common.factory.OSGIServiceFactory"/>
<bean id="organizationManagementServiceFactoryBean"
class="org.wso2.carbon.identity.api.user.application.common.factory.OrganizationManagementOSGIServiceFactory"/>
</beans>
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@
<artifactId>org.wso2.carbon.extension.identity.verification.provider</artifactId>
<version>${identity.verification.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.application</artifactId>
<version>${identity.organization.management.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.carbon.extension.identity.verification</groupId>
<artifactId>org.wso2.carbon.extension.identity.verification.mgt</artifactId>
Expand Down Expand Up @@ -491,6 +496,7 @@
<commons-lang.wso2.version>2.6.0.wso2v1</commons-lang.wso2.version>
<mavan.findbugsplugin.exclude.file>findbugs-exclude-filter.xml</mavan.findbugsplugin.exclude.file>
<config.mapper.version>1.0.13</config.mapper.version>
<identity.organization.management.version>1.4.47</identity.organization.management.version>
</properties>

<modules>
Expand Down

0 comments on commit ffbc68a

Please sign in to comment.