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 3c77ce055..f7883718e 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 d01325c22..b70038522 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 @@ - - - - - - - - -