diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/pom.xml b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/pom.xml index 5e56317804..47287fd096 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/pom.xml @@ -1,18 +1,20 @@ @@ -28,10 +30,5 @@ org.wso2.carbon.identity.governance org.wso2.carbon.identity.governance - - org.springframework - spring-web - provided - diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java index ad65d1e029..2fac919981 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/GovernanceDataHolder.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.identity.governance.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.governance.IdentityGovernanceService; /** @@ -23,15 +26,20 @@ */ public class GovernanceDataHolder { - private static IdentityGovernanceService identityGovernanceService; + private GovernanceDataHolder() {} - public static IdentityGovernanceService getIdentityGovernanceService() { - - return identityGovernanceService; + private static class IdentityGovernanceServiceHolder { + static final IdentityGovernanceService SERVICE = (IdentityGovernanceService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(IdentityGovernanceService.class, null); } - public static void setIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { + /** + * Get IdentityGovernanceService osgi service. + * + * @return IdentityGovernanceService + */ + public static IdentityGovernanceService getIdentityGovernanceService() { - GovernanceDataHolder.identityGovernanceService = identityGovernanceService; + return IdentityGovernanceServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/factory/OSGIServiceFactory.java deleted file mode 100644 index e35f2fad47..0000000000 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.common/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/common/factory/OSGIServiceFactory.java +++ /dev/null @@ -1,53 +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.identity.governance.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.governance.IdentityGovernanceService; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the IdentityGovernanceService type of object inside the container. - */ -public class OSGIServiceFactory extends AbstractFactoryBean { - - private IdentityGovernanceService identityGovernanceService; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected IdentityGovernanceService createInstance() throws Exception { - - if (this.identityGovernanceService == null) { - IdentityGovernanceService identityGovernanceService = (IdentityGovernanceService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(IdentityGovernanceService.class, null); - if (identityGovernanceService != null) { - this.identityGovernanceService = identityGovernanceService; - } else { - throw new Exception("Unable to retrieve IdentityGovernanceService service."); - } - } - return this.identityGovernanceService; - } - -} diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/pom.xml index 74ea4680a0..611873ef34 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/pom.xml @@ -1,20 +1,21 @@ - org.wso2.carbon.identity.server.api @@ -105,11 +106,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.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java index b4f5b05af4..f8d2c225d6 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/IdentityGovernanceApi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019-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 @@ -18,7 +18,7 @@ package org.wso2.carbon.identity.api.server.identity.governance.v1; -import org.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.api.server.identity.governance.v1.factories.IdentityGovernanceApiServiceFactory; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoriesRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoryRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorRes; @@ -28,7 +28,6 @@ import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceResp; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; -import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; import javax.validation.Valid; import javax.ws.rs.*; @@ -42,8 +41,12 @@ public class IdentityGovernanceApi { - @Autowired - private IdentityGovernanceApiService delegate; + private final IdentityGovernanceApiService delegate; + + public IdentityGovernanceApi() { + + this.delegate = IdentityGovernanceApiServiceFactory.getIdentityGovernanceApi(); + } @Valid @GET diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/IdentityGovernanceApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/IdentityGovernanceApiServiceFactory.java index eeabb1e97e..a3dd71bbd7 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/IdentityGovernanceApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/gen/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/IdentityGovernanceApiServiceFactory.java @@ -1,30 +1,40 @@ /* -* 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. -*/ + * Copyright (c) 2019-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.identity.governance.v1.factories; import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; import org.wso2.carbon.identity.api.server.identity.governance.v1.impl.IdentityGovernanceApiServiceImpl; +/** + * Factory class for Identity Governance API. + */ public class IdentityGovernanceApiServiceFactory { - private final static IdentityGovernanceApiService service = new IdentityGovernanceApiServiceImpl(); + private final static IdentityGovernanceApiService SERVICE = new IdentityGovernanceApiServiceImpl(); + /** + * Get Identity Governance API Service. + * + * @return IdentityGovernanceApiService + */ public static IdentityGovernanceApiService getIdentityGovernanceApi() { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java index 4d153e5086..a0518cd01a 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/core/ServerIdentityGovernanceService.java @@ -26,7 +26,6 @@ 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.identity.governance.common.GovernanceConstants; -import org.wso2.carbon.identity.api.server.identity.governance.common.GovernanceDataHolder; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoriesRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoryConnectorsRes; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.CategoryRes; @@ -68,8 +67,14 @@ */ public class ServerIdentityGovernanceService { + private final IdentityGovernanceService identityGovernanceService; private static final Log LOG = LogFactory.getLog(ServerIdentityGovernanceService.class); + public ServerIdentityGovernanceService(IdentityGovernanceService identityGovernanceService) { + + this.identityGovernanceService = identityGovernanceService; + } + /** * Get all governance connector categories. * @@ -84,7 +89,6 @@ public List getGovernanceConnectors(Integer limit, Integer offset handleNotImplementedCapabilities(limit, offset, filter, sort); try { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); Map> connectorConfigs = identityGovernanceService.getCategorizedConnectorListWithConfigs(tenantDomain); @@ -125,7 +129,6 @@ public CategoryRes getGovernanceConnectorCategory(String categoryId) { public List getGovernanceConnectorsByCategory(String categoryId) { try { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String category = new String(Base64.getUrlDecoder().decode(categoryId), StandardCharsets.UTF_8); List connectorConfigs = @@ -155,7 +158,6 @@ public List getGovernanceConnectorsByCategory(String categoryId) { public ConnectorRes getGovernanceConnector(String categoryId, String connectorId) { try { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); String connectorName = new String(Base64.getUrlDecoder().decode(connectorId), StandardCharsets.UTF_8); ConnectorConfig connectorConfig = @@ -188,7 +190,6 @@ public ConnectorRes getGovernanceConnector(String categoryId, String connectorId */ public List getConfigPreference(List preferenceSearchAttribute) { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); List preferenceRespList = new ArrayList<>(); for (PreferenceSearchAttribute prefSearchAttr : preferenceSearchAttribute) { @@ -288,7 +289,6 @@ public void updateGovernanceConnectorProperty(String categoryId, String connecto ConnectorsPatchReq governanceConnector) { try { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); ConnectorRes connector = getGovernanceConnector(categoryId, connectorId); @@ -330,7 +330,6 @@ public void updateGovernanceConnectorProperties(String categoryId, MultipleConnectorsPatchReq multipleConnectorsPatchReq) { try { - IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); // Check whether the category ID exists. diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java new file mode 100644 index 0000000000..1680880a57 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/factories/ServerIdentityGovernanceServiceFactory.java @@ -0,0 +1,51 @@ +/* + * 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.identity.governance.v1.factories; + +import org.wso2.carbon.identity.api.server.identity.governance.common.GovernanceDataHolder; +import org.wso2.carbon.identity.api.server.identity.governance.v1.core.ServerIdentityGovernanceService; +import org.wso2.carbon.identity.governance.IdentityGovernanceService; + +/** + * Factory class for Server Identity Governance Service. + */ +public class ServerIdentityGovernanceServiceFactory { + + private static final ServerIdentityGovernanceService SERVICE; + + static { + IdentityGovernanceService identityGovernanceService = GovernanceDataHolder.getIdentityGovernanceService(); + + if (identityGovernanceService == null) { + throw new IllegalStateException("RolePermissionManagementService is not available from OSGi context."); + } + + SERVICE = new ServerIdentityGovernanceService(identityGovernanceService); + } + + /** + * Get IdentityGovernanceService. + * + * @return IdentityGovernanceService + */ + public static ServerIdentityGovernanceService getServerIdentityGovernanceService() { + + return SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java index dd85e5de13..8e647bee74 100644 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/java/org/wso2/carbon/identity/api/server/identity/governance/v1/impl/IdentityGovernanceApiServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2019-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 @@ -18,9 +18,9 @@ package org.wso2.carbon.identity.api.server.identity.governance.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.identity.governance.v1.IdentityGovernanceApiService; import org.wso2.carbon.identity.api.server.identity.governance.v1.core.ServerIdentityGovernanceService; +import org.wso2.carbon.identity.api.server.identity.governance.v1.factories.ServerIdentityGovernanceServiceFactory; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.ConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.MultipleConnectorsPatchReq; import org.wso2.carbon.identity.api.server.identity.governance.v1.model.PreferenceSearchAttribute; @@ -33,8 +33,16 @@ */ public class IdentityGovernanceApiServiceImpl implements IdentityGovernanceApiService { - @Autowired - private ServerIdentityGovernanceService identityGovernanceService; + private final ServerIdentityGovernanceService identityGovernanceService; + + public IdentityGovernanceApiServiceImpl() { + try { + this.identityGovernanceService = ServerIdentityGovernanceServiceFactory + .getServerIdentityGovernanceService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating identity governance service.", e); + } + } @Override public Response getCategories(Integer limit, Integer offset, String filter, String sort) { diff --git a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/META-INF/cxf/identity-governance-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/META-INF/cxf/identity-governance-server-v1-cxf.xml deleted file mode 100644 index 5a60e64fd2..0000000000 --- a/components/org.wso2.carbon.identity.api.server.identity.governance/org.wso2.carbon.identity.api.server.identity.governance.v1/src/main/resources/META-INF/cxf/identity-governance-server-v1-cxf.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - -