From 3d04b1936e84fe12fecfbf3b04643a06edebe633 Mon Sep 17 00:00:00 2001 From: lashini Date: Thu, 23 Jan 2025 22:48:36 +0530 Subject: [PATCH] [Spring Cleanup] Remove Spring dependencies in permission management API --- .../pom.xml | 9 +--- ...PermissionManagementServiceDataHolder.java | 45 ++++++++-------- ...olePermissionManagementServiceFactory.java | 53 ------------------- .../pom.xml | 33 ++++-------- .../v1/PermissionManagementApi.java | 41 ++++++++------ ...PermissionManagementApiServiceFactory.java | 34 ++++++++++-- .../v1/core/PermissionManagementService.java | 27 ++++++---- .../PermissionManagementServiceFactory.java | 52 ++++++++++++++++++ .../PermissionManagementApiServiceImpl.java | 44 +++++++++------ .../cxf/permission-management-v1-cxf.xml | 27 ---------- .../pom.xml | 8 +-- 11 files changed, 185 insertions(+), 188 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.common/src/main/java/org/wso2/carbon/identity/api/server/permission/management/common/RolePermissionManagementServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/resources/META-INF/cxf/permission-management-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.common/pom.xml b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.common/pom.xml index cad474b3d5..a5918b1af0 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.common/pom.xml @@ -1,8 +1,8 @@ @@ -104,11 +106,6 @@ cxf-rt-rs-service-description provided - - org.springframework - spring-web - provided - javax.ws.rs javax.ws.rs-api @@ -149,22 +146,12 @@ jackson-jaxrs-json-provider provided - - org.springframework - spring-context - provided - org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.permission.management.common ${project.version} provided - - org.springframework - spring-beans - provided - org.wso2.carbon.identity.server.api org.wso2.carbon.identity.api.server.common diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/PermissionManagementApi.java b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/PermissionManagementApi.java index 731e3de1f5..ffde22d2be 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/PermissionManagementApi.java +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/PermissionManagementApi.java @@ -1,18 +1,20 @@ /* -* 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-2025, 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.permission.management.v1; @@ -21,7 +23,8 @@ import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Authorization; -import org.springframework.beans.factory.annotation.Autowired; +import org.wso2.carbon.identity.api.server.permission.management.v1.factories.PermissionManagementApiServiceFactory; +import org.wso2.carbon.identity.api.server.permission.management.v1.impl.PermissionManagementApiServiceImpl; import org.wso2.carbon.identity.api.server.permission.management.v1.model.Error; import org.wso2.carbon.identity.api.server.permission.management.v1.model.Permission; @@ -36,8 +39,12 @@ public class PermissionManagementApi { - @Autowired - private PermissionManagementApiService delegate; + private final PermissionManagementApiService delegate; + + public PermissionManagementApi() { + + this.delegate = PermissionManagementApiServiceFactory.getPermissionManagementApi(); + } @Valid @GET diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementApiServiceFactory.java b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementApiServiceFactory.java index b44c072632..8f487e1ff2 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/gen/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementApiServiceFactory.java @@ -1,14 +1,40 @@ +/* + * Copyright (c) 2019-2025, 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.permission.management.v1.factories; import org.wso2.carbon.identity.api.server.permission.management.v1.PermissionManagementApiService; import org.wso2.carbon.identity.api.server.permission.management.v1.impl.PermissionManagementApiServiceImpl; +/** + * Factory class for PermissionManagementApiService. + */ public class PermissionManagementApiServiceFactory { - private final static PermissionManagementApiService service = new PermissionManagementApiServiceImpl(); + private final static PermissionManagementApiService SERVICE = new PermissionManagementApiServiceImpl(); + + /** + * Get PermissionManagementApiService. + * + * @return PermissionManagementApiService + */ + public static PermissionManagementApiService getPermissionManagementApi() { - public static PermissionManagementApiService getPermissionManagementApi() - { - return service; + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/core/PermissionManagementService.java b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/core/PermissionManagementService.java index fddd44041e..0192f83459 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/core/PermissionManagementService.java +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/core/PermissionManagementService.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2019-2025, 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.permission.management.v1.core; @@ -23,7 +25,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.permission.management.common.Constant; -import org.wso2.carbon.identity.api.server.permission.management.common.RolePermissionManagementServiceDataHolder; import org.wso2.carbon.identity.api.server.permission.management.v1.model.Permission; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.user.mgt.RolePermissionException; @@ -36,8 +37,14 @@ */ public class PermissionManagementService { + private final RolePermissionManagementService rolePermissionManagementService; private static final Log LOG = LogFactory.getLog(PermissionManagementService.class); + public PermissionManagementService(RolePermissionManagementService rolePermissionManagementService) { + + this.rolePermissionManagementService = rolePermissionManagementService; + } + /** * Get all permissions array. * @@ -47,8 +54,6 @@ public Permission[] getAllPermissions() { try { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); - RolePermissionManagementService rolePermissionManagementService = - RolePermissionManagementServiceDataHolder.getRolePermissionManagementService(); return getPermissionObjects(rolePermissionManagementService.getAllPermissions(IdentityTenantUtil .getTenantId(tenantDomain))); } catch (RolePermissionException e) { diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementServiceFactory.java b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementServiceFactory.java new file mode 100644 index 0000000000..6131d39261 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/factories/PermissionManagementServiceFactory.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2025, 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.permission.management.v1.factories; + +import org.wso2.carbon.identity.api.server.permission.management.common.RolePermissionManagementServiceDataHolder; +import org.wso2.carbon.identity.api.server.permission.management.v1.core.PermissionManagementService; +import org.wso2.carbon.user.mgt.RolePermissionManagementService; + +/** + * Permission Management Service Factory. + */ +public class PermissionManagementServiceFactory { + + private static final PermissionManagementService SERVICE; + + static { + RolePermissionManagementService rolePermissionManagementService = RolePermissionManagementServiceDataHolder + .getRolePermissionManagementService(); + + if (rolePermissionManagementService == null) { + throw new IllegalStateException("RolePermissionManagementService is not available from OSGi context."); + } + + SERVICE = new PermissionManagementService(rolePermissionManagementService); + } + + /** + * Get PermissionManagementService. + * + * @return PermissionManagementService + */ + public static PermissionManagementService getPermissionManagementService() { + + return SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/impl/PermissionManagementApiServiceImpl.java b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/impl/PermissionManagementApiServiceImpl.java index 4a27b38c44..e85019bc06 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/impl/PermissionManagementApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/java/org/wso2/carbon/identity/api/server/permission/management/v1/impl/PermissionManagementApiServiceImpl.java @@ -1,24 +1,26 @@ /* -* 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-2025, 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.permission.management.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.server.permission.management.v1.PermissionManagementApiService; import org.wso2.carbon.identity.api.server.permission.management.v1.core.PermissionManagementService; +import org.wso2.carbon.identity.api.server.permission.management.v1.factories.PermissionManagementServiceFactory; import javax.ws.rs.core.Response; @@ -27,8 +29,16 @@ */ public class PermissionManagementApiServiceImpl implements PermissionManagementApiService { - @Autowired - private PermissionManagementService permissionManagementService; + private final PermissionManagementService permissionManagementService; + + public PermissionManagementApiServiceImpl() { + + try { + this.permissionManagementService = PermissionManagementServiceFactory.getPermissionManagementService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating PermissionManagementService.", e); + } + } @Override public Response permissionManagementPermissionsGet() { diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/resources/META-INF/cxf/permission-management-v1-cxf.xml b/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/resources/META-INF/cxf/permission-management-v1-cxf.xml deleted file mode 100644 index 93f9a7c76f..0000000000 --- a/components/org.wso2.carbon.identity.api.server.permission.management/org.wso2.carbon.identity.api.server.permission.management.v1/src/main/resources/META-INF/cxf/permission-management-v1-cxf.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - - - - - - - - diff --git a/components/org.wso2.carbon.identity.api.server.permission.management/pom.xml b/components/org.wso2.carbon.identity.api.server.permission.management/pom.xml index f5fb56c9cf..6d951a368c 100644 --- a/components/org.wso2.carbon.identity.api.server.permission.management/pom.xml +++ b/components/org.wso2.carbon.identity.api.server.permission.management/pom.xml @@ -1,8 +1,8 @@