From 7a788e153eb84135ba2975f606c58d62dd971873 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:06:38 +0530 Subject: [PATCH 01/15] Remove Spring dependency from api.user.application --- .../pom.xml | 9 +-- .../common/ApplicationServiceHolder.java | 46 +++++++-------- .../common/factory/OSGIServiceFactory.java | 54 ----------------- ...anizationManagementOSGIServiceFactory.java | 55 ----------------- .../pom.xml | 9 +-- .../rest/api/user/application/v1/MeApi.java | 41 +++++++------ .../v1/factories/MeApiServiceFactory.java | 42 ++++++++----- .../v1/core/ApplicationService.java | 29 +++++---- .../factories/ApplicationServiceFactory.java | 59 +++++++++++++++++++ .../application/v1/impl/MeApiServiceImpl.java | 31 ++++++---- .../META-INF/cxf/application-user-v1-cxf.xml | 33 ----------- 11 files changed, 171 insertions(+), 237 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/src/main/java/org/wso2/carbon/identity/api/user/application/common/factory/OrganizationManagementOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/application/v1/factories/ApplicationServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.rest.api.user.application.v1/src/main/resources/META-INF/cxf/application-user-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml index 72447002b..15a0222e2 100644 --- a/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.application/org.wso2.carbon.identity.api.user.application.common/pom.xml @@ -1,8 +1,8 @@ - - - - - - - - - - - From 9030284a9882c3c8a6add91561a80b2ac88986f9 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:09:17 +0530 Subject: [PATCH 02/15] Remove Spring dependency from api.user.organization --- .../pom.xml | 7 +- .../common/UserOrganizationServiceHolder.java | 65 ++++++++----------- ...plicationManagementOSGIServiceFactory.java | 54 --------------- ...anizationManagementOSGIServiceFactory.java | 53 --------------- ...serResidentResolverOSGIServiceFactory.java | 56 ---------------- .../pom.xml | 7 +- .../rest/api/user/organization/v1/MeApi.java | 13 ++-- .../api/user/organization/v1/RootApi.java | 13 ++-- .../v1/factories/MeApiServiceFactory.java | 6 +- .../v1/factories/RootApiServiceFactory.java | 6 +- .../v1/core/UserOrganizationService.java | 22 +++++-- .../UserOrganizationServiceFactory.java | 64 ++++++++++++++++++ .../v1/impl/MeApiServiceImpl.java | 15 +++-- .../v1/impl/RootApiServiceImpl.java | 15 +++-- .../META-INF/cxf/user-organization-v1-cxf.xml | 38 ----------- 15 files changed, 153 insertions(+), 281 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/src/main/java/org/wso2/carbon/identity/api/user/organization/common/factory/ApplicationManagementOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/src/main/java/org/wso2/carbon/identity/api/user/organization/common/factory/OrganizationManagementOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/src/main/java/org/wso2/carbon/identity/api/user/organization/common/factory/OrganizationUserResidentResolverOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.rest.api.user.organization.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/organization/v1/factories/UserOrganizationServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.rest.api.user.organization.v1/src/main/resources/META-INF/cxf/user-organization-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/pom.xml b/components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/pom.xml index 74107750e..9489c2008 100644 --- a/components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.organization/org.wso2.carbon.identity.api.user.organization.common/pom.xml @@ -1,6 +1,6 @@ - - - - - - - - - - - - - - - From cbf55aab38c27fd28890e29de867a79f17776e25 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:12:37 +0530 Subject: [PATCH 03/15] Remove Spring dependency from api.user.session --- .../pom.xml | 9 +-- .../common/factory/OSGIServiceFactory.java | 52 ----------------- .../RealmServiceOSGIServiceFactory.java | 52 ----------------- .../util/SessionManagementServiceHolder.java | 37 +++++++----- .../pom.xml | 9 +-- .../rest/api/user/session/v1/MeApi.java | 28 ++++++---- .../rest/api/user/session/v1/SessionsApi.java | 28 ++++++---- .../rest/api/user/session/v1/UserIdApi.java | 28 ++++++---- .../v1/factories/MeApiServiceFactory.java | 8 +-- .../factories/SessionsApiServiceFactory.java | 22 ++++---- .../v1/factories/UserIdApiServiceFactory.java | 8 +-- .../v1/core/SessionManagementService.java | 30 ++++++---- .../SessionManagementServiceFactory.java | 56 +++++++++++++++++++ .../session/v1/impl/MeApiServiceImpl.java | 18 ++++-- .../v1/impl/SessionsApiServiceImpl.java | 32 +++++++---- .../session/v1/impl/UserIdApiServiceImpl.java | 18 ++++-- .../META-INF/cxf/session-user-v1-cxf.xml | 34 ----------- 17 files changed, 219 insertions(+), 250 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/src/main/java/org/wso2/carbon/identity/api/user/session/common/factory/OSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/src/main/java/org/wso2/carbon/identity/api/user/session/common/factory/RealmServiceOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/session/v1/factories/SessionManagementServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.v1/src/main/resources/META-INF/cxf/session-user-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/pom.xml b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/pom.xml index 8fce4cf8d..cdf3fb60c 100644 --- a/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.session/org.wso2.carbon.identity.api.user.session.common/pom.xml @@ -1,8 +1,8 @@ - - - - - - - - - - - - - From cd4cb88e6cae01fae51fc40f4265eea36cdd000a Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:13:17 +0530 Subject: [PATCH 04/15] Remove Spring dependency from api.user.association --- .../pom.xml | 23 +++-- .../rest/api/user/association/v1/MeApi.java | 36 ++++---- .../api/user/association/v1/UserIdApi.java | 39 ++++---- .../v1/factories/MeApiServiceFactory.java | 28 +++--- .../v1/factories/UserIdApiServiceFactory.java | 28 +++--- ...dAssociationManagerOSGIServiceFactory.java | 52 ----------- .../RealmServiceOSGIServiceFactory.java | 52 ----------- ...serAccountConnectorOSGIServiceFactory.java | 51 ----------- .../v1/core/UserAssociationService.java | 66 ++++++++------ .../UserAssociationServiceFactory.java | 89 +++++++++++++++++++ .../association/v1/impl/MeApiServiceImpl.java | 34 ++++++- .../v1/impl/UserIdApiServiceImpl.java | 32 ++++++- .../v1/util/UserAssociationServiceHolder.java | 68 +++++++++----- .../META-INF/cxf/user-association-v1-cxf.xml | 35 -------- 14 files changed, 315 insertions(+), 318 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/FederatedAssociationManagerOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/RealmServiceOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/UserAccountConnectorOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserAssociationServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/resources/META-INF/cxf/user-association-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/pom.xml index 799398f5d..7bb65d1be 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/pom.xml @@ -1,5 +1,21 @@ - + @@ -66,11 +82,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.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/MeApi.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/MeApi.java index 7ff8a7fb2..81176b942 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/MeApi.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/MeApi.java @@ -1,39 +1,31 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.association.v1; -import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.identity.rest.api.user.association.v1.dto.*; -import org.wso2.carbon.identity.rest.api.user.association.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.association.v1.factories.MeApiServiceFactory; import io.swagger.annotations.ApiParam; -import org.wso2.carbon.identity.rest.api.user.association.v1.dto.ErrorDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.UserDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.AssociationUserRequestDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.FederatedAssociationDTO; -import java.util.List; - -import java.io.InputStream; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.cxf.jaxrs.ext.multipart.Multipart; - import javax.validation.Valid; import javax.ws.rs.core.Response; import javax.ws.rs.*; @@ -44,8 +36,12 @@ @io.swagger.annotations.Api(value = "/me", description = "the me API") public class MeApi { - @Autowired - private MeApiService delegate; + private final MeApiService delegate; + + public MeApi() { + + this.delegate = MeApiServiceFactory.getMeApi(); + } @Valid @DELETE diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/UserIdApi.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/UserIdApi.java index c4f203819..df33a7b0d 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/UserIdApi.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/UserIdApi.java @@ -1,37 +1,28 @@ /* - * 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.user.association.v1; -import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.identity.rest.api.user.association.v1.dto.*; -import org.wso2.carbon.identity.rest.api.user.association.v1.UserIdApiService; -import org.wso2.carbon.identity.rest.api.user.association.v1.factories.UserIdApiServiceFactory; - import io.swagger.annotations.ApiParam; -import org.wso2.carbon.identity.rest.api.user.association.v1.dto.ErrorDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.UserDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.FederatedAssociationDTO; - -import java.util.List; - -import java.io.InputStream; -import org.apache.cxf.jaxrs.ext.multipart.Attachment; -import org.apache.cxf.jaxrs.ext.multipart.Multipart; +import org.wso2.carbon.identity.rest.api.user.association.v1.factories.UserIdApiServiceFactory; import javax.validation.Valid; import javax.ws.rs.core.Response; @@ -43,8 +34,12 @@ @io.swagger.annotations.Api(value = "/{user-id}", description = "the {user-id} API") public class UserIdApi { - @Autowired - private UserIdApiService delegate; + private final UserIdApiService delegate; + + public UserIdApi() { + + this.delegate = UserIdApiServiceFactory.getUserIdApi(); + } @Valid @DELETE diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/MeApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/MeApiServiceFactory.java index cb1fe918e..6709d63c5 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/MeApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/MeApiServiceFactory.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.user.association.v1.factories; @@ -21,10 +23,10 @@ public class MeApiServiceFactory { - private final static MeApiService service = new MeApiServiceImpl(); + private final static MeApiService SERVICE = new MeApiServiceImpl(); - public static MeApiService getMeApi() - { - return service; - } + public static MeApiService getMeApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserIdApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserIdApiServiceFactory.java index cc79f22a6..c32955016 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserIdApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserIdApiServiceFactory.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.user.association.v1.factories; @@ -21,10 +23,10 @@ public class UserIdApiServiceFactory { - private final static UserIdApiService service = new UserIdApiServiceImpl(); + private final static UserIdApiService SERVICE = new UserIdApiServiceImpl(); - public static UserIdApiService getUserIdApi() - { - return service; - } + public static UserIdApiService getUserIdApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/FederatedAssociationManagerOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/FederatedAssociationManagerOSGIServiceFactory.java deleted file mode 100644 index 38aca9392..000000000 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/FederatedAssociationManagerOSGIServiceFactory.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.rest.api.user.association.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the FederatedAssociationManager type of object inside the container. - */ -public class FederatedAssociationManagerOSGIServiceFactory extends AbstractFactoryBean { - - private FederatedAssociationManager federatedAssociationManager; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected FederatedAssociationManager createInstance() throws Exception { - - if (this.federatedAssociationManager == null) { - FederatedAssociationManager federatedAssociationManager - = (FederatedAssociationManager) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(FederatedAssociationManager.class, null); - if (federatedAssociationManager != null) { - this.federatedAssociationManager = federatedAssociationManager; - } else { - throw new Exception("Unable to retrieve FederatedAssociationManager service."); - } - } - return this.federatedAssociationManager; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/RealmServiceOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/RealmServiceOSGIServiceFactory.java deleted file mode 100644 index 7085974b9..000000000 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/RealmServiceOSGIServiceFactory.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.rest.api.user.association.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 RealmServiceOSGIServiceFactory extends AbstractFactoryBean { - - private RealmService realmService; - - @Override - public Class getObjectType() { - - return Object.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 RealmService."); - } - } - return this.realmService; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/UserAccountConnectorOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/UserAccountConnectorOSGIServiceFactory.java deleted file mode 100644 index 3aa3fde31..000000000 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/factory/UserAccountConnectorOSGIServiceFactory.java +++ /dev/null @@ -1,51 +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.rest.api.user.association.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.user.account.association.UserAccountConnector; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the UserAccountConnector type of object inside the container. - */ -public class UserAccountConnectorOSGIServiceFactory extends AbstractFactoryBean { - - private UserAccountConnector userAccountConnector; - - @Override - public Class getObjectType() { - return Object.class; - } - - @Override - protected UserAccountConnector createInstance() throws Exception { - - if (this.userAccountConnector == null) { - UserAccountConnector userAccountConnector = (UserAccountConnector) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(UserAccountConnector.class, null); - if (userAccountConnector != null) { - this.userAccountConnector = userAccountConnector; - } else { - throw new Exception("Unable to retrieve UserAccountConnector service."); - } - } - return this.userAccountConnector; - } - -} diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/core/UserAssociationService.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/core/UserAssociationService.java index c3c10f2b8..dc86700db 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/core/UserAssociationService.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/core/UserAssociationService.java @@ -1,18 +1,21 @@ /* - * 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.user.association.v1.core; import org.apache.commons.lang.StringUtils; @@ -26,18 +29,21 @@ import org.wso2.carbon.identity.rest.api.user.association.v1.dto.FederatedAssociationDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.IdpDTO; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.UserDTO; -import org.wso2.carbon.identity.rest.api.user.association.v1.util.UserAssociationServiceHolder; +import org.wso2.carbon.identity.user.account.association.UserAccountConnector; import org.wso2.carbon.identity.user.account.association.dto.UserAccountAssociationDTO; import org.wso2.carbon.identity.user.account.association.exception.UserAccountAssociationClientException; import org.wso2.carbon.identity.user.account.association.exception.UserAccountAssociationException; +import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager; import org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerClientException; import org.wso2.carbon.identity.user.profile.mgt.association.federation.exception.FederatedAssociationManagerException; import org.wso2.carbon.identity.user.profile.mgt.association.federation.model.FederatedAssociation; +import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.util.UserCoreUtil; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.ArrayList; import java.util.List; + import javax.ws.rs.core.Response; import static org.wso2.carbon.identity.api.user.common.Constants.ERROR_CODE_DELIMITER; @@ -52,11 +58,24 @@ public class UserAssociationService { private static final Log log = LogFactory.getLog(UserAssociationService.class); + private final UserAccountConnector userAccountConnector; + private final FederatedAssociationManager federatedAssociationManager; + private final RealmService realmService; + + public UserAssociationService(UserAccountConnector userAccountConnector, FederatedAssociationManager + federatedAssociationManager, RealmService realmService) { + + this.userAccountConnector = userAccountConnector; + this.federatedAssociationManager = federatedAssociationManager; + this.realmService = realmService; + } + public List getAssociationsOfUser(String userId) { try { - UserAccountAssociationDTO[] accountAssociationsOfUser = UserAssociationServiceHolder - .getUserAccountConnector().getAccountAssociationsOfUser(userId); + UserAccountAssociationDTO[] accountAssociationsOfUser = userAccountConnector + .getAccountAssociationsOfUser(userId); + return getUserAssociationsDTOs(accountAssociationsOfUser); } catch (UserAccountAssociationException e) { throw handleUserAccountAssociationException(e, "Error while getting associations of user: " + userId); @@ -66,8 +85,8 @@ public List getAssociationsOfUser(String userId) { public List getFederatedAssociationsOfUser(String userId) { try { - FederatedAssociation[] federatedAccountAssociationsOfUser = UserAssociationServiceHolder - .getFederatedAssociationManager().getFederatedAssociationsOfUser(getUser(userId)); + FederatedAssociation[] federatedAccountAssociationsOfUser = federatedAssociationManager + .getFederatedAssociationsOfUser(getUser(userId)); return getFederatedAssociationDTOs(federatedAccountAssociationsOfUser); } catch (FederatedAssociationManagerException e) { throw handleFederatedAssociationManagerException(e, "Error while getting associations of user: " + userId); @@ -81,19 +100,18 @@ public void createUserAccountAssociation(AssociationUserRequestDTO associationUs throw new UserAccountAssociationClientException(ERROR_CODE_PW_MANDATORY.getCode(), ERROR_CODE_PW_MANDATORY.getDescription()); } - UserAssociationServiceHolder.getUserAccountConnector() - .createUserAccountAssociation(associationUserRequestDTO.getUserId(), - associationUserRequestDTO.getPassword().toCharArray()); + userAccountConnector.createUserAccountAssociation(associationUserRequestDTO.getUserId(), + associationUserRequestDTO.getPassword().toCharArray()); } catch (UserAccountAssociationException e) { throw handleUserAccountAssociationException(e, "Error while adding associations of user: " + associationUserRequestDTO.getUserId()); } } - public boolean switchLoggedInUser(String userName) { + public boolean switchLoggedInUser(String userName) { try { - return UserAssociationServiceHolder.getUserAccountConnector().switchLoggedInUser(userName); + return userAccountConnector.switchLoggedInUser(userName); } catch (UserAccountAssociationException e) { throw handleUserAccountAssociationException(e, "Error while switching user: " + userName); } @@ -102,7 +120,7 @@ public boolean switchLoggedInUser(String userName) { public void deleteUserAccountAssociation(String userId) { try { - UserAssociationServiceHolder.getUserAccountConnector().deleteUserAccountAssociation(userId); + userAccountConnector.deleteUserAccountAssociation(userId); } catch (UserAccountAssociationException e) { throw handleUserAccountAssociationException(e, "Error while deleting user association: " + userId); } @@ -111,8 +129,7 @@ public void deleteUserAccountAssociation(String userId) { public void deleteAssociatedUserAccount(String ownerUserId, String associatedUserId) { try { - UserAssociationServiceHolder.getUserAccountConnector().deleteAssociatedUserAccount(ownerUserId, - associatedUserId); + userAccountConnector.deleteAssociatedUserAccount(ownerUserId, associatedUserId); } catch (UserAccountAssociationException e) { throw handleUserAccountAssociationException(e, "Error while deleting user association of the user: " + ownerUserId + ", with the user: " + associatedUserId); @@ -122,8 +139,7 @@ public void deleteAssociatedUserAccount(String ownerUserId, String associatedUse public void deleteFederatedUserAccountAssociation(String userId, String federatedAssociationId) { try { - UserAssociationServiceHolder.getFederatedAssociationManager() - .deleteFederatedAssociation(getUser(userId), federatedAssociationId); + federatedAssociationManager.deleteFederatedAssociation(getUser(userId), federatedAssociationId); } catch (FederatedAssociationManagerException e) { throw handleFederatedAssociationManagerException(e, "Error while deleting federated user association: " + userId); @@ -133,7 +149,7 @@ public void deleteFederatedUserAccountAssociation(String userId, String federate public void deleteFederatedUserAccountAssociation(String userId) { try { - UserAssociationServiceHolder.getFederatedAssociationManager().deleteFederatedAssociation(getUser(userId)); + federatedAssociationManager.deleteFederatedAssociation(getUser(userId)); } catch (FederatedAssociationManagerException e) { throw handleFederatedAssociationManagerException(e, "Error while deleting federated user association: " + userId); @@ -281,7 +297,7 @@ private String getUniqueUserId(UserAccountAssociationDTO userAccountAssociationD user.setUserName(userAccountAssociationDTO.getUsername()); user.setUserStoreDomain(userAccountAssociationDTO.getDomain()); user.setTenantDomain(userAccountAssociationDTO.getTenantDomain()); - return new UserToUniqueId().apply(UserAssociationServiceHolder.getRealmService(), user); + return new UserToUniqueId().apply(realmService, user); } private User getUser(String userId) { diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserAssociationServiceFactory.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserAssociationServiceFactory.java new file mode 100644 index 000000000..9ac975a00 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/factories/UserAssociationServiceFactory.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.rest.api.user.association.v1.factories; + +import org.wso2.carbon.identity.rest.api.user.association.v1.core.UserAssociationService; +import org.wso2.carbon.identity.rest.api.user.association.v1.util.UserAssociationServiceHolder; +import org.wso2.carbon.identity.user.account.association.UserAccountConnector; +import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * Factory class for User Association Service. + */ +public class UserAssociationServiceFactory { + + private UserAssociationServiceFactory() { + + } + + private static class UserAssociationServiceManagerHolder { + + private static final UserAssociationService SERVICE = createServiceInstance(); + } + + private static UserAssociationService createServiceInstance() { + + UserAccountConnector userAccountConnector = getUserAccountConnector(); + FederatedAssociationManager federatedAssociationManager = getFederatedAssociationManager(); + RealmService realmService = getRealmService(); + + return new UserAssociationService(userAccountConnector, federatedAssociationManager, realmService); + } + + /** + * Get UserAssociationService instance. + * + * @return UserAssociationService instance. + */ + public static UserAssociationService getUserAssociationService() { + + return UserAssociationServiceManagerHolder.SERVICE; + } + + private static UserAccountConnector getUserAccountConnector() { + + UserAccountConnector service = UserAssociationServiceHolder.getUserAccountConnector(); + if (service == null) { + throw new IllegalStateException("UserAccountConnector is not available from OSGi context."); + } + + return service; + } + + private static FederatedAssociationManager getFederatedAssociationManager() { + + FederatedAssociationManager service = UserAssociationServiceHolder.getFederatedAssociationManager(); + if (service == null) { + throw new IllegalStateException("FederatedAssociationManager is not available from OSGi context."); + } + + return service; + } + + private static RealmService getRealmService() { + + RealmService service = UserAssociationServiceHolder.getRealmService(); + if (service == null) { + throw new IllegalStateException("RealmService is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/MeApiServiceImpl.java index 3c9aae993..c7efa5407 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/MeApiServiceImpl.java @@ -1,6 +1,23 @@ +/* + * 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.rest.api.user.association.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser; import org.wso2.carbon.identity.application.common.model.User; @@ -8,10 +25,12 @@ import org.wso2.carbon.identity.rest.api.user.association.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.association.v1.core.UserAssociationService; import org.wso2.carbon.identity.rest.api.user.association.v1.dto.AssociationUserRequestDTO; +import org.wso2.carbon.identity.rest.api.user.association.v1.factories.UserAssociationServiceFactory; import org.wso2.carbon.identity.rest.api.user.association.v1.util.UserAssociationServiceHolder; import org.wso2.carbon.user.core.util.UserCoreUtil; import java.net.URI; + import javax.ws.rs.core.Response; import static org.wso2.carbon.identity.api.user.common.ContextLoader.buildURIForHeader; @@ -24,8 +43,16 @@ */ public class MeApiServiceImpl extends MeApiService { - @Autowired - private UserAssociationService userAssociationService; + private final UserAssociationService userAssociationService; + + public MeApiServiceImpl() { + + try { + this.userAssociationService = UserAssociationServiceFactory.getUserAssociationService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating UserAssociationService.", e); + } + } @Override public Response meAssociationsDelete() { @@ -44,6 +71,7 @@ public Response meAssociationsAssociatedUserIdDelete(String associatedUserId) { @Override public Response meAssociationsGet() { + return Response.ok().entity(userAssociationService.getAssociationsOfUser( getFullyQualifiedUsernameFromContext())).build(); } diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/UserIdApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/UserIdApiServiceImpl.java index e24bcb400..146bedd48 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/UserIdApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/impl/UserIdApiServiceImpl.java @@ -1,11 +1,29 @@ +/* + * 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.rest.api.user.association.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser; import org.wso2.carbon.identity.application.common.model.User; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.rest.api.user.association.v1.UserIdApiService; import org.wso2.carbon.identity.rest.api.user.association.v1.core.UserAssociationService; +import org.wso2.carbon.identity.rest.api.user.association.v1.factories.UserAssociationServiceFactory; import org.wso2.carbon.identity.rest.api.user.association.v1.util.UserAssociationServiceHolder; import javax.ws.rs.core.Response; @@ -15,8 +33,16 @@ */ public class UserIdApiServiceImpl extends UserIdApiService { - @Autowired - private UserAssociationService userAssociationService; + private final UserAssociationService userAssociationService; + + public UserIdApiServiceImpl() { + + try { + this.userAssociationService = UserAssociationServiceFactory.getUserAssociationService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating UserAssociationService.", e); + } + } @Override public Response userIdAssociationsDelete(String userId) { diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/util/UserAssociationServiceHolder.java b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/util/UserAssociationServiceHolder.java index 726b5d00b..f6857b917 100644 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/util/UserAssociationServiceHolder.java +++ b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/association/v1/util/UserAssociationServiceHolder.java @@ -1,20 +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.user.association.v1.util; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.user.account.association.UserAccountConnector; import org.wso2.carbon.identity.user.profile.mgt.association.federation.FederatedAssociationManager; import org.wso2.carbon.user.core.service.RealmService; @@ -24,37 +28,55 @@ */ public class UserAssociationServiceHolder { - private static UserAccountConnector userAccountConnector; - private static FederatedAssociationManager federatedAssociationManager; - private static RealmService realmService; + private UserAssociationServiceHolder() { - public static FederatedAssociationManager getFederatedAssociationManager() { + } - return federatedAssociationManager; + private static class FederatedAssociationManagerServiceHolder { + + static final FederatedAssociationManager SERVICE = (FederatedAssociationManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(FederatedAssociationManager.class, null); } - public static void setFederatedAssociationManager(FederatedAssociationManager federatedAssociationManager) { + private static class UserAccountConnectorServiceHolder { - UserAssociationServiceHolder.federatedAssociationManager = federatedAssociationManager; + static final UserAccountConnector SERVICE = (UserAccountConnector) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(UserAccountConnector.class, null); } - public static UserAccountConnector getUserAccountConnector() { + private static class RealmServiceHolder { - return userAccountConnector; + static final RealmService SERVICE = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(RealmService.class, null); } - public static void setUserAccountConnector(UserAccountConnector userAccountConnector) { + /** + * Get FederatedAssociationManager OSGi service. + * + * @return FederatedAssociationManager + */ + public static FederatedAssociationManager getFederatedAssociationManager() { - UserAssociationServiceHolder.userAccountConnector = userAccountConnector; + return FederatedAssociationManagerServiceHolder.SERVICE; } - public static RealmService getRealmService() { + /** + * Get UserAccountConnector OSGi service. + * + * @return UserAccountConnector + */ + public static UserAccountConnector getUserAccountConnector() { - return realmService; + return UserAccountConnectorServiceHolder.SERVICE; } - public static void setRealmService(RealmService realmService) { + /** + * Get RealmService OSGi service. + * + * @return RealmService + */ + public static RealmService getRealmService() { - UserAssociationServiceHolder.realmService = realmService; + return RealmServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/resources/META-INF/cxf/user-association-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/resources/META-INF/cxf/user-association-v1-cxf.xml deleted file mode 100644 index c58fdb5cc..000000000 --- a/components/org.wso2.carbon.identity.api.user.association/org.wso2.carbon.identity.api.user.association.v1/src/main/resources/META-INF/cxf/user-association-v1-cxf.xml +++ /dev/null @@ -1,35 +0,0 @@ - - - - - - - - - - - - - - - - From b8cc967590ef850a582979dcbf5dfc05c97758fa Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:14:31 +0530 Subject: [PATCH 05/15] Remove Spring dependency from api.user.authorized.apps --- .../pom.xml | 23 ++-- .../api/user/authorized/apps/v1/MeApi.java | 27 +++-- .../user/authorized/apps/v1/UserIdApi.java | 27 +++-- .../v1/factories/MeApiServiceFactory.java | 28 ++--- .../v1/factories/UserIdApiServiceFactory.java | 28 ++--- .../apps/v1/core/AuthorizedAppsService.java | 32 +++--- .../AuthorizedAppsServiceFactory.java | 65 +++++++++++ .../apps/v1/impl/MeApiServiceImpl.java | 32 ++++-- .../apps/v1/impl/UserIdApiServiceImpl.java | 39 ++++--- .../utils/AuthorizedAppsServicesHolder.java | 73 ++++++++++++ .../cxf/authorized-apps-user-v1-cxf.xml | 22 ---- .../pom.xml | 23 ++-- .../authorized/apps/v2/AuthorizedAppsApi.java | 15 ++- .../api/user/authorized/apps/v2/MeApi.java | 29 +++-- .../user/authorized/apps/v2/UserIdApi.java | 29 +++-- .../AuthorizedAppsApiServiceFactory.java | 17 ++- .../v2/factories/MeApiServiceFactory.java | 36 +++--- .../v2/factories/UserIdApiServiceFactory.java | 28 ++--- .../apps/v2/core/AuthorizedAppsService.java | 33 +++--- .../AuthorizedAppsServiceFactory.java | 92 +++++++++++++++ .../v2/impl/AuthorizedAppsApiServiceImpl.java | 14 ++- .../apps/v2/impl/MeApiServiceImpl.java | 33 ++++-- .../apps/v2/impl/UserIdApiServiceImpl.java | 39 ++++--- .../utils/AuthorizedAppsServicesHolder.java | 107 ++++++++++++++++++ .../cxf/authorized-apps-user-v2-cxf.xml | 23 ---- 25 files changed, 641 insertions(+), 273 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/AuthorizedAppsServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/utils/AuthorizedAppsServicesHolder.java delete mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/resources/META-INF/cxf/authorized-apps-user-v1-cxf.xml create mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/utils/AuthorizedAppsServicesHolder.java delete mode 100644 components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/resources/META-INF/cxf/authorized-apps-user-v2-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/pom.xml index 9ec2d77f9..496b61985 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/pom.xml @@ -1,18 +1,20 @@ 4.0.0 @@ -79,11 +81,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.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/MeApi.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/MeApi.java index 7301d7b4c..a7f263610 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/MeApi.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/MeApi.java @@ -1,22 +1,23 @@ /* - * 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.user.authorized.apps.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.*; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.factories.MeApiServiceFactory; @@ -41,8 +42,12 @@ @io.swagger.annotations.Api(value = "/me", description = "the me API") public class MeApi { - @Autowired - private MeApiService delegate; + private final MeApiService delegate; + + public MeApi() { + + this.delegate = MeApiServiceFactory.getMeApi(); + } @DELETE @Path("/authorized-apps/{application-id}") diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/UserIdApi.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/UserIdApi.java index 8f197ac61..8dfbfbdf4 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/UserIdApi.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/UserIdApi.java @@ -1,22 +1,23 @@ /* - * 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.user.authorized.apps.v1; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.*; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.UserIdApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.factories.UserIdApiServiceFactory; @@ -41,8 +42,12 @@ @io.swagger.annotations.Api(value = "/{user-id}", description = "the {user-id} API") public class UserIdApi { - @Autowired - private UserIdApiService delegate; + private final UserIdApiService delegate; + + public UserIdApi() { + + this.delegate = UserIdApiServiceFactory.getUserIdApi(); + } @DELETE @Path("/authorized-apps") diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/MeApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/MeApiServiceFactory.java index d4f54a53b..10435ff80 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/MeApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/MeApiServiceFactory.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.user.authorized.apps.v1.factories; @@ -21,10 +23,10 @@ public class MeApiServiceFactory { - private final static MeApiService service = new MeApiServiceImpl(); + private final static MeApiService SERVICE = new MeApiServiceImpl(); - public static MeApiService getMeApi() - { - return service; - } + public static MeApiService getMeApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/UserIdApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/UserIdApiServiceFactory.java index bd12a7800..e79b13dfe 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/UserIdApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/UserIdApiServiceFactory.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.user.authorized.apps.v1.factories; @@ -21,10 +23,10 @@ public class UserIdApiServiceFactory { - private final static UserIdApiService service = new UserIdApiServiceImpl(); + private final static UserIdApiService SERVICE = new UserIdApiServiceImpl(); - public static UserIdApiService getUserIdApi() - { - return service; - } + public static UserIdApiService getUserIdApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/core/AuthorizedAppsService.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/core/AuthorizedAppsService.java index 475aafbc2..79838dc97 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/core/AuthorizedAppsService.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/core/AuthorizedAppsService.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.user.authorized.apps.v1.core; @@ -30,7 +32,6 @@ import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.core.functions.OAuthConsumerAppToExternal; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.AuthorizedAppDTO; import org.wso2.carbon.user.core.UserCoreConstants; -import org.wso2.carbon.user.core.service.RealmService; import java.util.Arrays; import java.util.List; @@ -47,14 +48,11 @@ public class AuthorizedAppsService { private static final Log log = LogFactory.getLog(AuthorizedAppsService.class); - private static OAuthAdminServiceImpl oAuthAdminService = null; - private static RealmService realmService = null; - - static { - oAuthAdminService = (OAuthAdminServiceImpl) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(OAuthAdminServiceImpl.class, null); - realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(RealmService.class, null); + private final OAuthAdminServiceImpl oAuthAdminService; + + public AuthorizedAppsService(OAuthAdminServiceImpl oAuthAdminService) { + + this.oAuthAdminService = oAuthAdminService; } public void deleteUserAuthorizedApps(User user) { diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/AuthorizedAppsServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/AuthorizedAppsServiceFactory.java new file mode 100644 index 000000000..554c98b67 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/factories/AuthorizedAppsServiceFactory.java @@ -0,0 +1,65 @@ +/* + * 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.user.authorized.apps.v1.factories; + +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.core.AuthorizedAppsService; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.utils.AuthorizedAppsServicesHolder; + +/** + * This class is responsible for initializing AuthorizedAppsService. + */ +public class AuthorizedAppsServiceFactory { + + private AuthorizedAppsServiceFactory() { + + } + + private static class AuthorizedAppsServiceHolder { + + private static final AuthorizedAppsService SERVICE = createServiceInstance(); + } + + private static AuthorizedAppsService createServiceInstance() { + + OAuthAdminServiceImpl oAuthAdminServiceImpl = getOAuthAdminService(); + + return new AuthorizedAppsService(oAuthAdminServiceImpl); + } + + /** + * Get AuthorizedAppsService + * + * @return AuthorizedAppsService + */ + public static AuthorizedAppsService getAuthorizedAppsService() { + + return AuthorizedAppsServiceHolder.SERVICE; + } + + private static OAuthAdminServiceImpl getOAuthAdminService() { + + OAuthAdminServiceImpl service = AuthorizedAppsServicesHolder.getOAuthAdminService(); + if (service == null) { + throw new IllegalStateException("OAuthAdminServiceImpl is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/MeApiServiceImpl.java index 7f29cfef7..568796c80 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/MeApiServiceImpl.java @@ -1,25 +1,27 @@ /* - * 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.user.authorized.apps.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.MeApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.core.AuthorizedAppsService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.AuthorizedAppDTO; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.factories.AuthorizedAppsServiceFactory; import java.util.List; import javax.ws.rs.core.Response; @@ -31,8 +33,16 @@ */ public class MeApiServiceImpl extends MeApiService { - @Autowired - private AuthorizedAppsService authorizedAppsService; + private final AuthorizedAppsService authorizedAppsService; + + public MeApiServiceImpl() { + + try { + this.authorizedAppsService = AuthorizedAppsServiceFactory.getAuthorizedAppsService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating AuthorizedAppsService.", e); + } + } @Override public Response deleteLoggedInUserAuthorizedAppByAppId(String applicationId) { diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/UserIdApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/UserIdApiServiceImpl.java index 17a1230a7..ebd412c53 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/UserIdApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/impl/UserIdApiServiceImpl.java @@ -1,32 +1,35 @@ /* - * 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.user.authorized.apps.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser; import org.wso2.carbon.identity.application.common.model.User; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.UserIdApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.core.AuthorizedAppsService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.dto.AuthorizedAppDTO; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.factories.AuthorizedAppsServiceFactory; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v1.utils.AuthorizedAppsServicesHolder; import org.wso2.carbon.user.core.service.RealmService; import java.util.List; + import javax.ws.rs.core.Response; /** @@ -34,13 +37,17 @@ */ public class UserIdApiServiceImpl extends UserIdApiService { - @Autowired - private AuthorizedAppsService authorizedAppsService; - private static RealmService realmService = null; + private final AuthorizedAppsService authorizedAppsService; + private final RealmService realmService; + + public UserIdApiServiceImpl() { - static { - realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(RealmService.class, null); + try { + this.authorizedAppsService = AuthorizedAppsServiceFactory.getAuthorizedAppsService(); + this.realmService = AuthorizedAppsServicesHolder.getRealmService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating the authorized app services.", e); + } } @Override diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/utils/AuthorizedAppsServicesHolder.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/utils/AuthorizedAppsServicesHolder.java new file mode 100644 index 000000000..f4c10f2a0 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v1/utils/AuthorizedAppsServicesHolder.java @@ -0,0 +1,73 @@ +/* + * 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.user.authorized.apps.v1.utils; + +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * This class holds the service instances required for authorized apps management. + */ +public class AuthorizedAppsServicesHolder { + + private AuthorizedAppsServicesHolder() { + + } + + private static class OAuthAdminServiceImplServiceHolder { + + static final OAuthAdminServiceImpl SERVICE = (OAuthAdminServiceImpl) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null); + } + + /** + * Get OAuthAdminService + * + * @return OAuthAdminServiceImpl + */ + public static OAuthAdminServiceImpl getOAuthAdminService() { + + return OAuthAdminServiceImplServiceHolder.SERVICE; + } + + private static class RealmServiceHolder { + + static final RealmService SERVICE; + + static { + SERVICE = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(RealmService.class, null); + + if (SERVICE == null) { + throw new IllegalStateException("RealmService is not available from OSGi context."); + } + } + } + + /** + * Get RealmService + * + * @return RealmService + */ + public static RealmService getRealmService() { + + return RealmServiceHolder.SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/resources/META-INF/cxf/authorized-apps-user-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/resources/META-INF/cxf/authorized-apps-user-v1-cxf.xml deleted file mode 100644 index 290abefe5..000000000 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v1/src/main/resources/META-INF/cxf/authorized-apps-user-v1-cxf.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/pom.xml b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/pom.xml index 1d99ae84c..360bcf29a 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/pom.xml @@ -1,18 +1,20 @@ @@ -103,11 +105,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.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/AuthorizedAppsApi.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/AuthorizedAppsApi.java index f0c6207c7..0d0539370 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/AuthorizedAppsApi.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/AuthorizedAppsApi.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache 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 @@ -18,19 +18,18 @@ package org.wso2.carbon.identity.rest.api.user.authorized.apps.v2; -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.rest.api.user.authorized.apps.v2.dto.ErrorDTO; -import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.AuthorizedAppsApiService; import javax.validation.Valid; import javax.ws.rs.*; import javax.ws.rs.core.Response; import io.swagger.annotations.*; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.AuthorizedAppsApiServiceFactory; import javax.validation.constraints.*; @@ -39,8 +38,12 @@ public class AuthorizedAppsApi { - @Autowired - private AuthorizedAppsApiService delegate; + private final AuthorizedAppsApiService delegate; + + protected AuthorizedAppsApi() { + + this.delegate = AuthorizedAppsApiServiceFactory.getAuthorizedAppsApi(); + } @Valid @DELETE diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/MeApi.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/MeApi.java index 6e0cf2da1..c855dcd9e 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/MeApi.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/MeApi.java @@ -1,22 +1,23 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2; -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; @@ -24,12 +25,12 @@ import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.AuthorizedAppDTO; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.ErrorDTO; -import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.MeApiService; import javax.validation.Valid; import javax.ws.rs.*; import javax.ws.rs.core.Response; import io.swagger.annotations.*; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.MeApiServiceFactory; import javax.validation.constraints.*; @@ -38,8 +39,12 @@ public class MeApi { - @Autowired - private MeApiService delegate; + private final MeApiService delegate; + + public MeApi() { + + this.delegate = MeApiServiceFactory.getMeApi(); + } @Valid @DELETE diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/UserIdApi.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/UserIdApi.java index 6aad89a1e..37b69d630 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/UserIdApi.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/UserIdApi.java @@ -1,23 +1,23 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2; -import org.springframework.beans.factory.annotation.Autowired; - import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.AuthorizedAppDTO; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.ErrorDTO; @@ -25,14 +25,19 @@ import javax.ws.rs.*; import javax.ws.rs.core.Response; import io.swagger.annotations.*; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.UserIdApiServiceFactory; @Path("/{user-id}") @Api(description = "The {user-id} API") public class UserIdApi { - @Autowired - private UserIdApiService delegate; + private final UserIdApiService delegate; + + public UserIdApi() { + + this.delegate = UserIdApiServiceFactory.getUserIdApi(); + } @Valid @DELETE diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsApiServiceFactory.java index 30a50e5c9..514b662b8 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsApiServiceFactory.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache 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 @@ -21,11 +21,20 @@ import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.AuthorizedAppsApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.impl.AuthorizedAppsApiServiceImpl; +/** + * Factory class for AuthorizedAppsApiService. + */ public class AuthorizedAppsApiServiceFactory { - private final static AuthorizedAppsApiService service = new AuthorizedAppsApiServiceImpl(); + private final static AuthorizedAppsApiService SERVICE = new AuthorizedAppsApiServiceImpl(); + /** + * Get AuthorizedAppsApiService + * + * @return AuthorizedAppsApiService + */ public static AuthorizedAppsApiService getAuthorizedAppsApi() { - return service; + + return SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/MeApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/MeApiServiceFactory.java index eab6b72c6..2a5de047d 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/MeApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/MeApiServiceFactory.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2.factories; @@ -19,12 +21,20 @@ import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.MeApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.impl.MeApiServiceImpl; +/** + * Factory class for MeApiService. + */ public class MeApiServiceFactory { - private final static MeApiService service = new MeApiServiceImpl(); + private final static MeApiService SERVICE = new MeApiServiceImpl(); + + /** + * Get MeApiService + * + * @return MeApiService + */ + public static MeApiService getMeApi() { - public static MeApiService getMeApi() - { - return service; - } + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/UserIdApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/UserIdApiServiceFactory.java index b388cb5a4..e247c691f 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/UserIdApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/gen/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/UserIdApiServiceFactory.java @@ -1,17 +1,19 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2.factories; @@ -21,10 +23,10 @@ public class UserIdApiServiceFactory { - private final static UserIdApiService service = new UserIdApiServiceImpl(); + private final static UserIdApiService SERVICE = new UserIdApiServiceImpl(); - public static UserIdApiService getUserIdApi() - { - return service; - } + public static UserIdApiService getUserIdApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/core/AuthorizedAppsService.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/core/AuthorizedAppsService.java index 8f30a855b..1062e73fc 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/core/AuthorizedAppsService.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/core/AuthorizedAppsService.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache 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 @@ -67,21 +67,20 @@ public class AuthorizedAppsService { private static final Log log = LogFactory.getLog(AuthorizedAppsService.class); private static final String OAUTH2 = "oauth2"; - private static final ApplicationManagementService applicationManagementService; - private static final OAuthAdminServiceImpl oAuthAdminService; - private static final OAuth2ScopeService oAuth2ScopeService; - private static final RealmService realmService; - - - static { - applicationManagementService = (ApplicationManagementService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null); - oAuthAdminService = (OAuthAdminServiceImpl) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(OAuthAdminServiceImpl.class, null); - oAuth2ScopeService = (OAuth2ScopeService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(OAuth2ScopeService.class, null); - realmService = (RealmService) PrivilegedCarbonContext. - getThreadLocalCarbonContext().getOSGiService(RealmService.class, null); + private final ApplicationManagementService applicationManagementService; + private final OAuthAdminServiceImpl oAuthAdminService; + private final OAuth2ScopeService oAuth2ScopeService; + private final RealmService realmService; + + public AuthorizedAppsService(ApplicationManagementService applicationManagementService, + OAuthAdminServiceImpl oAuthAdminService, + OAuth2ScopeService oAuth2ScopeService, + RealmService realmService) { + + this.applicationManagementService = applicationManagementService; + this.oAuthAdminService = oAuthAdminService; + this.oAuth2ScopeService = oAuth2ScopeService; + this.realmService = realmService; } /** diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsServiceFactory.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsServiceFactory.java new file mode 100644 index 000000000..3665b4679 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/factories/AuthorizedAppsServiceFactory.java @@ -0,0 +1,92 @@ +/* + * 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.user.authorized.apps.v2.factories; + +import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; +import org.wso2.carbon.identity.oauth2.OAuth2ScopeService; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.core.AuthorizedAppsService; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.utils.AuthorizedAppsServicesHolder; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * This class is responsible for initializing AuthorizedAppsService. + */ +public class AuthorizedAppsServiceFactory { + + private AuthorizedAppsServiceFactory() { + + } + + private static class AuthorizedAppsServiceHolder { + + private static final AuthorizedAppsService SERVICE = createServiceInstance(); + } + + private static AuthorizedAppsService createServiceInstance() { + + ApplicationManagementService applicationManagementService = getApplicationManagementService(); + OAuthAdminServiceImpl oAuthAdminServiceImpl = getOAuthAdminService(); + OAuth2ScopeService oAuth2ScopeService = getOAuth2ScopeService(); + RealmService realmService = AuthorizedAppsServicesHolder.getRealmService(); + + return new AuthorizedAppsService(applicationManagementService, oAuthAdminServiceImpl, + oAuth2ScopeService, realmService); + } + + /** + * Get AuthorizedAppsService + * + * @return AuthorizedAppsService + */ + public static AuthorizedAppsService getAuthorizedAppsService() { + + return AuthorizedAppsServiceHolder.SERVICE; + } + + private static ApplicationManagementService getApplicationManagementService() { + + ApplicationManagementService service = AuthorizedAppsServicesHolder.getApplicationManagementService(); + if (service == null) { + throw new IllegalStateException("ApplicationManagementService is not available from OSGi context."); + } + + return service; + } + + private static OAuthAdminServiceImpl getOAuthAdminService() { + + OAuthAdminServiceImpl service = AuthorizedAppsServicesHolder.getOAuthAdminService(); + if (service == null) { + throw new IllegalStateException("OAuthAdminServiceImpl is not available from OSGi context."); + } + + return service; + } + + private static OAuth2ScopeService getOAuth2ScopeService() { + + OAuth2ScopeService service = AuthorizedAppsServicesHolder.getOAuth2ScopeService(); + if (service == null) { + throw new IllegalStateException("OAuth2ScopeService is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/AuthorizedAppsApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/AuthorizedAppsApiServiceImpl.java index 4f2eb0fa9..44e373cdb 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/AuthorizedAppsApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/AuthorizedAppsApiServiceImpl.java @@ -1,7 +1,7 @@ /* - * Copyright (c) 2021, WSO2 Inc. (http://www.wso2.com). + * Copyright (c) 2021-2024, WSO2 LLC. (http://www.wso2.com). * - * WSO2 Inc. licenses this file to you under the Apache 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 @@ -18,9 +18,9 @@ package org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.AuthorizedAppsApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.core.AuthorizedAppsService; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.AuthorizedAppsServiceFactory; import javax.ws.rs.core.Response; @@ -29,8 +29,12 @@ */ public class AuthorizedAppsApiServiceImpl implements AuthorizedAppsApiService { - @Autowired - private AuthorizedAppsService authorizedAppsService; + private final AuthorizedAppsService authorizedAppsService; + + public AuthorizedAppsApiServiceImpl() { + + this.authorizedAppsService = AuthorizedAppsServiceFactory.getAuthorizedAppsService(); + } @Override public Response deleteIssuedTokensByAppId(String applicationId) { diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/MeApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/MeApiServiceImpl.java index 201f512fc..e78d2d319 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/MeApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/MeApiServiceImpl.java @@ -1,26 +1,27 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2.impl; -import org.springframework.beans.factory.annotation.Autowired; - import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.MeApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.core.AuthorizedAppsService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.AuthorizedAppDTO; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.AuthorizedAppsServiceFactory; import java.util.List; @@ -33,8 +34,16 @@ */ public class MeApiServiceImpl implements MeApiService { - @Autowired - private AuthorizedAppsService authorizedAppsService; + private final AuthorizedAppsService authorizedAppsService; + + public MeApiServiceImpl() { + + try { + this.authorizedAppsService = AuthorizedAppsServiceFactory.getAuthorizedAppsService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating AuthorizedAppsService.", e); + } + } @Override public Response deleteLoggedInUserAuthorizedAppByAppId(String applicationId) { diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/UserIdApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/UserIdApiServiceImpl.java index 23974d1da..8ab865862 100644 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/UserIdApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/impl/UserIdApiServiceImpl.java @@ -1,29 +1,31 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.authorized.apps.v2.impl; -import org.springframework.beans.factory.annotation.Autowired; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.function.UniqueIdToUser; import org.wso2.carbon.identity.application.common.model.User; import org.wso2.carbon.identity.core.util.IdentityTenantUtil; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.UserIdApiService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.core.AuthorizedAppsService; import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.dto.AuthorizedAppDTO; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.factories.AuthorizedAppsServiceFactory; +import org.wso2.carbon.identity.rest.api.user.authorized.apps.v2.utils.AuthorizedAppsServicesHolder; import org.wso2.carbon.user.core.service.RealmService; import java.util.List; @@ -35,13 +37,18 @@ */ public class UserIdApiServiceImpl implements UserIdApiService { - @Autowired - private AuthorizedAppsService authorizedAppsService; - private static RealmService realmService = null; + private final AuthorizedAppsService authorizedAppsService; + private final RealmService realmService; - static { - realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(RealmService.class, null); + public UserIdApiServiceImpl() { + + try { + this.authorizedAppsService = AuthorizedAppsServiceFactory.getAuthorizedAppsService(); + this.realmService = AuthorizedAppsServicesHolder.getRealmService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating required services " + + "for UserIdApiServiceImpl.", e); + } } @Override diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/utils/AuthorizedAppsServicesHolder.java b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/utils/AuthorizedAppsServicesHolder.java new file mode 100644 index 000000000..de8fca014 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/authorized/apps/v2/utils/AuthorizedAppsServicesHolder.java @@ -0,0 +1,107 @@ +/* + * 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.user.authorized.apps.v2.utils; + +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.identity.application.mgt.ApplicationManagementService; +import org.wso2.carbon.identity.oauth.OAuthAdminServiceImpl; +import org.wso2.carbon.identity.oauth2.OAuth2ScopeService; +import org.wso2.carbon.user.core.service.RealmService; + +/** + * This class holds the service instances required for authorized apps management. + */ +public class AuthorizedAppsServicesHolder { + + private AuthorizedAppsServicesHolder() { + + } + + private static class ApplicationManagementServiceHolder { + + static final ApplicationManagementService SERVICE = (ApplicationManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null); + } + + private static class OAuthAdminServiceImplServiceHolder { + + static final OAuthAdminServiceImpl SERVICE = (OAuthAdminServiceImpl) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null); + } + + private static class OAuth2ScopeServiceHolder { + + static final OAuth2ScopeService SERVICE = (OAuth2ScopeService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OAuth2ScopeService.class, null); + } + + private static class RealmServiceHolder { + + static final RealmService SERVICE; + + static { + SERVICE = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext() + .getOSGiService(RealmService.class, null); + + if (SERVICE == null) { + throw new IllegalStateException("RealmService is not available from OSGi context."); + } + } + } + + /** + * Get OAuth2ScopeService + * + * @return OAuth2ScopeService + */ + public static ApplicationManagementService getApplicationManagementService() { + + return ApplicationManagementServiceHolder.SERVICE; + } + + /** + * Get OAuthAdminService + * + * @return OAuthAdminServiceImpl + */ + public static OAuthAdminServiceImpl getOAuthAdminService() { + + return OAuthAdminServiceImplServiceHolder.SERVICE; + } + + /** + * Get OAuth2ScopeService + * + * @return OAuth2ScopeService + */ + public static OAuth2ScopeService getOAuth2ScopeService() { + + return OAuth2ScopeServiceHolder.SERVICE; + } + + /** + * Get RealmService + * + * @return RealmService + */ + public static RealmService getRealmService() { + + return RealmServiceHolder.SERVICE; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/resources/META-INF/cxf/authorized-apps-user-v2-cxf.xml b/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/resources/META-INF/cxf/authorized-apps-user-v2-cxf.xml deleted file mode 100644 index 21fccc568..000000000 --- a/components/org.wso2.carbon.identity.api.user.authorized.apps/org.wso2.carbon.identity.rest.api.user.authorized.apps.v2/src/main/resources/META-INF/cxf/authorized-apps-user-v2-cxf.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - - - - From 0b4fc56fce4ad547dbf933fcc73a02091e15b373 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:15:32 +0530 Subject: [PATCH 06/15] Remove Spring dependency from api.user.backupcode --- .../pom.xml | 9 +---- .../pom.xml | 9 +---- .../rest/api/user/backupcode/v1/MeApi.java | 28 +++++++------ .../v1/factories/MeApiServiceFactory.java | 27 ++++++++----- .../factories/BackupCodeServiceFactory.java | 39 +++++++++++++++++++ .../backupcode/v1/impl/MeApiServiceImpl.java | 29 ++++++++------ .../META-INF/cxf/user-backupcode-v1-cxf.xml | 21 ---------- 7 files changed, 95 insertions(+), 67 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/backupcode/v1/factories/BackupCodeServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.v1/src/main/resources/META-INF/cxf/user-backupcode-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.common/pom.xml b/components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.common/pom.xml index da8944ae7..2cee13d82 100644 --- a/components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.backupcode/org.wso2.carbon.identity.api.user.backupcode.common/pom.xml @@ -1,8 +1,8 @@ - - - - - From de05888410c010fabc302ecfc8e82fe53a61012a Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:15:52 +0530 Subject: [PATCH 07/15] Remove Spring dependency from api.user.common --- .../org.wso2.carbon.identity.api.user.common/pom.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/components/org.wso2.carbon.identity.api.user.common/pom.xml b/components/org.wso2.carbon.identity.api.user.common/pom.xml index 886aaab71..e19025dfc 100644 --- a/components/org.wso2.carbon.identity.api.user.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.common/pom.xml @@ -1,6 +1,6 @@ - - - - - From e9f2333ad3181d6c286586d505ef212193e613f2 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:25:01 +0530 Subject: [PATCH 09/15] Remove Spring dependency from api.user.functionality --- .../pom.xml | 9 +-- .../UserFunctionalityServiceHolder.java | 40 +++++----- .../RealmServiceOSGIServiceFactory.java | 54 ------------- ...serFunctionalityMgtOSGIServiceFactory.java | 53 ------------- .../pom.xml | 9 +-- .../rest/api/user/functionality/v1/MeApi.java | 41 +++++----- .../api/user/functionality/v1/UserIdApi.java | 15 ++-- .../v1/factories/MeApiServiceFactory.java | 48 +++++++----- .../v1/factories/UserIdApiServiceFactory.java | 22 ++++-- .../v1/core/UserFunctionalityService.java | 32 ++++---- .../UserFunctionalityServiceFactory.java | 77 +++++++++++++++++++ .../v1/impl/MeApiServiceImpl.java | 45 +++++++---- .../v1/impl/UserIdApiServiceImpl.java | 19 +++-- .../cxf/user-functionality-v1-cxf.xml | 33 -------- 14 files changed, 236 insertions(+), 261 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/src/main/java/org/wso2/carbon/identity/api/user/functionality/common/factory/RealmServiceOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/src/main/java/org/wso2/carbon/identity/api/user/functionality/common/factory/UserFunctionalityMgtOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.rest.api.user.functionality.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/functionality/v1/factories/UserFunctionalityServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.rest.api.user.functionality.v1/src/main/resources/META-INF/cxf/user-functionality-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/pom.xml b/components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/pom.xml index df30dbef7..dcdbd55b7 100644 --- a/components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.functionality/org.wso2.carbon.identity.api.user.functionality.common/pom.xml @@ -1,8 +1,8 @@ - - - - - - - - - - - - From d561c3307014ae0b8e609eaabb826c0a6412fa09 Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:27:08 +0530 Subject: [PATCH 10/15] Remove Spring dependency from api.user.idv --- .../pom.xml | 7 +- .../IdentityVerificationServiceHolder.java | 38 +++++------ ...dentityVerificationManagerOSGIFactory.java | 55 ---------------- .../pom.xml | 7 +- .../rest/api/user/idv/v1/DefaultApi.java | 13 ++-- .../identity/rest/api/user/idv/v1/MeApi.java | 13 ++-- .../factories/DefaultApiServiceFactory.java | 20 ++++-- .../idv/v1/factories/MeApiServiceFactory.java | 20 ++++-- .../v1/core/IdentityVerificationService.java | 37 ++++++----- .../IdentityVerificationServiceFactory.java | 65 +++++++++++++++++++ .../idv/v1/impl/DefaultApiServiceImpl.java | 17 +++-- .../user/idv/v1/impl/MeApiServiceImpl.java | 18 +++-- .../resources/META-INF/cxf/idv-v1-cxf.xml | 29 --------- 13 files changed, 175 insertions(+), 164 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.common/src/main/java/org/wso2/carbon/identity/api/user/idv/common/factory/IdentityVerificationManagerOSGIFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/idv/v1/factories/IdentityVerificationServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.v1/src/main/resources/META-INF/cxf/idv-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.common/pom.xml b/components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.common/pom.xml index e220f14f3..5d2e6c9f9 100644 --- a/components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.idv/org.wso2.carbon.identity.api.user.idv.common/pom.xml @@ -1,6 +1,6 @@ - - - - - - - - - - From 7061f1cdaa3b6dea0bccd9fb8d223c42e846f24a Mon Sep 17 00:00:00 2001 From: lashinie Date: Fri, 10 Jan 2025 17:27:43 +0530 Subject: [PATCH 11/15] Remove Spring dependency from api.user.mfa --- .../pom.xml | 9 +-- .../pom.xml | 9 +-- .../identity/rest/api/user/mfa/v1/MeApi.java | 27 ++++---- .../mfa/v1/factories/MeApiServiceFactory.java | 33 ++++++---- .../RealmServiceOSGIServiceFactory.java | 52 --------------- .../rest/api/user/mfa/v1/core/MFAService.java | 37 ++++++----- .../mfa/v1/factories/MFAServiceFactory.java | 65 +++++++++++++++++++ .../user/mfa/v1/impl/MeApiServiceImpl.java | 33 ++++++---- .../mfa/v1/util/UserMFAServiceHolder.java | 41 ++++++------ .../META-INF/cxf/user-mfa-v1-cxf.xml | 28 -------- 10 files changed, 169 insertions(+), 165 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/mfa/factory/RealmServiceOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/mfa/v1/factories/MFAServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.v1/src/main/resources/META-INF/cxf/user-mfa-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.common/pom.xml b/components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.common/pom.xml index 0ec043ce2..660738394 100644 --- a/components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.mfa/org.wso2.carbon.identity.api.user.mfa.common/pom.xml @@ -1,8 +1,8 @@ - - - - - - - - - From bf4d7bd1ac2f0bf3a3e7a67ea7e3c19817143b50 Mon Sep 17 00:00:00 2001 From: lashinie Date: Sat, 11 Jan 2025 07:43:34 +0530 Subject: [PATCH 12/15] Remove Spring dependency from api.user.onboard --- .../pom.xml | 42 +++++------- .../common/UserOnboardServiceDataHolder.java | 24 ++++--- .../common/factory/OSGIServiceFactory.java | 56 ---------------- .../pom.xml | 37 +++++------ .../user/onboard/v1/OfflineInviteLinkApi.java | 13 ++-- .../OfflineInviteLinkApiServiceFactory.java | 16 +++-- .../OfflineInviteLinkServiceFactory.java | 65 +++++++++++++++++++ .../impl/OfflineInviteLinkApiServiceImpl.java | 18 ++--- .../v1/service/OfflineInviteLinkService.java | 14 ++-- .../cxf/user-onboard-management-cxf.xml | 15 ----- 10 files changed, 151 insertions(+), 149 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/factory/OSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/resources/META-INF/cxf/user-onboard-management-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/pom.xml b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/pom.xml index 82379a397..6d7bc62be 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/pom.xml @@ -1,21 +1,21 @@ + ~ Copyright (c) 2023-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. + --> @@ -32,11 +32,6 @@ jar - - org.springframework - spring-web - provided - org.wso2.carbon org.wso2.carbon.core @@ -52,11 +47,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.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/UserOnboardServiceDataHolder.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/UserOnboardServiceDataHolder.java index 5f4a8630a..8a609bc09 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/UserOnboardServiceDataHolder.java +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/UserOnboardServiceDataHolder.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-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,25 +18,31 @@ package org.wso2.carbon.identity.api.user.onboard.common; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.user.onboard.core.service.UserOnboardCoreService; /** * Service holder class for User onboard service. - * - * Note: This date holder is populated through Spring Factory beans. Hence there is no setter references visible. Please - * check the cxf xml related to the user rest service inside META-INF/cxf folder for setter references. */ public class UserOnboardServiceDataHolder { - private static UserOnboardCoreService userOnboardCoreService; + private UserOnboardServiceDataHolder() { - public static UserOnboardCoreService getUserOnboardCoreService() { + } - return userOnboardCoreService; + private static class UserOnboardCoreServiceHolder { + + static final UserOnboardCoreService SERVICE = (UserOnboardCoreService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(UserOnboardCoreService.class, null); } - public static void setUserOnboardCoreService(UserOnboardCoreService userOnboardCoreService) { + /** + * Get UserOnboardCoreService OSGi service. + * + * @return UserOnboardCoreService + */ + public static UserOnboardCoreService getUserOnboardCoreService() { - UserOnboardServiceDataHolder.userOnboardCoreService = userOnboardCoreService; + return UserOnboardCoreServiceHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/factory/OSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/factory/OSGIServiceFactory.java deleted file mode 100644 index 1ca6b3a45..000000000 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.common/src/main/java/org/wso2/carbon/identity/api/user/onboard/common/factory/OSGIServiceFactory.java +++ /dev/null @@ -1,56 +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.user.onboard.common.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.lang.NonNull; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.user.onboard.core.service.UserOnboardCoreService; - -/** - * Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to - * instantiate the UserOnboardCoreService type of object inside the container. - */ -public class OSGIServiceFactory extends AbstractFactoryBean { - - private UserOnboardCoreService userOnboardCoreService; - - @Override - public Class getObjectType() { - - return UserOnboardCoreService.class; - } - - @Override - @NonNull - protected UserOnboardCoreService createInstance() throws Exception { - - if (this.userOnboardCoreService == null) { - UserOnboardCoreService userOnboardCoreService = (UserOnboardCoreService) - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .getOSGiService(UserOnboardCoreService.class, null); - if (userOnboardCoreService != null) { - this.userOnboardCoreService = userOnboardCoreService; - } else { - throw new Exception("Unable to retrieve GuestUserManagementService service."); - } - } - return this.userOnboardCoreService; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/pom.xml index 424273997..ec0e13aa5 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/pom.xml @@ -1,21 +1,21 @@ + ~ Copyright (c) 2023-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. + --> @@ -108,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.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/OfflineInviteLinkApi.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/OfflineInviteLinkApi.java index 606472246..2e712a89d 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/OfflineInviteLinkApi.java +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/OfflineInviteLinkApi.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-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 @@ -25,8 +25,7 @@ import io.swagger.annotations.ApiResponses; import io.swagger.annotations.Authorization; -import org.springframework.beans.factory.annotation.Autowired; - +import org.wso2.carbon.identity.api.user.onboard.v1.factories.OfflineInviteLinkApiServiceFactory; import org.wso2.carbon.identity.api.user.onboard.v1.model.Error; import org.wso2.carbon.identity.api.user.onboard.v1.model.InvitationRequest; @@ -45,8 +44,12 @@ public class OfflineInviteLinkApi { - @Autowired - private OfflineInviteLinkApiService delegate; + private final OfflineInviteLinkApiService delegate; + + public OfflineInviteLinkApi() { + + this.delegate = OfflineInviteLinkApiServiceFactory.getOfflineInviteLinkApi(); + } @Valid @POST diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkApiServiceFactory.java index df7e3d30a..4d73b17bd 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/gen/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkApiServiceFactory.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-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 @@ -26,9 +26,15 @@ */ public class OfflineInviteLinkApiServiceFactory { - private static final OfflineInviteLinkApiService service = new OfflineInviteLinkApiServiceImpl(); + private static final OfflineInviteLinkApiService SERVICE = new OfflineInviteLinkApiServiceImpl(); - public static OfflineInviteLinkApiService getOfflineInviteLinkApi() { - return service; - } + /** + * Get OfflineInviteLinkApiService. + * + * @return OfflineInviteLinkApiService + */ + public static OfflineInviteLinkApiService getOfflineInviteLinkApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkServiceFactory.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkServiceFactory.java new file mode 100644 index 000000000..4ec9e4acc --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/factories/OfflineInviteLinkServiceFactory.java @@ -0,0 +1,65 @@ +/* + * 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.user.onboard.v1.factories; + +import org.wso2.carbon.identity.api.user.onboard.common.UserOnboardServiceDataHolder; +import org.wso2.carbon.identity.api.user.onboard.v1.service.OfflineInviteLinkService; +import org.wso2.carbon.identity.user.onboard.core.service.UserOnboardCoreService; + +/** + * Factory class for OfflineInviteLinkService. + */ +public class OfflineInviteLinkServiceFactory { + + private OfflineInviteLinkServiceFactory() { + + } + + private static class OfflineInviteLinkServicesHolder { + + private static final OfflineInviteLinkService SERVICE = createServiceInstance(); + } + + private static OfflineInviteLinkService createServiceInstance() { + + UserOnboardCoreService userOnboardCoreService = getUserOnboardCoreService(); + + return new OfflineInviteLinkService(userOnboardCoreService); + } + + /** + * Get OfflineInviteLinkService. + * + * @return OfflineInviteLinkService + */ + public static OfflineInviteLinkService getOfflineInviteLinkService() { + + return OfflineInviteLinkServicesHolder.SERVICE; + } + + private static UserOnboardCoreService getUserOnboardCoreService() { + + UserOnboardCoreService service = UserOnboardServiceDataHolder.getUserOnboardCoreService(); + if (service == null) { + throw new IllegalStateException("UserOnboardCoreService is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/impl/OfflineInviteLinkApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/impl/OfflineInviteLinkApiServiceImpl.java index bdc7c5a1b..265b7ff81 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/impl/OfflineInviteLinkApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/impl/OfflineInviteLinkApiServiceImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-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 @@ -20,8 +20,8 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.api.user.onboard.v1.OfflineInviteLinkApiService; +import org.wso2.carbon.identity.api.user.onboard.v1.factories.OfflineInviteLinkServiceFactory; import org.wso2.carbon.identity.api.user.onboard.v1.model.InvitationRequest; import org.wso2.carbon.identity.api.user.onboard.v1.service.OfflineInviteLinkService; @@ -35,14 +35,16 @@ public class OfflineInviteLinkApiServiceImpl implements OfflineInviteLinkApiService { private static final Log LOG = LogFactory.getLog(OfflineInviteLinkApiServiceImpl.class); - @Autowired - private OfflineInviteLinkService offlineInviteLinkService; + private final OfflineInviteLinkService offlineInviteLinkService; - /** - * Creates UsersApiServiceImpl. - */ public OfflineInviteLinkApiServiceImpl() { - super(); + + try { + this.offlineInviteLinkService = OfflineInviteLinkServiceFactory.getOfflineInviteLinkService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating required services for " + + "OfflineInviteLinkService.", e); + } } @Override diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/service/OfflineInviteLinkService.java b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/service/OfflineInviteLinkService.java index 7a3c3c1ef..571a85e3d 100644 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/service/OfflineInviteLinkService.java +++ b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/java/org/wso2/carbon/identity/api/user/onboard/v1/service/OfflineInviteLinkService.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023, WSO2 LLC. (http://www.wso2.com). + * Copyright (c) 2023-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 @@ -31,6 +31,7 @@ import org.wso2.carbon.identity.recovery.IdentityRecoveryClientException; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; import org.wso2.carbon.identity.recovery.IdentityRecoveryException; +import org.wso2.carbon.identity.user.onboard.core.service.UserOnboardCoreService; import org.wso2.carbon.identity.user.onboard.core.service.model.Configuration; import java.util.Arrays; @@ -38,13 +39,13 @@ import javax.ws.rs.core.Response; -import static org.wso2.carbon.identity.api.user.onboard.common.UserOnboardServiceDataHolder.getUserOnboardCoreService; - /** * This class provides the implementation of the OfflineInviteLinkService. */ public class OfflineInviteLinkService { + private final UserOnboardCoreService userOnboardCoreService; + public static final String AUTH_USER_TENANT_DOMAIN = "authUserTenantDomain"; private static final Log LOG = LogFactory.getLog(OfflineInviteLinkService.class); @@ -59,6 +60,11 @@ public class OfflineInviteLinkService { ); + public OfflineInviteLinkService(UserOnboardCoreService userOnboardCoreService) { + + this.userOnboardCoreService = userOnboardCoreService; + } + /** * This method generates the password reset URL. * @@ -70,7 +76,7 @@ public String generatePasswordURL(InvitationRequest invitationRequest) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); Configuration configuration = prepareConfigObject(invitationRequest, tenantDomain); try { - return getUserOnboardCoreService().generatePasswordResetLink(configuration); + return userOnboardCoreService.generatePasswordResetLink(configuration); } catch (IdentityRecoveryException e) { throw handleException(e, Constants.ErrorMessages.ERROR_UNABLE_TO_GENERATE_INVITE_LINK, invitationRequest.getUsername()); diff --git a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/resources/META-INF/cxf/user-onboard-management-cxf.xml b/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/resources/META-INF/cxf/user-onboard-management-cxf.xml deleted file mode 100644 index a034e2d18..000000000 --- a/components/org.wso2.carbon.identity.api.user.onboard/org.wso2.carbon.identity.api.user.onboard.v1/src/main/resources/META-INF/cxf/user-onboard-management-cxf.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - From 648930469f3dea5e6e08dd94a4d189bf56c65fcf Mon Sep 17 00:00:00 2001 From: lashinie Date: Sat, 11 Jan 2025 07:47:02 +0530 Subject: [PATCH 13/15] Remove Spring dependency from api.user.recovery --- .../pom.xml | 23 +++---- .../UserAccountRecoveryServiceDataHolder.java | 60 ++++++++--------- ...wordRecoveryManagerOSGIServiceFactory.java | 49 -------------- ...nameRecoveryManagerOSGIServiceFactory.java | 49 -------------- .../pom.xml | 23 +++---- .../api/user/recovery/v1/RecoveryApi.java | 41 +++++++----- .../factories/RecoveryApiServiceFactory.java | 48 ++++++++------ .../v1/impl/RecoveryApiServiceImpl.java | 37 +++++++---- .../v1/impl/core/PasswordRecoveryService.java | 50 +++++++------- .../v1/impl/core/UsernameRecoveryService.java | 38 ++++++----- .../PasswordRecoveryServiceFactory.java | 65 +++++++++++++++++++ .../UsernameRecoveryServiceFactory.java | 65 +++++++++++++++++++ .../META-INF/cxf/user-recovery-v1-cxf.xml | 31 --------- .../pom.xml | 7 +- .../api/user/recovery/v2/RecoveryApi.java | 13 ++-- .../factories/RecoveryApiServiceFactory.java | 20 ++++-- .../v2/impl/RecoveryApiServiceImpl.java | 21 ++++-- .../v2/impl/core/PasswordRecoveryService.java | 40 ++++++------ .../v2/impl/core/UsernameRecoveryService.java | 21 +++--- .../PasswordRecoveryServiceFactory.java | 65 +++++++++++++++++++ .../UsernameRecoveryServiceFactory.java | 65 +++++++++++++++++++ .../META-INF/cxf/user-recovery-v2-cxf.xml | 33 ---------- 22 files changed, 506 insertions(+), 358 deletions(-) delete mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/PasswordRecoveryManagerOSGIServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/UsernameRecoveryManagerOSGIServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/PasswordRecoveryServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/UsernameRecoveryServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/resources/META-INF/cxf/user-recovery-v1-cxf.xml create mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v2/impl/factories/PasswordRecoveryServiceFactory.java create mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v2/impl/factories/UsernameRecoveryServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/src/main/resources/META-INF/cxf/user-recovery-v2-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/pom.xml b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/pom.xml index e7baf66f3..6f003a2f3 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/pom.xml @@ -1,18 +1,20 @@ @@ -40,11 +42,6 @@ - - org.springframework - spring-web - provided - org.wso2.carbon.identity.governance org.wso2.carbon.identity.recovery diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/UserAccountRecoveryServiceDataHolder.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/UserAccountRecoveryServiceDataHolder.java index a2b9ef226..29a4d9b8a 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/UserAccountRecoveryServiceDataHolder.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/UserAccountRecoveryServiceDataHolder.java @@ -1,20 +1,24 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.recovery.commons; +import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.recovery.services.password.PasswordRecoveryManager; import org.wso2.carbon.identity.recovery.services.username.UsernameRecoveryManager; @@ -23,47 +27,39 @@ */ public class UserAccountRecoveryServiceDataHolder { - private static UsernameRecoveryManager usernameRecoveryManager; - private static PasswordRecoveryManager passwordRecoveryManager; + private UserAccountRecoveryServiceDataHolder () { - /** - * Get UsernameRecoveryManager instance. - * - * @return UsernameRecoveryManager - */ - public static UsernameRecoveryManager getUsernameRecoveryManager() { + } - return UserAccountRecoveryServiceDataHolder.usernameRecoveryManager; + private static class UsernameRecoveryManagerHolder { + + static final UsernameRecoveryManager SERVICE = (UsernameRecoveryManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(UsernameRecoveryManager.class, null); } - /** - * Set UsernameRecoveryManager instance. - * - * @param usernameRecoveryManager UsernameRecoveryManager - */ - public static void setUsernameRecoveryManager(UsernameRecoveryManager usernameRecoveryManager) { + private static class PasswordRecoveryManagerHolder { - UserAccountRecoveryServiceDataHolder.usernameRecoveryManager = usernameRecoveryManager; + static final PasswordRecoveryManager SERVICE = (PasswordRecoveryManager) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(PasswordRecoveryManager.class, null); } /** - * Get PasswordRecoveryManager instance. + * Get UsernameRecoveryManager instance. * - * @return PasswordRecoveryManager + * @return UsernameRecoveryManager */ - public static PasswordRecoveryManager getPasswordRecoveryManager() { + public static UsernameRecoveryManager getUsernameRecoveryManager() { - return UserAccountRecoveryServiceDataHolder.passwordRecoveryManager; + return UsernameRecoveryManagerHolder.SERVICE; } /** * Get PasswordRecoveryManager instance. * - * @param passwordRecoveryManager PasswordRecoveryManager + * @return PasswordRecoveryManager */ - public static void setPasswordRecoveryManager( - PasswordRecoveryManager passwordRecoveryManager) { + public static PasswordRecoveryManager getPasswordRecoveryManager() { - UserAccountRecoveryServiceDataHolder.passwordRecoveryManager = passwordRecoveryManager; + return PasswordRecoveryManagerHolder.SERVICE; } } diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/PasswordRecoveryManagerOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/PasswordRecoveryManagerOSGIServiceFactory.java deleted file mode 100644 index 0f6f4da43..000000000 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/PasswordRecoveryManagerOSGIServiceFactory.java +++ /dev/null @@ -1,49 +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.user.recovery.commons.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.recovery.services.password.PasswordRecoveryManager; - -/** - * This factory bean is used to instantiate PasswordRecoveryManager type object inside the container. - */ -public class PasswordRecoveryManagerOSGIServiceFactory extends AbstractFactoryBean { - - private PasswordRecoveryManager passwordRecoveryManager; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected PasswordRecoveryManager createInstance() throws Exception { - - if (this.passwordRecoveryManager == null) { - PasswordRecoveryManager passwordRecoveryManager = (PasswordRecoveryManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(PasswordRecoveryManager.class, null); - if (passwordRecoveryManager != null) { - this.passwordRecoveryManager = passwordRecoveryManager; - } else { - throw new Exception("Unable to retrieve PasswordRecoveryManager service."); - } - } - return this.passwordRecoveryManager; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/UsernameRecoveryManagerOSGIServiceFactory.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/UsernameRecoveryManagerOSGIServiceFactory.java deleted file mode 100644 index 19409fa3b..000000000 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.api.user.recovery.commons/src/main/java/org/wso2/carbon/identity/api/user/recovery/commons/factory/UsernameRecoveryManagerOSGIServiceFactory.java +++ /dev/null @@ -1,49 +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.user.recovery.commons.factory; - -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.identity.recovery.services.username.UsernameRecoveryManager; - -/** - * This factory bean is used to instantiate UsernameRecoveryManager type object inside the container. - */ -public class UsernameRecoveryManagerOSGIServiceFactory extends AbstractFactoryBean { - - private UsernameRecoveryManager usernameRecoveryManager; - - @Override - public Class getObjectType() { - - return Object.class; - } - - @Override - protected UsernameRecoveryManager createInstance() throws Exception { - - if (this.usernameRecoveryManager == null) { - UsernameRecoveryManager usernameRecoveryManager = (UsernameRecoveryManager) PrivilegedCarbonContext - .getThreadLocalCarbonContext().getOSGiService(UsernameRecoveryManager.class, null); - if (usernameRecoveryManager != null) { - this.usernameRecoveryManager = usernameRecoveryManager; - } else { - throw new Exception("Unable to retrieve UsernameRecoveryManager service."); - } - } - return this.usernameRecoveryManager; - } -} diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/pom.xml b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/pom.xml index 5760dddfd..5a555906a 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/pom.xml @@ -1,18 +1,20 @@ @@ -105,11 +107,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.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/RecoveryApi.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/RecoveryApi.java index 6d23f68b2..e94ffe81b 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/RecoveryApi.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/RecoveryApi.java @@ -1,26 +1,28 @@ /* -* 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.rest.api.user.recovery.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 org.wso2.carbon.identity.rest.api.user.recovery.v1.factories.RecoveryApiServiceFactory; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ConfirmRequest; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ErrorResponse; @@ -36,7 +38,6 @@ import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ResetRequest; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RetryErrorResponse; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.UsernameRecoveryNotifyResponse; -import org.wso2.carbon.identity.rest.api.user.recovery.v1.RecoveryApiService; import javax.validation.Valid; import javax.ws.rs.*; @@ -50,8 +51,12 @@ public class RecoveryApi { - @Autowired - private RecoveryApiService delegate; + private final RecoveryApiService delegate; + + public RecoveryApi() { + + this.delegate = RecoveryApiServiceFactory.getRecoveryApi(); + } @Valid @POST diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/factories/RecoveryApiServiceFactory.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/factories/RecoveryApiServiceFactory.java index b6c71fae0..993ab7b89 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/factories/RecoveryApiServiceFactory.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/gen/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/factories/RecoveryApiServiceFactory.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.rest.api.user.recovery.v1.factories; import org.wso2.carbon.identity.rest.api.user.recovery.v1.RecoveryApiService; import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.RecoveryApiServiceImpl; +/** + * Factory class for RecoveryApiService. + */ public class RecoveryApiServiceFactory { - private final static RecoveryApiService service = new RecoveryApiServiceImpl(); + private final static RecoveryApiService SERVICE = new RecoveryApiServiceImpl(); - public static RecoveryApiService getRecoveryApi() - { - return service; - } + /** + * Get RecoveryApiService instance. + * + * @return RecoveryApiService + */ + public static RecoveryApiService getRecoveryApi() { + + return SERVICE; + } } diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/RecoveryApiServiceImpl.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/RecoveryApiServiceImpl.java index bc9de7327..542e49fd0 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/RecoveryApiServiceImpl.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/RecoveryApiServiceImpl.java @@ -1,26 +1,29 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.recovery.v1.impl; -import org.springframework.beans.factory.annotation.Autowired; import org.wso2.carbon.identity.rest.api.user.recovery.v1.RecoveryApiService; import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.PasswordRecoveryService; import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.UsernameRecoveryService; +import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.factories.PasswordRecoveryServiceFactory; +import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.factories.UsernameRecoveryServiceFactory; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.ConfirmRequest; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.InitRequest; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.RecoveryRequest; @@ -34,11 +37,19 @@ */ public class RecoveryApiServiceImpl implements RecoveryApiService { - @Autowired - private UsernameRecoveryService usernameRecoveryService; + private final UsernameRecoveryService usernameRecoveryService; + private final PasswordRecoveryService passwordRecoveryService; - @Autowired - private PasswordRecoveryService passwordRecoveryService; + public RecoveryApiServiceImpl() { + + try { + this.usernameRecoveryService = UsernameRecoveryServiceFactory.getUsernameRecoveryService(); + this.passwordRecoveryService = PasswordRecoveryServiceFactory.getPasswordRecoveryService(); + } catch (IllegalStateException e) { + throw new RuntimeException("Error occurred while initiating required services for " + + "RecoveryApiServiceImpl.", e); + } + } @Override public Response confirmRecovery(ConfirmRequest confirmRequest) { diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java index 54b3c5c2b..2f8798214 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/PasswordRecoveryService.java @@ -1,25 +1,27 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.recovery.v1.impl.core; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.Util; -import org.wso2.carbon.identity.api.user.recovery.commons.UserAccountRecoveryServiceDataHolder; import org.wso2.carbon.identity.governance.service.notification.NotificationChannels; import org.wso2.carbon.identity.recovery.IdentityRecoveryClientException; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; @@ -62,8 +64,15 @@ */ public class PasswordRecoveryService { + private final PasswordRecoveryManager passwordRecoveryManager; + private static final Log log = LogFactory.getLog(PasswordRecoveryService.class.getName()); + public PasswordRecoveryService(PasswordRecoveryManager passwordRecoveryManager) { + + this.passwordRecoveryManager = passwordRecoveryManager; + } + /** * Initiate Password Recovery from POST. * @@ -129,9 +138,8 @@ public Response recoverPassword(RecoveryRequest recoveryRequest) { String recoveryId = recoveryRequest.getRecoveryCode(); String channelId = recoveryRequest.getChannelId(); try { - PasswordRecoverDTO passwordRecoverDTO = UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager() - .notify(recoveryId, channelId, tenantDomain, - RecoveryUtil.buildPropertiesMap(recoveryRequest.getProperties())); + PasswordRecoverDTO passwordRecoverDTO = passwordRecoveryManager.notify(recoveryId, channelId, tenantDomain, + RecoveryUtil.buildPropertiesMap(recoveryRequest.getProperties())); if (passwordRecoverDTO == null) { if (log.isDebugEnabled()) { String message = String @@ -161,10 +169,9 @@ public Response confirmRecovery(ConfirmRequest confirmRequest) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); try { - PasswordResetCodeDTO passwordResetCodeDTO = - UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager() - .confirm(confirmRequest.getConfirmationCode(), tenantDomain, - RecoveryUtil.buildPropertiesMap(confirmRequest.getProperties())); + PasswordResetCodeDTO passwordResetCodeDTO = passwordRecoveryManager.confirm(confirmRequest + .getConfirmationCode(), tenantDomain, RecoveryUtil.buildPropertiesMap(confirmRequest + .getProperties())); return Response.ok().entity(buildResetCodeResponse(tenantDomain, passwordResetCodeDTO)).build(); } catch (IdentityRecoveryClientException e) { throw RecoveryUtil.handleClientExceptions(PasswordRecoveryService.class.getName(), tenantDomain, @@ -187,10 +194,8 @@ public Response resetPassword(ResetRequest resetRequest) { String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); char[] password = resetRequest.getPassword().toCharArray(); try { - SuccessfulPasswordResetDTO successfulPasswordResetDTO = - UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager() - .reset(resetRequest.getResetCode(), password, - RecoveryUtil.buildPropertiesMap(resetRequest.getProperties())); + SuccessfulPasswordResetDTO successfulPasswordResetDTO = passwordRecoveryManager.reset(resetRequest + .getResetCode(), password, RecoveryUtil.buildPropertiesMap(resetRequest.getProperties())); return Response.ok().entity(buildPasswordResetResponse(successfulPasswordResetDTO)).build(); } catch (IdentityRecoveryClientException e) { // Send the reset code again for a retry attempt. @@ -216,9 +221,8 @@ public Response resendConfirmation(ResendConfirmationRequest resendConfirmationR String resendCode = resendConfirmationRequest.getResendCode(); Map properties = RecoveryUtil.buildPropertiesMap(resendConfirmationRequest.getProperties()); try { - ResendConfirmationDTO resendConfirmationDTO = - UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager() - .resend(tenantDomain, resendCode, properties); + ResendConfirmationDTO resendConfirmationDTO = passwordRecoveryManager.resend(tenantDomain, resendCode, + properties); if (resendConfirmationDTO == null) { if (log.isDebugEnabled()) { log.debug("No ResendConfirmationDTO data for resend code :" + resendCode); diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/UsernameRecoveryService.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/UsernameRecoveryService.java index 2c0ff1ad1..6cf368485 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/UsernameRecoveryService.java +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/core/UsernameRecoveryService.java @@ -1,18 +1,21 @@ /* - * Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2020-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.user.recovery.v1.impl.core; import org.apache.commons.lang.StringUtils; @@ -21,7 +24,6 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.identity.api.user.common.Util; -import org.wso2.carbon.identity.api.user.recovery.commons.UserAccountRecoveryServiceDataHolder; import org.wso2.carbon.identity.governance.service.notification.NotificationChannels; import org.wso2.carbon.identity.recovery.IdentityRecoveryClientException; import org.wso2.carbon.identity.recovery.IdentityRecoveryConstants; @@ -30,6 +32,7 @@ import org.wso2.carbon.identity.recovery.dto.RecoveryInformationDTO; import org.wso2.carbon.identity.recovery.dto.UsernameRecoverDTO; +import org.wso2.carbon.identity.recovery.services.username.UsernameRecoveryManager; import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.utils.RecoveryUtil; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.APICall; import org.wso2.carbon.identity.rest.api.user.recovery.v1.model.AccountRecoveryType; @@ -49,8 +52,15 @@ */ public class UsernameRecoveryService { + private final UsernameRecoveryManager usernameRecoveryManager; + private static final Log log = LogFactory.getLog(UsernameRecoveryService.class); + public UsernameRecoveryService(UsernameRecoveryManager usernameRecoveryManager) { + + this.usernameRecoveryManager = usernameRecoveryManager; + } + /** * Initiate userName recovery from POST. * @@ -64,9 +74,8 @@ public Response initiateUsernameRecovery(InitRequest initRequest) { Map userClaims = RecoveryUtil.buildUserClaimsMap(initRequest.getClaims()); try { // Get username recovery notification information. - RecoveryInformationDTO recoveryInformationDTO = - UserAccountRecoveryServiceDataHolder.getUsernameRecoveryManager().initiate(userClaims, tenantDomain, - RecoveryUtil.buildPropertiesMap(initRequest.getProperties())); + RecoveryInformationDTO recoveryInformationDTO = usernameRecoveryManager.initiate(userClaims, tenantDomain, + RecoveryUtil.buildPropertiesMap(initRequest.getProperties())); if (recoveryInformationDTO == null) { // If RecoveryChannelInfoDTO is null throw not found error. if (log.isDebugEnabled()) { @@ -100,9 +109,8 @@ public Response recoverUsername(RecoveryRequest recoveryRequest) { String recoveryId = recoveryRequest.getRecoveryCode(); String channelId = recoveryRequest.getChannelId(); try { - UsernameRecoverDTO usernameRecoverDTO = UserAccountRecoveryServiceDataHolder.getUsernameRecoveryManager(). - notify(recoveryId, channelId, tenantDomain, - RecoveryUtil.buildPropertiesMap(recoveryRequest.getProperties())); + UsernameRecoverDTO usernameRecoverDTO = usernameRecoveryManager.notify(recoveryId, channelId, tenantDomain, + RecoveryUtil.buildPropertiesMap(recoveryRequest.getProperties())); if (usernameRecoverDTO == null) { if (log.isDebugEnabled()) { String message = String.format("No recovery data object for recovery code : %s", recoveryId); diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/PasswordRecoveryServiceFactory.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/PasswordRecoveryServiceFactory.java new file mode 100644 index 000000000..268593497 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/PasswordRecoveryServiceFactory.java @@ -0,0 +1,65 @@ +/* + * 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.user.recovery.v1.impl.factories; + +import org.wso2.carbon.identity.api.user.recovery.commons.UserAccountRecoveryServiceDataHolder; +import org.wso2.carbon.identity.recovery.services.password.PasswordRecoveryManager; +import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.PasswordRecoveryService; + +/** + * Factory class for PasswordRecoveryService. + */ +public class PasswordRecoveryServiceFactory { + + private PasswordRecoveryServiceFactory() { + + } + + private static class PasswordRecoveryServiceHolder { + + private static final PasswordRecoveryService SERVICE = createServiceInstance(); + } + + private static PasswordRecoveryService createServiceInstance() { + + PasswordRecoveryManager passwordRecoveryManager = getPasswordRecoveryManagerService(); + + return new PasswordRecoveryService(passwordRecoveryManager); + } + + /** + * Get AuthorizedAppsService + * + * @return AuthorizedAppsService + */ + public static PasswordRecoveryService getPasswordRecoveryService() { + + return PasswordRecoveryServiceHolder.SERVICE; + } + + private static PasswordRecoveryManager getPasswordRecoveryManagerService() { + + PasswordRecoveryManager service = UserAccountRecoveryServiceDataHolder.getPasswordRecoveryManager(); + if (service == null) { + throw new IllegalStateException("PasswordRecoveryManager is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/UsernameRecoveryServiceFactory.java b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/UsernameRecoveryServiceFactory.java new file mode 100644 index 000000000..4a274d3f5 --- /dev/null +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/recovery/v1/impl/factories/UsernameRecoveryServiceFactory.java @@ -0,0 +1,65 @@ +/* + * 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.user.recovery.v1.impl.factories; + +import org.wso2.carbon.identity.api.user.recovery.commons.UserAccountRecoveryServiceDataHolder; +import org.wso2.carbon.identity.recovery.services.username.UsernameRecoveryManager; +import org.wso2.carbon.identity.rest.api.user.recovery.v1.impl.core.UsernameRecoveryService; + +/** + * Factory class for UsernameRecoveryService. + */ +public class UsernameRecoveryServiceFactory { + + private UsernameRecoveryServiceFactory() { + + } + + private static class UsernameRecoveryServiceHolder { + + private static final UsernameRecoveryService SERVICE = createServiceInstance(); + } + + private static UsernameRecoveryService createServiceInstance() { + + UsernameRecoveryManager passwordRecoveryManager = getUsernameRecoveryManager(); + + return new UsernameRecoveryService(passwordRecoveryManager); + } + + /** + * Get AuthorizedAppsService + * + * @return AuthorizedAppsService + */ + public static UsernameRecoveryService getUsernameRecoveryService() { + + return UsernameRecoveryServiceHolder.SERVICE; + } + + private static UsernameRecoveryManager getUsernameRecoveryManager() { + + UsernameRecoveryManager service = UserAccountRecoveryServiceDataHolder.getUsernameRecoveryManager(); + if (service == null) { + throw new IllegalStateException("UsernameRecoveryManager is not available from OSGi context."); + } + + return service; + } +} diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/resources/META-INF/cxf/user-recovery-v1-cxf.xml b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/resources/META-INF/cxf/user-recovery-v1-cxf.xml deleted file mode 100644 index 5519b5d41..000000000 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v1/src/main/resources/META-INF/cxf/user-recovery-v1-cxf.xml +++ /dev/null @@ -1,31 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/pom.xml b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/pom.xml index 7600565e3..23b4f3059 100644 --- a/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.recovery/org.wso2.carbon.identity.rest.api.user.recovery.v2/pom.xml @@ -1,6 +1,6 @@ - - - - - - - - - - - - - From 8ef3bd8867461d8714b75f4a8fd07a8eb545bcd6 Mon Sep 17 00:00:00 2001 From: lashinie Date: Sat, 11 Jan 2025 07:48:01 +0530 Subject: [PATCH 14/15] Remove Spring dependency from api.user.totp --- .../pom.xml | 9 +---- .../pom.xml | 9 +---- .../identity/rest/api/user/totp/v1/MeApi.java | 27 ++++++++----- .../v1/factories/MeApiServiceFactory.java | 36 +++++++++++------ .../totp/v1/factories/TOTPServiceFactory.java | 40 +++++++++++++++++++ .../user/totp/v1/impl/MeApiServiceImpl.java | 29 +++++++++----- .../META-INF/cxf/user-totp-v1-cxf.xml | 21 ---------- 7 files changed, 101 insertions(+), 70 deletions(-) create mode 100644 components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.v1/src/main/java/org/wso2/carbon/identity/rest/api/user/totp/v1/factories/TOTPServiceFactory.java delete mode 100644 components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.v1/src/main/resources/META-INF/cxf/user-totp-v1-cxf.xml diff --git a/components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.common/pom.xml b/components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.common/pom.xml index 8ee885508..419d2c6da 100644 --- a/components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.common/pom.xml +++ b/components/org.wso2.carbon.identity.api.user.totp/org.wso2.carbon.identity.api.user.totp.common/pom.xml @@ -1,8 +1,8 @@ - - - - - From 6bb213dcd647f4f0ae5d16dcd678ae68231625e3 Mon Sep 17 00:00:00 2001 From: lashinie Date: Sat, 11 Jan 2025 07:48:42 +0530 Subject: [PATCH 15/15] Remove Spring dependency from main pom.xml --- pom.xml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 67ad2eaec..49560b2c9 100644 --- a/pom.xml +++ b/pom.xml @@ -1,8 +1,8 @@