Skip to content

Commit

Permalink
[Spring Cleanup] Remove Spring dependencies in APIs (#687)
Browse files Browse the repository at this point in the history
* Remove Spring dependencies in Application management API

* Resolve PR comments

* Remove Spring dependencies in the userstores management API

* Remove Spring dependencies in the self service management API

* Fix minor issues

* Update SelfServiceMgtServiceTest test class
  • Loading branch information
NipuniBhagya authored Dec 9, 2024
1 parent cd4e9b9 commit 48369ef
Show file tree
Hide file tree
Showing 51 changed files with 1,052 additions and 1,575 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
~ Copyright (c) 2019-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
Expand Down Expand Up @@ -31,11 +31,6 @@
<packaging>jar</packaging>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
/*
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2019-2024, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.server.application.management.common;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.api.resource.mgt.APIResourceManager;
import org.wso2.carbon.identity.application.mgt.ApplicationManagementService;
import org.wso2.carbon.identity.application.mgt.AuthorizedAPIManagementService;
Expand All @@ -32,166 +38,213 @@
*/
public class ApplicationManagementServiceHolder {

private static ApplicationManagementService applicationManagementService;
private static OAuthAdminServiceImpl oauthAdminService;
private static STSAdminServiceInterface stsAdminService;
private static SAMLSSOConfigServiceImpl samlssoConfigService;
private static OAuthServerConfiguration oAuthServerConfiguration;
private static TemplateManager templateManager;
private static CORSManagementService corsManagementService;
private static RealmService realmService;
private static APIResourceManager apiResourceManager;
private static AuthorizedAPIManagementService authorizedAPIManagementService;
private static OrgApplicationManager orgApplicationManager;
private ApplicationManagementServiceHolder() {

public static ApplicationManagementService getApplicationManagementService() {
}

private static class ApplicationServiceHolder {

return applicationManagementService;
static final ApplicationManagementService SERVICE = (ApplicationManagementService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(ApplicationManagementService.class, null);
}

public static void setApplicationManagementService(ApplicationManagementService applicationManagementService) {
private static class OAuthAdminServiceImplHolder {

ApplicationManagementServiceHolder.applicationManagementService = applicationManagementService;
static final OAuthAdminServiceImpl SERVICE = (OAuthAdminServiceImpl) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OAuthAdminServiceImpl.class, null);
}

public static OAuthAdminServiceImpl getOAuthAdminService() {
private static class STSAdminServiceInterfaceHolder {

private static final Log log = LogFactory.getLog(STSAdminServiceInterfaceHolder.class);
static final STSAdminServiceInterface SERVICE = initializeService();

/**
* Initializes the STSAdminServiceInterface from the OSGi context.
*
* @return STSAdminServiceInterface or null if the service is unavailable.
*/
private static STSAdminServiceInterface initializeService() {

return oauthAdminService;
try {
STSAdminServiceInterface service = (STSAdminServiceInterface) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(STSAdminServiceInterface.class, null);

if (service == null) {
// Log a warning if the service is not available, but don't throw an exception
log.warn("STSAdminServiceInterface is not available from OSGi context. This may occur if " +
"the STS connector is not present.");
}
return service;

} catch (NullPointerException e) {
// Catch NullPointerException if the context or the service isn't properly set
log.warn("NullPointerException occurred while retrieving STSAdminServiceInterface. " +
"Context or service might not be available.");
return null;
} catch (Exception e) {
// Catch any other exceptions and log them
log.error("Error occurred while retrieving STSAdminServiceInterface: " + e.getMessage(), e);
return null;
}
}
}

public static void setOauthAdminService(OAuthAdminServiceImpl oauthAdminService) {
private static class SAMLSSOConfigServiceImplHolder {

ApplicationManagementServiceHolder.oauthAdminService = oauthAdminService;
static final SAMLSSOConfigServiceImpl SERVICE = (SAMLSSOConfigServiceImpl) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(SAMLSSOConfigServiceImpl.class, null);
}

public static STSAdminServiceInterface getStsAdminService() {
private static class OAuthServerConfigurationHolder {

return stsAdminService;
static final OAuthServerConfiguration SERVICE = (OAuthServerConfiguration) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OAuthServerConfiguration.class, null);
}

public static void setStsAdminService(STSAdminServiceInterface stsAdminService) {
private static class TemplateManagerHolder {

ApplicationManagementServiceHolder.stsAdminService = stsAdminService;
static final TemplateManager SERVICE = (TemplateManager) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(TemplateManager.class, null);
}

public static SAMLSSOConfigServiceImpl getSamlssoConfigService() {
private static class CORSManagementServiceHolder {

return samlssoConfigService;
static final CORSManagementService SERVICE = (CORSManagementService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(CORSManagementService.class, null);
}

public static void setSamlssoConfigService(SAMLSSOConfigServiceImpl samlssoConfigService) {
private static class RealmServiceHolder {

ApplicationManagementServiceHolder.samlssoConfigService = samlssoConfigService;
static final RealmService SERVICE = (RealmService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(RealmService.class, null);
}

public static OAuthServerConfiguration getoAuthServerConfiguration() {
private static class APIResourceManagerHolder {

return oAuthServerConfiguration;
static final APIResourceManager SERVICE = (APIResourceManager) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(APIResourceManager.class, null);
}

public static void setoAuthServerConfiguration(OAuthServerConfiguration oAuthServerConfiguration) {
private static class AuthorizedAPIManagementServiceHolder {

ApplicationManagementServiceHolder.oAuthServerConfiguration = oAuthServerConfiguration;
static final AuthorizedAPIManagementService SERVICE = (AuthorizedAPIManagementService) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(AuthorizedAPIManagementService.class, null);
}

public static TemplateManager getTemplateManager() {
private static class OrgApplicationManagerHolder {

return templateManager;
static final OrgApplicationManager SERVICE = (OrgApplicationManager) PrivilegedCarbonContext
.getThreadLocalCarbonContext().getOSGiService(OrgApplicationManager.class, null);
}

public static void setTemplateManager(TemplateManager templateManager) {
/**
* Get ApplicationManagementService.
*
* @return ApplicationManagementService.
*/
public static ApplicationManagementService getApplicationManagementService() {

ApplicationManagementServiceHolder.templateManager = templateManager;
return ApplicationServiceHolder.SERVICE;
}

public static CORSManagementService getCorsManagementService() {
/**
* Get OAuthAdminServiceImpl.
*
* @return OAuthAdminServiceImpl.
*/
public static OAuthAdminServiceImpl getOAuthAdminService() {

return corsManagementService;
return OAuthAdminServiceImplHolder.SERVICE;
}

public static void setCorsManagementService(CORSManagementService corsManagementService) {
/**
* Get STSAdminServiceInterface.
*
* @return STSAdminServiceInterface.
*/
public static STSAdminServiceInterface getStsAdminService() {

ApplicationManagementServiceHolder.corsManagementService = corsManagementService;
return STSAdminServiceInterfaceHolder.SERVICE;
}

/**
* Get RealmService.
* Get SAMLSSOConfigServiceImpl.
*
* @return RealmService.
* @return SAMLSSOConfigServiceImpl.
*/
public static RealmService getRealmService() {
public static SAMLSSOConfigServiceImpl getSamlssoConfigService() {

return realmService;
return SAMLSSOConfigServiceImplHolder.SERVICE;
}

/**
* Set RealmService.
* Get OAuthServerConfiguration.
*
* @param realmService RealmService.
* @return OAuthServerConfiguration.
*/
public static void setRealmService(RealmService realmService) {
public static OAuthServerConfiguration getoAuthServerConfiguration() {

ApplicationManagementServiceHolder.realmService = realmService;
return OAuthServerConfigurationHolder.SERVICE;
}

/**
* Get APIResourceManager.
* Get TemplateManager.
*
* @return APIResourceManager.
* @return TemplateManager.
*/
public static APIResourceManager getApiResourceManager() {
public static TemplateManager getTemplateManager() {

return apiResourceManager;
return TemplateManagerHolder.SERVICE;
}

/**
* Set APIResourceManager.
* Get CORSManagementService.
*
* @param apiResourceManager APIResourceManager.
* @return CORSManagementService.
*/
public static void setApiResourceManager(APIResourceManager apiResourceManager) {
public static CORSManagementService getCorsManagementService() {

ApplicationManagementServiceHolder.apiResourceManager = apiResourceManager;
return CORSManagementServiceHolder.SERVICE;
}

/**
* Get AuthorizedAPIManagementService.
* Get RealmService.
*
* @return AuthorizedAPIManagementService.
* @return RealmService.
*/
public static AuthorizedAPIManagementService getAuthorizedAPIManagementService() {
public static RealmService getRealmService() {

return authorizedAPIManagementService;
return RealmServiceHolder.SERVICE;
}

/**
* Set AuthorizedAPIManagementService.
* Get APIResourceManager.
*
* @param authorizedAPIManagementService AuthorizedAPIManagementService.
* @return APIResourceManager.
*/
public static void setAuthorizedAPIManagementService(AuthorizedAPIManagementService
authorizedAPIManagementService) {
public static APIResourceManager getApiResourceManager() {

ApplicationManagementServiceHolder.authorizedAPIManagementService = authorizedAPIManagementService;
return APIResourceManagerHolder.SERVICE;
}

/**
* Get OrgApplicationManager OSGi service.
* Get AuthorizedAPIManagementService.
*
* @return OrgApplicationManager.
* @return AuthorizedAPIManagementService.
*/
public static OrgApplicationManager getOrgApplicationManager() {
public static AuthorizedAPIManagementService getAuthorizedAPIManagementService() {

return orgApplicationManager;
return AuthorizedAPIManagementServiceHolder.SERVICE;
}

/**
* Set OrgApplicationManager OSGi service.
* Get OrgApplicationManager OSGi service.
*
* @param orgApplicationManager OrgApplicationManager.
* @return OrgApplicationManager.
*/
public static void setOrgApplicationManager(OrgApplicationManager orgApplicationManager) {
public static OrgApplicationManager getOrgApplicationManager() {

ApplicationManagementServiceHolder.orgApplicationManager = orgApplicationManager;
return OrgApplicationManagerHolder.SERVICE;
}
}

This file was deleted.

Loading

0 comments on commit 48369ef

Please sign in to comment.