diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/pom.xml index 0c633e70eb..9cb5d03741 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/pom.xml @@ -50,10 +50,5 @@ org.wso2.carbon.identity.organization.management.service provided - - org.springframework - spring-web - provided - diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/ClaimManagementDataHolder.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/ClaimManagementDataHolder.java index 6dda201330..8a2df63f93 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/ClaimManagementDataHolder.java +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/ClaimManagementDataHolder.java @@ -1,21 +1,24 @@ /* - * Copyright (c) (2019-2023), WSO2 LLC. (http://www.wso2.org). + * 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.claim.management.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; import org.wso2.carbon.identity.organization.management.service.OrganizationManager; @@ -24,37 +27,35 @@ */ public class ClaimManagementDataHolder { - private static ClaimMetadataManagementService claimMetadataManagementService; - private static OrganizationManager organizationManager; - - public static ClaimMetadataManagementService getClaimMetadataManagementService() { - - return claimMetadataManagementService; + private static class OrganizationManagerHolder { + static final OrganizationManager SERVICE = (OrganizationManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext() + .getOSGiService(OrganizationManager.class, null); } - public static void setClaimMetadataManagementService( - ClaimMetadataManagementService claimMetadataManagementService) { - - ClaimManagementDataHolder.claimMetadataManagementService = claimMetadataManagementService; + private static class ClaimMetadataManagementServiceHolder { + static final ClaimMetadataManagementService SERVICE = (ClaimMetadataManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext() + .getOSGiService(ClaimMetadataManagementService.class, null); } /** - * Get organizationManager OSGi service. + * Get ClaimMetadataManagementService OSGi service. * - * @return organization Manager. + * @return ClaimMetadataManagementService. */ - public static OrganizationManager getOrganizationManager() { + public static ClaimMetadataManagementService getClaimMetadataManagementService() { - return organizationManager; + return ClaimMetadataManagementServiceHolder.SERVICE; } /** - * Set organizationManager OSGi service. + * Get organizationManager OSGi service. * - * @param organizationManager Organization Manager. + * @return organization Manager. */ - public static void setOrganizationManager(OrganizationManager organizationManager) { + public static OrganizationManager getOrganizationManager() { - ClaimManagementDataHolder.organizationManager = organizationManager; + return OrganizationManagerHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/factory/OSGIServiceFactory.java deleted file mode 100644 index 85c8f0385f..0000000000 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/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.claim.management.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 OSGIServiceFactory extends AbstractFactoryBean { - - private ClaimMetadataManagementService claimMetadataManagementService; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected ClaimMetadataManagementService createInstance() throws Exception { - - if (this.claimMetadataManagementService == null) { - ClaimMetadataManagementService identityGovernanceService = (ClaimMetadataManagementService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(ClaimMetadataManagementService.class, null); - if (identityGovernanceService != null) { - this.claimMetadataManagementService = identityGovernanceService; - } else { - throw new Exception("Unable to retrieve ClaimMetadataManagementService service."); - } - } - return this.claimMetadataManagementService; - } - -} diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/factory/OrganizationManagementOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/factory/OrganizationManagementOSGIServiceFactory.java deleted file mode 100644 index cec4ed1e4f..0000000000 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.api.server.claim.management.common/src/main/java/org/wso2/carbon/identity/api/server/claim/management/common/factory/OrganizationManagementOSGIServiceFactory.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2023, 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.claim.management.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.organization.management.service.OrganizationManager; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the OrganizationManagementService type of object inside the container. - */ -public class OrganizationManagementOSGIServiceFactory extends AbstractFactoryBean { - - private OrganizationManager organizationManager; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected OrganizationManager createInstance() throws Exception { - - if (this.organizationManager == null) { - OrganizationManager orgMgtService = (OrganizationManager) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(OrganizationManager.class, null); - if (orgMgtService == null) { - throw new Exception("Unable to retrieve Organization Management service."); - } - this.organizationManager = orgMgtService; - } - return this.organizationManager; - } -} - - diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/pom.xml b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/pom.xml index 99a533338a..09be07b811 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/pom.xml @@ -80,11 +80,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.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/ClaimManagementApi.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/ClaimManagementApi.java index c92ef9ee80..4251b27060 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/ClaimManagementApi.java +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/ClaimManagementApi.java @@ -1,22 +1,23 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2021-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.rest.api.server.claim.management.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.*; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.ClaimManagementApiService; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.factories.ClaimManagementApiServiceFactory; @@ -45,8 +46,11 @@ @io.swagger.annotations.Api(value = "/claim-dialects", description = "the claim-dialects API") public class ClaimManagementApi { - @Autowired - private ClaimManagementApiService delegate; + private final ClaimManagementApiService delegate; + + public ClaimManagementApi() { + this.delegate = ClaimManagementApiServiceFactory.getClaimManagementApi(); + } @Valid @POST diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ClaimManagementApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ClaimManagementApiServiceFactory.java index 55d77c73ae..96419ff86c 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ClaimManagementApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/gen/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ClaimManagementApiServiceFactory.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.rest.api.server.claim.management.v1.factories; @@ -19,12 +21,20 @@ import org.wso2.carbon.identity.rest.api.server.claim.management.v1.ClaimManagementApiService; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.impl.ClaimManagementApiServiceImpl; +/** + * Factory class for ClaimManagementApiService. + */ public class ClaimManagementApiServiceFactory { - private final static ClaimManagementApiService service = new ClaimManagementApiServiceImpl(); + private final static ClaimManagementApiService SERVICE = new ClaimManagementApiServiceImpl(); + /** + * Get ClaimManagementApiService. + * + * @return ClaimManagementApiService. + */ public static ClaimManagementApiService getClaimManagementApi() { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/core/ServerClaimManagementService.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/core/ServerClaimManagementService.java index 4146a2dcdb..7e73d61ca6 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/core/ServerClaimManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/core/ServerClaimManagementService.java @@ -1,17 +1,19 @@ /* - * Copyright (c) (2019-2023), WSO2 LLC. (http://www.wso2.org). + * 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. - * You may obtain a copy of the License at + * 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 + * 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.rest.api.server.claim.management.v1.core; @@ -37,6 +39,7 @@ import org.wso2.carbon.identity.api.server.common.error.ErrorResponse; import org.wso2.carbon.identity.api.server.common.error.bulk.BulkAPIError; import org.wso2.carbon.identity.api.server.common.error.bulk.BulkErrorResponse; +import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataClientException; import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.model.AttributeMapping; @@ -45,6 +48,7 @@ import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim; import org.wso2.carbon.identity.claim.metadata.mgt.util.ClaimConstants; import org.wso2.carbon.identity.core.util.IdentityUtil; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.AttributeMappingDTO; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.ClaimDialectReqDTO; @@ -88,7 +92,6 @@ import javax.xml.bind.Unmarshaller; import static org.wso2.carbon.identity.api.server.claim.management.common.ClaimManagementDataHolder.getClaimMetadataManagementService; -import static org.wso2.carbon.identity.api.server.claim.management.common.ClaimManagementDataHolder.getOrganizationManager; import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.CMT_PATH_COMPONENT; import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.ErrorMessage.ERROR_CODE_ATTRIBUTE_FILTERING_NOT_IMPLEMENTED; import static org.wso2.carbon.identity.api.server.claim.management.common.Constant.ErrorMessage.ERROR_CODE_CLAIMS_NOT_FOUND_FOR_DIALECT; @@ -158,6 +161,15 @@ public class ServerClaimManagementService { ClaimConstants.ErrorMessage.ERROR_CODE_EXISTING_EXTERNAL_CLAIM_URI.getCode(), ClaimConstants.ErrorMessage.ERROR_CODE_EXISTING_LOCAL_CLAIM_URI.getCode() ); + private final ClaimMetadataManagementService claimMetadataManagementService; + private final OrganizationManager organizationManager; + + public ServerClaimManagementService(ClaimMetadataManagementService claimMetadataManagementService, + OrganizationManager organizationManager) { + + this.claimMetadataManagementService = claimMetadataManagementService; + this.organizationManager = organizationManager; + } /** * Add a claim dialect. @@ -190,7 +202,7 @@ public String addClaimDialect(String dialectURI) { try { validateClaimModificationEligibility(); - getClaimMetadataManagementService().addClaimDialect( + claimMetadataManagementService.addClaimDialect( createClaimDialect(dialectURI), ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { @@ -216,7 +228,7 @@ public void deleteClaimDialect(String dialectId) { return; } try { - getClaimMetadataManagementService().removeClaimDialect( + claimMetadataManagementService.removeClaimDialect( new ClaimDialect(claimDialectURI), ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { @@ -234,7 +246,7 @@ public void deleteClaimDialect(String dialectId) { public ClaimDialectResDTO getClaimDialect(String dialectId) { try { - List claimDialectList = getClaimMetadataManagementService().getClaimDialects( + List claimDialectList = claimMetadataManagementService.getClaimDialects( ContextLoader.getTenantDomainFromContext()); String decodedDialectId; if (StringUtils.equals(dialectId, LOCAL_DIALECT_PATH)) { @@ -268,8 +280,8 @@ public List getClaimDialects(Integer limit, Integer offset, handleNotImplementedCapabilities(limit, offset, filter, sort); try { - List claimDialectList = getClaimMetadataManagementService().getClaimDialects( - ContextLoader.getTenantDomainFromContext()); + List claimDialectList = claimMetadataManagementService.getClaimDialects(ContextLoader + .getTenantDomainFromContext()); return getClaimDialectResDTOs(claimDialectList); @@ -293,8 +305,7 @@ public String updateClaimDialect(String dialectId, ClaimDialectReqDTO claimDiale validateClaimModificationEligibility(); // If the old and new dialect uri is the same we don't need to do a db update. if (!StringUtils.equals(base64DecodeId(dialectId), claimDialectReqDTO.getDialectURI())) { - getClaimMetadataManagementService().renameClaimDialect( - createClaimDialect(base64DecodeId(dialectId)), + claimMetadataManagementService.renameClaimDialect(createClaimDialect(base64DecodeId(dialectId)), createClaimDialect(claimDialectReqDTO), ContextLoader.getTenantDomainFromContext()); } else { @@ -332,8 +343,8 @@ public String addLocalClaim(LocalClaimReqDTO localClaimReqDTO) { try { validateClaimModificationEligibility(); validateAttributeMappings(localClaimReqDTO.getAttributeMapping()); - getClaimMetadataManagementService().addLocalClaim(createLocalClaim(localClaimReqDTO), - ContextLoader.getTenantDomainFromContext()); + claimMetadataManagementService.addLocalClaim(createLocalClaim(localClaimReqDTO), ContextLoader + .getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_ADDING_LOCAL_CLAIM, localClaimReqDTO.getClaimURI()); @@ -361,9 +372,7 @@ public void deleteLocalClaim(String claimId) { return; } try { - getClaimMetadataManagementService().removeLocalClaim( - claimURI, - ContextLoader.getTenantDomainFromContext()); + claimMetadataManagementService.removeLocalClaim(claimURI, ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_DELETING_LOCAL_CLAIM, claimId); } @@ -379,8 +388,8 @@ public void deleteLocalClaim(String claimId) { public LocalClaimResDTO getLocalClaim(String claimId) { try { - List localClaimList = getClaimMetadataManagementService().getLocalClaims( - ContextLoader.getTenantDomainFromContext()); + List localClaimList = claimMetadataManagementService.getLocalClaims(ContextLoader + .getTenantDomainFromContext()); LocalClaim localClaim = extractLocalClaimFromClaimList(base64DecodeId(claimId), localClaimList); @@ -412,8 +421,8 @@ public List getLocalClaims(Boolean excludeIdentityClaims, Stri handleNotImplementedCapabilities(attributes, limit, offset, filter, sort); try { - List localClaimList = getClaimMetadataManagementService().getLocalClaims( - ContextLoader.getTenantDomainFromContext()); + List localClaimList = claimMetadataManagementService.getLocalClaims(ContextLoader + .getTenantDomainFromContext()); if (excludeIdentityClaims != null && excludeIdentityClaims) { localClaimList = localClaimList.stream() @@ -448,7 +457,7 @@ public void updateLocalClaim(String claimId, LocalClaimReqDTO localClaimReqDTO) BAD_REQUEST); } validateAttributeMappings(localClaimReqDTO.getAttributeMapping()); - getClaimMetadataManagementService().updateLocalClaim(createLocalClaim(localClaimReqDTO), + claimMetadataManagementService.updateLocalClaim(createLocalClaim(localClaimReqDTO), ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_UPDATING_LOCAL_CLAIM, claimId); @@ -526,7 +535,7 @@ private void updateLocalClaims(List localClaimReqDTOList, bool private void deleteObsoleteLocalClaims(List localClaimReqDTOList, List errors) throws ClaimMetadataException { - List claimsToDelete = getLocalClaimResDTOs(getClaimMetadataManagementService() + List claimsToDelete = getLocalClaimResDTOs(claimMetadataManagementService .getLocalClaims(ContextLoader.getTenantDomainFromContext())).stream() .map(LocalClaimResDTO::getClaimURI) .filter(claimURI -> localClaimReqDTOList.stream() @@ -602,12 +611,12 @@ public FileContent exportClaimDialectToFile(String dialectId, String fileType) { try { if (LOCAL_DIALECT_PATH.equals(dialectId)) { - List localClaimResDTOList = getLocalClaimResDTOs(getClaimMetadataManagementService() + List localClaimResDTOList = getLocalClaimResDTOs(claimMetadataManagementService .getLocalClaims(ContextLoader.getTenantDomainFromContext())); claimResDTOList.addAll(localClaimResDTOList); dialectConfiguration.setClaims(claimResDTOList); } else { - List externalClaimList = getClaimMetadataManagementService().getExternalClaims( + List externalClaimList = claimMetadataManagementService.getExternalClaims( base64DecodeId(dialectId), ContextLoader.getTenantDomainFromContext()); List externalClaimResDTOList = getExternalClaimResDTOs(externalClaimList); @@ -717,8 +726,7 @@ public String addExternalClaim(String dialectId, ExternalClaimReqDTO externalCla throw handleClaimManagementClientError(ERROR_CODE_INVALID_DIALECT_ID, NOT_FOUND, dialectId); } - getClaimMetadataManagementService().addExternalClaim( - createExternalClaim(dialectId, externalClaimReqDTO), + claimMetadataManagementService.addExternalClaim(createExternalClaim(dialectId, externalClaimReqDTO), ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_ADDING_EXTERNAL_CLAIM, @@ -748,9 +756,7 @@ public void deleteExternalClaim(String dialectId, String claimId) { } try { - getClaimMetadataManagementService().removeExternalClaim( - externalClaimDialectURI, - externalClaimURI, + claimMetadataManagementService.removeExternalClaim(externalClaimDialectURI, externalClaimURI, ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_DELETING_EXTERNAL_CLAIM, claimId); @@ -768,7 +774,7 @@ public void deleteExternalClaim(String dialectId, String claimId) { public ExternalClaimResDTO getExternalClaim(String dialectId, String claimId) { try { - List externalClaimList = getClaimMetadataManagementService().getExternalClaims( + List externalClaimList = claimMetadataManagementService.getExternalClaims( base64DecodeId(dialectId), ContextLoader.getTenantDomainFromContext()); @@ -806,8 +812,8 @@ public List getExternalClaims(String dialectId, Integer lim handleNotImplementedCapabilities(limit, offset, filter, sort); try { - List claimDialectList = getClaimMetadataManagementService().getClaimDialects( - ContextLoader.getTenantDomainFromContext()); + List claimDialectList = claimMetadataManagementService.getClaimDialects(ContextLoader + .getTenantDomainFromContext()); String decodedDialectId = base64DecodeId(dialectId); ClaimDialect claimDialect = extractDialectFromDialectList(decodedDialectId, claimDialectList); @@ -815,7 +821,7 @@ public List getExternalClaims(String dialectId, Integer lim throw handleClaimManagementClientError(ERROR_CODE_DIALECT_NOT_FOUND, NOT_FOUND, dialectId); } - List externalClaimList = getClaimMetadataManagementService().getExternalClaims( + List externalClaimList = claimMetadataManagementService.getExternalClaims( base64DecodeId(dialectId), ContextLoader.getTenantDomainFromContext()); return getExternalClaimResDTOs(externalClaimList); @@ -840,8 +846,7 @@ public void updateExternalClaim(String dialectId, String claimId, ExternalClaimR throw handleClaimManagementClientError(ERROR_CODE_EXTERNAL_CLAIM_CONFLICT, CONFLICT, base64DecodeId(claimId), dialectId); } - getClaimMetadataManagementService().updateExternalClaim( - createExternalClaim(dialectId, externalClaimReqDTO), + claimMetadataManagementService.updateExternalClaim(createExternalClaim(dialectId, externalClaimReqDTO), ContextLoader.getTenantDomainFromContext()); } catch (ClaimMetadataException e) { throw handleClaimManagementException(e, ERROR_CODE_ERROR_UPDATING_EXTERNAL_CLAIM, claimId, dialectId); @@ -1231,7 +1236,7 @@ private boolean isUserStoreExists(String userStoreDomain) throws UserStoreExcept private boolean isDialectExists(String dialectId) throws ClaimMetadataException { List claimDialectList = - getClaimMetadataManagementService().getClaimDialects(ContextLoader.getTenantDomainFromContext()); + claimMetadataManagementService.getClaimDialects(ContextLoader.getTenantDomainFromContext()); ClaimDialect claimDialect = extractDialectFromDialectList(base64DecodeId(dialectId), claimDialectList); return claimDialect != null; @@ -1239,8 +1244,8 @@ private boolean isDialectExists(String dialectId) throws ClaimMetadataException private boolean isLocalClaimExist(String claimId) throws ClaimMetadataException { - List localClaimList = getClaimMetadataManagementService().getLocalClaims( - ContextLoader.getTenantDomainFromContext()); + List localClaimList = claimMetadataManagementService.getLocalClaims(ContextLoader + .getTenantDomainFromContext()); LocalClaim localClaim = extractLocalClaimFromClaimList(base64DecodeId(claimId), localClaimList); return localClaim != null; @@ -1248,7 +1253,7 @@ private boolean isLocalClaimExist(String claimId) throws ClaimMetadataException private boolean isExternalClaimExist(String dialectId, String claimId) throws ClaimMetadataException { - List externalClaimList = getClaimMetadataManagementService().getExternalClaims( + List externalClaimList = claimMetadataManagementService.getExternalClaims( base64DecodeId(dialectId), ContextLoader.getTenantDomainFromContext()); ExternalClaim externalClaim = extractExternalClaimFromClaimList(base64DecodeId(claimId), externalClaimList); @@ -1465,8 +1470,8 @@ private void validateClaimModificationEligibility() throws ClaimMetadataClientEx String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { - String organizationId = getOrganizationManager().resolveOrganizationId(tenantDomain); - boolean isPrimaryOrg = getOrganizationManager().isPrimaryOrganization(organizationId); + String organizationId = organizationManager.resolveOrganizationId(tenantDomain); + boolean isPrimaryOrg = organizationManager.isPrimaryOrganization(organizationId); if (!MultitenantConstants.SUPER_TENANT_DOMAIN_NAME.equals(tenantDomain) && !isPrimaryOrg) { throw handleClaimManagementClientError(ERROR_CODE_UNAUTHORIZED_ORG_FOR_CLAIM_MANAGEMENT, FORBIDDEN, organizationId); diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ServerClaimManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ServerClaimManagementServiceFactory.java new file mode 100644 index 0000000000..38ce0cf5b3 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/factories/ServerClaimManagementServiceFactory.java @@ -0,0 +1,57 @@ +/* + * 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.rest.api.server.claim.management.v1.factories; + +import org.wso2.carbon.identity.api.server.claim.management.common.ClaimManagementDataHolder; +import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementService; +import org.wso2.carbon.identity.organization.management.service.OrganizationManager; +import org.wso2.carbon.identity.rest.api.server.claim.management.v1.core.ServerClaimManagementService; + +/** + * Factory class for ServerClaimManagementService. + */ +public class ServerClaimManagementServiceFactory { + + private static final ServerClaimManagementService SERVICE; + + static { + ClaimMetadataManagementService claimMetadataManagementService = ClaimManagementDataHolder + .getClaimMetadataManagementService(); + OrganizationManager organizationManager = ClaimManagementDataHolder.getOrganizationManager(); + + if (claimMetadataManagementService == null) { + throw new IllegalStateException("ClaimMetadataManagementService is not available from OSGi context."); + } + + if (organizationManager == null) { + throw new IllegalStateException("OrganizationManager is not available from OSGi context."); + } + + SERVICE = new ServerClaimManagementService(claimMetadataManagementService, organizationManager); + } + + /** + * Get ServerClaimManagementService. + * + * @return ServerClaimManagementService + */ + public static ServerClaimManagementService getServerClaimManagementService() { + return SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/impl/ClaimManagementApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/impl/ClaimManagementApiServiceImpl.java index ee1fa73c61..d1257578f2 100644 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/impl/ClaimManagementApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/java/org/wso2/carbon/identity/rest/api/server/claim/management/v1/impl/ClaimManagementApiServiceImpl.java @@ -1,24 +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.rest.api.server.claim.management.v1.impl; import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpHeaders; import org.wso2.carbon.identity.api.server.common.FileContent; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.ClaimManagementApiService; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.core.ServerClaimManagementService; @@ -26,6 +26,7 @@ import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.ClaimDialectReqDTO; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.ExternalClaimReqDTO; import org.wso2.carbon.identity.rest.api.server.claim.management.v1.dto.LocalClaimReqDTO; +import org.wso2.carbon.identity.rest.api.server.claim.management.v1.factories.ServerClaimManagementServiceFactory; import java.io.InputStream; import java.net.URI; @@ -43,8 +44,15 @@ */ public class ClaimManagementApiServiceImpl extends ClaimManagementApiService { - @Autowired - private ServerClaimManagementService claimManagementService; + private final ServerClaimManagementService claimManagementService; + + public ClaimManagementApiServiceImpl() { + try { + claimManagementService = ServerClaimManagementServiceFactory.getServerClaimManagementService(); + } catch (Exception e) { + throw new RuntimeException("Error occurred while initiating claim management services.", e); + } + } @Override public Response addClaimDialect(ClaimDialectReqDTO claimDialect) { @@ -174,11 +182,11 @@ public Response exportClaimDialectToFile(String dialectId, 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") - .header(HttpHeaders.EXPIRES, "0") + .header("Cache-Control", "no-cache, no-store, must-revalidate") + .header("Pragma", "no-cache") + .header("Expires", "0") .entity(fileContent.getContent().getBytes(StandardCharsets.UTF_8)) .build(); } diff --git a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/resources/META-INF/cxf/claim-management-server-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/resources/META-INF/cxf/claim-management-server-v1-cxf.xml deleted file mode 100644 index 8997dfc24f..0000000000 --- a/components/org.wso2.carbon.identity.api.server.claim.management/org.wso2.carbon.identity.rest.api.server.claim.management.v1/src/main/resources/META-INF/cxf/claim-management-server-v1-cxf.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - - - - - - -