From 48369efb66ccf01df7cb573e3b15f1155ae6a828 Mon Sep 17 00:00:00 2001 From: Nipuni Paaris Date: Mon, 9 Dec 2024 15:33:00 +0530 Subject: [PATCH] [Spring Cleanup] Remove Spring dependencies in APIs (#687) * Remove Spring dependencies in Application management API * Resolve PR comments * Remove Spring dependencies in the userstores management API * Remove Spring dependencies in the self service management API * Fix minor issues * Update SelfServiceMgtServiceTest test class --- .../pom.xml | 9 +- .../ApplicationManagementServiceHolder.java | 213 +++++++++++------- .../APIResourceMgtOSGiServiceFactory.java | 50 ---- ...plicationManagementOSGiServiceFactory.java | 52 ----- .../AuthorizedAPIMgtOSGiServiceFactory.java | 52 ----- .../factory/CORSMgtOGSiServiceFactory.java | 52 ----- .../factory/OAuthAdminOSGiServiceFactory.java | 53 ----- ...gApplicationManagerOSGiServiceFactory.java | 51 ----- .../RealmServiceOSGIServiceFactory.java | 54 ----- .../SAMLSSOConfigOSGiServiceFactory.java | 52 ----- .../factory/STSAdminOSGiServiceFactory.java | 62 ----- .../TemplateManagementOSGiServiceFactory.java | 54 ----- .../pom.xml | 9 +- .../management/v1/ApplicationsApi.java | 10 +- .../ApplicationsApiServiceFactory.java | 14 +- .../ServerApplicationManagementService.java | 118 +++++----- .../ServerApplicationMetadataService.java | 41 ++-- .../core/ServerApplicationSharingService.java | 27 +-- .../management/v1/core/TransferResource.java | 24 +- ...erApplicationManagementServiceFactory.java | 90 ++++++++ ...rverApplicationMetadataServiceFactory.java | 106 +++++++++ ...erverApplicationSharingServiceFactory.java | 52 +++++ .../v1/impl/ApplicationsApiServiceImpl.java | 42 ++-- .../cxf/applications-server-v1-cxf.xml | 88 -------- .../pom.xml | 7 +- .../common/SelfServiceMgtServiceHolder.java | 77 +++---- ...IResourceManagementOSGiServiceFactory.java | 50 ---- ...plicationManagementOSGiServiceFactory.java | 53 ----- ...orizedAPIManagementOSGiServiceFactory.java | 52 ----- .../factory/GovernanceOSGIServiceFactory.java | 54 ----- .../pom.xml | 7 +- .../selfservice/v1/SelfServiceApi.java | 13 +- .../SelfServiceApiServiceFactory.java | 14 +- .../v1/core/SelfServiceMgtService.java | 138 +++++++----- .../SelfServiceMgtServiceFactory.java | 98 ++++++++ .../v1/impl/SelfServiceApiServiceImpl.java | 15 +- .../v1/util/SelfServiceMgtConstants.java | 8 +- .../META-INF/cxf/self-service-mgt-v1-cxf.xml | 41 ---- .../v1/core/SelfServiceMgtServiceTest.java | 38 +++- .../pom.xml | 23 +- .../common/UserStoreConfigServiceHolder.java | 71 +++--- ...ClaimMetadataManagementServiceFactory.java | 55 ----- .../common/factory/RealmServiceFactory.java | 52 ----- .../UserStoreConfigServiceFactory.java | 52 ----- .../pom.xml | 23 +- .../server/userstore/v1/UserstoresApi.java | 41 ++-- .../UserstoresApiServiceFactory.java | 42 ++-- .../v1/core/ServerUserStoreService.java | 64 ++---- .../ServerUserStoreServiceFactory.java | 89 ++++++++ .../v1/impl/UserstoresApiServiceImpl.java | 37 +-- .../META-INF/cxf/user-store-v1-cxf.xml | 38 ---- 51 files changed, 1052 insertions(+), 1575 deletions(-) delete mode 100644 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/factory/APIResourceMgtOSGiServiceFactory.java delete mode 100644 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/factory/ApplicationManagementOSGiServiceFactory.java delete mode 100644 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/factory/AuthorizedAPIMgtOSGiServiceFactory.java delete mode 100644 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/factory/CORSMgtOGSiServiceFactory.java delete mode 100644 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/factory/OAuthAdminOSGiServiceFactory.java delete mode 100644 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/factory/OrgApplicationManagerOSGiServiceFactory.java delete mode 100644 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/factory/RealmServiceOSGIServiceFactory.java delete mode 100644 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/factory/SAMLSSOConfigOSGiServiceFactory.java delete mode 100644 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/factory/STSAdminOSGiServiceFactory.java delete mode 100644 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/factory/TemplateManagementOSGiServiceFactory.java create mode 100644 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/factories/ServerApplicationManagementServiceFactory.java create mode 100644 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/factories/ServerApplicationMetadataServiceFactory.java create mode 100644 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/factories/ServerApplicationSharingServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.v1/src/main/resources/META-INF/cxf/applications-server-v1-cxf.xml delete mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/factory/APIResourceManagementOSGiServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/factory/ApplicationManagementOSGiServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/factory/AuthorizedAPIManagementOSGiServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/common/factory/GovernanceOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/factories/SelfServiceMgtServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/main/resources/META-INF/cxf/self-service-mgt-v1-cxf.xml delete mode 100644 components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/ClaimMetadataManagementServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/RealmServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/UserStoreConfigServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/ServerUserStoreServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/resources/META-INF/cxf/user-store-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/pom.xml index 6b11a6f42e..345f7fa7c2 100644 --- a/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.application.management/org.wso2.carbon.identity.api.server.application.management.common/pom.xml @@ -1,8 +1,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/pom.xml b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/pom.xml index 473ef3f24c..539ecb6735 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.common/pom.xml @@ -1,6 +1,6 @@ - - - - - - - - - - - - - - - - - diff --git a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/test/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtServiceTest.java b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/test/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtServiceTest.java index 952b549417..8586c19519 100644 --- a/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/test/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtServiceTest.java +++ b/components/org.wso2.carbon.identity.api.server.organization.selfservice/org.wso2.carbon.identity.api.server.organization.selfservice.v1/src/test/java/org/wso2/carbon/identity/api/server/organization/selfservice/v1/core/SelfServiceMgtServiceTest.java @@ -18,17 +18,20 @@ package org.wso2.carbon.identity.api.server.organization.selfservice.v1.core; -import org.mockito.Mock; import org.mockito.MockedStatic; +import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import org.wso2.carbon.base.CarbonBaseConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager; import org.wso2.carbon.identity.api.server.organization.selfservice.common.SelfServiceMgtServiceHolder; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.model.PropertyPatchReq; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.model.PropertyReq; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.model.PropertyRes; import org.wso2.carbon.identity.api.server.organization.selfservice.v1.util.SelfServiceMgtConstants; import org.wso2.carbon.identity.application.common.model.Property; +import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; +import org.wso2.carbon.identity.application.mgt.AuthorizedAPIManagementService; import org.wso2.carbon.identity.governance.IdentityGovernanceException; import org.wso2.carbon.identity.governance.IdentityGovernanceService; import org.wso2.carbon.identity.governance.bean.ConnectorConfig; @@ -57,15 +60,32 @@ public class SelfServiceMgtServiceTest { private static final String TENANT_DOMAIN = "abc.com"; private static final int TENANT_ID = 1; - private SelfServiceMgtService selfServiceMgtService = new SelfServiceMgtService(); - - @Mock private IdentityGovernanceService identityGovernanceService; + private SelfServiceMgtService selfServiceMgtService; + + @BeforeMethod + public void setUp() { + + identityGovernanceService = mock(IdentityGovernanceService.class); + ApplicationManagementService applicationManagementService = mock(ApplicationManagementService.class); + APIResourceManager apiResourceManager = mock(APIResourceManager.class); + AuthorizedAPIManagementService authorizedAPIManagementService = mock(AuthorizedAPIManagementService.class); + + // Create SelfServiceMgtService with mock dependencies + selfServiceMgtService = new SelfServiceMgtService( + identityGovernanceService, + applicationManagementService, + apiResourceManager, + authorizedAPIManagementService + ); + + mockCarbonContext(); + } + @Test public void testGetOrganizationGovernanceConfigs() throws IdentityGovernanceException { - mockCarbonContext(); ConnectorConfig mockConnectorConfig = new ConnectorConfig(); mockConnectorConfig.setName(SelfServiceMgtConstants.SELF_SERVICE_GOVERNANCE_CONNECTOR); @@ -83,14 +103,13 @@ public void testGetOrganizationGovernanceConfigs() throws IdentityGovernanceExce // Add properties to ConnectorConfig mockConnectorConfig.setProperties(new Property[]{property1, property2}); - identityGovernanceService = mock(IdentityGovernanceService.class); when(identityGovernanceService.getConnectorWithConfigs(TENANT_DOMAIN, SelfServiceMgtConstants.SELF_SERVICE_GOVERNANCE_CONNECTOR)) .thenReturn(mockConnectorConfig); List result; - try (MockedStatic mocked = mockStatic(SelfServiceMgtServiceHolder.class)) { + try (MockedStatic mocked = mockStatic(SelfServiceMgtServiceHolder.class)) { mocked.when(SelfServiceMgtServiceHolder::getIdentityGovernanceService) .thenReturn(identityGovernanceService); result = selfServiceMgtService.getOrganizationGovernanceConfigs(); @@ -112,7 +131,6 @@ public void testGetOrganizationGovernanceConfigs() throws IdentityGovernanceExce @Test public void testUpdateOrganizationGovernanceConfigs() throws IdentityGovernanceException { - mockCarbonContext(); PropertyPatchReq mockGovernanceConnector = mock(PropertyPatchReq.class); List propertyReqs = new ArrayList<>(); @@ -131,12 +149,10 @@ public void testUpdateOrganizationGovernanceConfigs() throws IdentityGovernanceE Map configurationDetails = new HashMap<>(); configurationDetails.put(property1.getName(), property1.getValue()); - identityGovernanceService = mock(IdentityGovernanceService.class); - when(identityGovernanceService.getConfiguration(any(String[].class), anyString())) .thenReturn(new Property[]{property2}); - try (MockedStatic mocked = mockStatic(SelfServiceMgtServiceHolder.class)) { + try (MockedStatic mocked = mockStatic(SelfServiceMgtServiceHolder.class)) { mocked.when(SelfServiceMgtServiceHolder::getIdentityGovernanceService) .thenReturn(identityGovernanceService); selfServiceMgtService.updateOrganizationGovernanceConfigs(mockGovernanceConnector, false); diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/pom.xml b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/pom.xml index a7981cbbd2..6d26112485 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/pom.xml @@ -1,18 +1,20 @@ @@ -33,11 +35,6 @@ org.wso2.carbon.identity.framework org.wso2.carbon.identity.claim.metadata.mgt - - org.springframework - spring-web - provided - javax.ws.rs javax.ws.rs-api diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/UserStoreConfigServiceHolder.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/UserStoreConfigServiceHolder.java index 791fa11051..ccabcaaa87 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/UserStoreConfigServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/UserStoreConfigServiceHolder.java @@ -1,21 +1,24 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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. + * 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.server.userstore.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; import org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService; import org.wso2.carbon.user.core.service.RealmService; @@ -25,45 +28,53 @@ */ public class UserStoreConfigServiceHolder { - private static UserStoreConfigServiceHolder instance = new UserStoreConfigServiceHolder(); - private UserStoreConfigService userStoreConfigService; - private RealmService realmService; - private ClaimMetadataManagementService claimMetadataManagementService; - private UserStoreConfigServiceHolder() {} - public static UserStoreConfigServiceHolder getInstance() { - - return instance; - } - - public UserStoreConfigService getUserStoreConfigService() { + private static class UserStoreServiceHolder { - return UserStoreConfigServiceHolder.getInstance().userStoreConfigService; + static final UserStoreConfigService SERVICE = (UserStoreConfigService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(UserStoreConfigService.class, null); } - public void setUserStoreConfigService(UserStoreConfigService userStoreConfigService) { + private static class RealmServiceHolder { - UserStoreConfigServiceHolder.getInstance().userStoreConfigService = userStoreConfigService; + static final RealmService SERVICE = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(RealmService.class, null); } - public RealmService getRealmService() { + private static class ClaimMetadataManagementServiceHolder { - return UserStoreConfigServiceHolder.getInstance().realmService; + static final ClaimMetadataManagementService SERVICE = (ClaimMetadataManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(ClaimMetadataManagementService.class, null); } - public void setRealmService(RealmService realmService) { + /** + * Get the UserStoreConfigService OSGi service. + * + * @return UserStoreConfigService + */ + public static UserStoreConfigService getUserStoreConfigService() { - UserStoreConfigServiceHolder.getInstance().realmService = realmService; + return UserStoreServiceHolder.SERVICE; } - public ClaimMetadataManagementService getClaimMetadataManagementService() { + /** + * Get the RealmService OSGi service. + * + * @return RealmService + */ + public static RealmService getRealmService() { - return UserStoreConfigServiceHolder.getInstance().claimMetadataManagementService; + return RealmServiceHolder.SERVICE; } - public void setClaimMetadataManagementService(ClaimMetadataManagementService claimMetadataManagementService) { + /** + * Get the ClaimMetadataManagementService OSGi service. + * + * @return ClaimMetadataManagementService + */ + public static ClaimMetadataManagementService getClaimMetadataManagementService() { - UserStoreConfigServiceHolder.getInstance().claimMetadataManagementService = claimMetadataManagementService; + return ClaimMetadataManagementServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/ClaimMetadataManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/ClaimMetadataManagementServiceFactory.java deleted file mode 100644 index 1e4f9fe402..0000000000 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/ClaimMetadataManagementServiceFactory.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). - * - * WSO2 Inc. 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.server.userstore.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the ClaimMetadataManagementService type of object inside the container. - */ -public class ClaimMetadataManagementServiceFactory extends AbstractFactoryBean { - - private ClaimMetadataManagementService claimMetadataManagementService; - - @Override - public Class getObjectType() { - - return ClaimMetadataManagementService.class; - } - - @Override - protected ClaimMetadataManagementService createInstance() throws Exception { - - if (this.claimMetadataManagementService != null) { - return this.claimMetadataManagementService; - } - - ClaimMetadataManagementService claimMetadataManagementService = (ClaimMetadataManagementService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(ClaimMetadataManagementService.class, null); - if (claimMetadataManagementService != null) { - this.claimMetadataManagementService = claimMetadataManagementService; - return this.claimMetadataManagementService; - } - throw new Exception("Unable to retrieve Claim Metadata Management Service."); - } -} diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/RealmServiceFactory.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/RealmServiceFactory.java deleted file mode 100644 index 66f7163235..0000000000 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/RealmServiceFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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.server.userstore.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.user.core.service.RealmService; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the RealmService type of object inside the container. - */ -public class RealmServiceFactory extends AbstractFactoryBean { - - private RealmService realmService; - - @Override - public Class getObjectType() { - - return RealmService.class; - } - - @Override - protected RealmService createInstance() throws Exception { - - if (this.realmService == null) { - RealmService realmService = (RealmService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(RealmService.class, null); - if (realmService != null) { - this.realmService = realmService; - } else { - throw new Exception("Unable to retrieve UserStoreConfig Service."); - } - } - return this.realmService; - } -} diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/UserStoreConfigServiceFactory.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/UserStoreConfigServiceFactory.java deleted file mode 100644 index fa15c0e653..0000000000 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.common/src/main/java/org/wso2/carbon/identity/api/server/userstore/common/factory/UserStoreConfigServiceFactory.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * Licensed 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.server.userstore.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the UserStoreConfigService type of object inside the container. - */ -public class UserStoreConfigServiceFactory extends AbstractFactoryBean { - - private UserStoreConfigService userStoreConfigService; - - @Override - public Class getObjectType() { - - return UserStoreConfigService.class; - } - - @Override - protected UserStoreConfigService createInstance() throws Exception { - - if (this.userStoreConfigService == null) { - UserStoreConfigService userStoreConfigService = (UserStoreConfigService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(UserStoreConfigService.class, null); - if (userStoreConfigService != null) { - this.userStoreConfigService = userStoreConfigService; - } else { - throw new Exception("Unable to retrieve UserStoreConfig Service."); - } - } - return this.userStoreConfigService; - } -} diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/pom.xml index 213efda5e4..faf58aea4a 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/pom.xml @@ -1,18 +1,20 @@ @@ -106,11 +108,6 @@ cxf-rt-rs-service-description provided - - org.springframework - spring-web - provided - javax.ws.rs javax.ws.rs-api diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/UserstoresApi.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/UserstoresApi.java index 68eb16aaf5..101c13ce86 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/UserstoresApi.java +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/UserstoresApi.java @@ -1,27 +1,29 @@ /* -* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* Licensed 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. -*/ + * Copyright (c) 2020-2024, 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 + * 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.server.userstore.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import java.io.InputStream; import java.util.List; +import org.wso2.carbon.identity.api.server.userstore.v1.factories.UserstoresApiServiceFactory; import org.wso2.carbon.identity.api.server.userstore.v1.model.AvailableUserStoreClassesRes; import org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping; import org.wso2.carbon.identity.api.server.userstore.v1.model.ConnectionEstablishedResponse; @@ -36,7 +38,6 @@ import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreListResponse; import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreReq; import org.wso2.carbon.identity.api.server.userstore.v1.model.UserStoreResponse; -import org.wso2.carbon.identity.api.server.userstore.v1.UserstoresApiService; import javax.validation.Valid; import javax.ws.rs.*; @@ -50,8 +51,12 @@ public class UserstoresApi { - @Autowired - private UserstoresApiService delegate; + private final UserstoresApiService delegate; + + public UserstoresApi() { + + this.delegate = UserstoresApiServiceFactory.getUserstoresApi(); + } @Valid @POST diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/UserstoresApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/UserstoresApiServiceFactory.java index a1384bc13b..2567072dd2 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/UserstoresApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/gen/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/UserstoresApiServiceFactory.java @@ -1,30 +1,40 @@ /* -* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. -* -* Licensed 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. -*/ + * Copyright (c) 2020-2024, 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 + * 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.server.userstore.v1.factories; import org.wso2.carbon.identity.api.server.userstore.v1.UserstoresApiService; import org.wso2.carbon.identity.api.server.userstore.v1.impl.UserstoresApiServiceImpl; +/** + * Factory class for UserstoresApiService. + */ public class UserstoresApiServiceFactory { - private final static UserstoresApiService service = new UserstoresApiServiceImpl(); + private final static UserstoresApiService SERVICE = new UserstoresApiServiceImpl(); + /** + * Get UserstoresApiService. + * + * @return UserstoresApiService + */ public static UserstoresApiService getUserstoresApi() { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/core/ServerUserStoreService.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/core/ServerUserStoreService.java index acd024baf5..d3b617d015 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/core/ServerUserStoreService.java +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/core/ServerUserStoreService.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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. + * 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.server.userstore.v1.core; @@ -34,7 +36,6 @@ import org.wso2.carbon.identity.api.server.common.Util; import org.wso2.carbon.identity.api.server.common.error.APIError; import org.wso2.carbon.identity.api.server.common.error.ErrorResponse; -import org.wso2.carbon.identity.api.server.userstore.common.UserStoreConfigServiceHolder; import org.wso2.carbon.identity.api.server.userstore.common.UserStoreConstants; import org.wso2.carbon.identity.api.server.userstore.v1.core.functions.userstore.AttributeMappingsToApiModel; import org.wso2.carbon.identity.api.server.userstore.v1.model.AddUserStorePropertiesRes; @@ -121,6 +122,12 @@ */ public class ServerUserStoreService { + private final UserStoreConfigService userStoreConfigService; + + private final RealmService realmService; + + private final ClaimMetadataManagementService claimMetadataManagementService; + private static final Log LOG = LogFactory.getLog(ServerUserStoreService.class); private static final String DUMMY_MESSAGE_ID = "DUMMY-MESSAGE-ID"; @@ -139,6 +146,14 @@ private static boolean isAvailableUserStoreTypes(List getAvailableUserStoreTypes() { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance(). - getUserStoreConfigService(); Set classNames; try { classNames = userStoreConfigService.getAvailableUserStoreClasses(); @@ -401,8 +408,6 @@ public List getUserStoreList(Integer limit, Integer offse handleNotImplementedBehaviour(limit, offset, filter, sort); - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); try { UserStoreDTO[] userStoreDTOS = userStoreConfigService.getUserStores(); return buildUserStoreListResponse(userStoreDTOS, requiredAttributes); @@ -421,7 +426,6 @@ public List getUserStoreList(Integer limit, Integer offse */ public UserStoreConfigurationsRes getPrimaryUserStore() { - RealmService realmService = UserStoreConfigServiceHolder.getInstance().getRealmService(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); RealmConfiguration realmConfiguration; try { @@ -481,8 +485,6 @@ public UserStoreConfigurationsRes getPrimaryUserStore() { */ public UserStoreConfigurationsRes getUserStoreByDomainId(String domainId) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); List propertiesTobeAdd = new ArrayList<>(); try { UserStoreDTO userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId)); @@ -534,8 +536,6 @@ public UserStoreConfigurationsRes getUserStoreByDomainId(String domainId) { public MetaUserStoreType getUserStoreManagerProperties(String typeId) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); Set classNames; try { classNames = userStoreConfigService.getAvailableUserStoreClasses(); @@ -561,8 +561,6 @@ public MetaUserStoreType getUserStoreManagerProperties(String typeId) { */ public ConnectionEstablishedResponse testRDBMSConnection(RDBMSConnectionReq rdBMSConnectionReq) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); ConnectionEstablishedResponse connectionEstablishedResponse = new ConnectionEstablishedResponse(); boolean isConnectionEstablished; connectionEstablishedResponse.setConnection(false); @@ -666,8 +664,6 @@ private boolean isUserStoreExists(String userStoreDomain) throws UserStoreExcept */ private UserStoreResponse performPatchReplace(UserStoreDTO userStoreDTO) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); try { userStoreConfigService.updateUserStore(userStoreDTO, false); return buildResponseForPatchReplace(userStoreDTO, userStoreDTO.getProperties()); @@ -687,8 +683,6 @@ private UserStoreResponse performPatchReplace(UserStoreDTO userStoreDTO) { */ private List getClaimAttributeMappings(String tenantDomain, String userstoreDomainName) { - ClaimMetadataManagementService claimMetadataManagementService = UserStoreConfigServiceHolder.getInstance() - .getClaimMetadataManagementService(); List claimAttributeMappingList = new ArrayList<>(); try { List localClaimList = claimMetadataManagementService.getLocalClaims(tenantDomain); @@ -709,8 +703,6 @@ private List getClaimAttributeMappings(String tenantDomai private UserStoreDTO buildUserStoreForPatch(String domainId, List patchDocuments) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); UserStoreDTO userStoreDTO; try { userStoreDTO = userStoreConfigService.getUserStore(base64URLDecodeId(domainId)); @@ -801,8 +793,6 @@ private List buildUserStorePropertiesRes(UserStoreReq */ private void updateClaimMappings(String userstoreDomain, String tenantDomain, List localClaimList) { - ClaimMetadataManagementService claimMetadataManagementService = UserStoreConfigServiceHolder.getInstance() - .getClaimMetadataManagementService(); try { claimMetadataManagementService.validateClaimAttributeMapping(localClaimList, tenantDomain); claimMetadataManagementService.updateLocalClaimMappings(localClaimList, tenantDomain, userstoreDomain); @@ -820,8 +810,6 @@ private void updateClaimMappings(String userstoreDomain, String tenantDomain, Li */ private void validateClaimMappings(String tenantDomain, List localClaimList) { - ClaimMetadataManagementService claimMetadataManagementService = UserStoreConfigServiceHolder.getInstance() - .getClaimMetadataManagementService(); try { claimMetadataManagementService.validateClaimAttributeMapping(localClaimList, tenantDomain); } catch (ClaimMetadataException e) { @@ -1457,8 +1445,6 @@ public UserStoreAttributeMappingResponse getUserStoreAttributeMappings(String ty ERROR_CODE_INVALID_INPUT); } try { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance() - .getUserStoreConfigService(); classNames = userStoreConfigService.getAvailableUserStoreClasses(); if (CollectionUtils.isEmpty(classNames) || !classNames.contains(userStoreName)) { throw handleException(Response.Status.NOT_FOUND, UserStoreConstants.ErrorMessage. @@ -1494,8 +1480,6 @@ public UserStoreAttributeMappingResponse getUserStoreAttributeMappings(String ty private List getAttributeMappings(String userStoreName, boolean includeIdentityClaimMappings) { - UserStoreConfigService userStoreConfigService = UserStoreConfigServiceHolder.getInstance(). - getUserStoreConfigService(); try { UserStoreAttributeMappings userStoreAttributeMappings = userStoreConfigService. getUserStoreAttributeMappings(); diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/ServerUserStoreServiceFactory.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/ServerUserStoreServiceFactory.java new file mode 100644 index 0000000000..204a4a5b99 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/factories/ServerUserStoreServiceFactory.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2024, 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 + * 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.server.userstore.v1.factories; + +import org.wso2.carbon.identity.api.server.userstore.common.UserStoreConfigServiceHolder; +import org.wso2.carbon.identity.api.server.userstore.v1.core.ServerUserStoreService; +import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; +import org.wso2.carbon.identity.user.store.configuration.UserStoreConfigService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * Factory class for ServerUserStoreService. + */ +public class ServerUserStoreServiceFactory { + + private ServerUserStoreServiceFactory() { + + } + + private static class ServerUserStoreServiceHolder { + + private static final ServerUserStoreService SERVICE = createServiceInstance(); + } + + private static ServerUserStoreService createServiceInstance() { + + UserStoreConfigService userStoreConfigService = getUserStoreConfigService(); + RealmService realmService = getRealmService(); + ClaimMetadataManagementService claimMetadataManagementService = getClaimMetadataManagementService(); + + return new ServerUserStoreService(userStoreConfigService, realmService, claimMetadataManagementService); + } + + /** + * Get ServerUserStoreService. + * + * @return ServerUserStoreService + */ + public static ServerUserStoreService getServerUserStoreService() { + + return ServerUserStoreServiceHolder.SERVICE; + } + + private static UserStoreConfigService getUserStoreConfigService() { + + UserStoreConfigService service = UserStoreConfigServiceHolder.getUserStoreConfigService(); + if (service == null) { + throw new IllegalStateException("UserStoreConfigService is not available from OSGi context."); + } + + return service; + } + + private static RealmService getRealmService() { + + RealmService service = UserStoreConfigServiceHolder.getRealmService(); + if (service == null) { + throw new IllegalStateException("RealmService is not available from OSGi context."); + } + + return service; + } + + private static ClaimMetadataManagementService getClaimMetadataManagementService() { + + ClaimMetadataManagementService service = UserStoreConfigServiceHolder.getClaimMetadataManagementService(); + if (service == null) { + throw new IllegalStateException("ClaimMetadataManagementService is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/impl/UserstoresApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/impl/UserstoresApiServiceImpl.java index 6489b0615c..8b4b39a81e 100644 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/impl/UserstoresApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/java/org/wso2/carbon/identity/api/server/userstore/v1/impl/UserstoresApiServiceImpl.java @@ -1,28 +1,30 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com). * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. + * 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. + * 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.server.userstore.v1.impl; import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; +import org.apache.http.HttpHeaders; import org.wso2.carbon.identity.api.server.common.ContextLoader; import org.wso2.carbon.identity.api.server.common.FileContent; import org.wso2.carbon.identity.api.server.userstore.v1.UserstoresApiService; import org.wso2.carbon.identity.api.server.userstore.v1.core.ServerUserStoreService; +import org.wso2.carbon.identity.api.server.userstore.v1.factories.ServerUserStoreServiceFactory; import org.wso2.carbon.identity.api.server.userstore.v1.model.ClaimAttributeMapping; import org.wso2.carbon.identity.api.server.userstore.v1.model.PatchDocument; import org.wso2.carbon.identity.api.server.userstore.v1.model.RDBMSConnectionReq; @@ -44,8 +46,15 @@ */ public class UserstoresApiServiceImpl implements UserstoresApiService { - @Autowired - private ServerUserStoreService serverUserStoreService; + private final ServerUserStoreService serverUserStoreService; + + public UserstoresApiServiceImpl() { + try { + this.serverUserStoreService = ServerUserStoreServiceFactory.getServerUserStoreService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating ServerUserStoreService.", e); + } + } @Override public Response addUserStore(UserStoreReq userStoreReq) { @@ -68,7 +77,7 @@ public Response exportUserStoreToFile(String userstoreDomainId, String accept) { return Response.ok() .type(fileContent.getFileType()) - .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + .header("Content-Disposition", "attachment; filename=\"" + fileContent.getFileName() + "\"") .header(HttpHeaders.CACHE_CONTROL, "no-cache, no-store, must-revalidate") .header(HttpHeaders.PRAGMA, "no-cache") @@ -77,8 +86,6 @@ public Response exportUserStoreToFile(String userstoreDomainId, String accept) { .build(); } - - @Override public Response getAvailableUserStoreTypes() { diff --git a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/resources/META-INF/cxf/user-store-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/resources/META-INF/cxf/user-store-v1-cxf.xml deleted file mode 100644 index 88f288935a..0000000000 --- a/components/org.wso2.carbon.identity.api.server.userstore/org.wso2.carbon.identity.api.server.userstore.v1/src/main/resources/META-INF/cxf/user-store-v1-cxf.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - -