Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Spring Cleanup] Remove Spring dependencies in the organization roles management API #707

Open
wants to merge 3 commits into
base: feature-spring-cleanup
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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
Expand Down Expand Up @@ -30,11 +30,6 @@
<artifactId>org.wso2.carbon.identity.api.server.organization.role.management.common</artifactId>

<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.carbon.identity.organization.management</groupId>
<artifactId>org.wso2.carbon.identity.organization.management.role.management.service</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -18,6 +18,7 @@

package org.wso2.carbon.identity.api.server.organization.role.management.common;

import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.organization.management.role.management.service.RoleManager;
import org.wso2.carbon.identity.organization.management.service.OrganizationUserResidentResolverService;

Expand All @@ -26,60 +27,36 @@
*/
public class OrganizationRoleManagementServiceHolder {

private static OrganizationRoleManagementServiceHolder instance = new OrganizationRoleManagementServiceHolder();

private RoleManager roleManager;

private OrganizationUserResidentResolverService organizationUserResidentResolverService;

private OrganizationRoleManagementServiceHolder() {
private OrganizationRoleManagementServiceHolder() {}

private static class RoleManagerServiceHolder {
static final RoleManager SERVICE = (RoleManager) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(RoleManager.class, null);
}

public static OrganizationRoleManagementServiceHolder getInstance() {

return instance;
private static class OrganizationUserResidentResolverServiceHolder {
static final OrganizationUserResidentResolverService SERVICE =
(OrganizationUserResidentResolverService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(OrganizationUserResidentResolverService.class, null);
}

/**
* Get RoleManager OSGi service.
*
* @return RoleManager.
*/
public RoleManager getRoleManager() {

return OrganizationRoleManagementServiceHolder.getInstance().roleManager;
}

/**
* Set RoleManager OSGi service.
*
* @param roleManager RoleManager.
*/
public void setRoleManager(RoleManager roleManager) {
public static RoleManager getRoleManager() {

OrganizationRoleManagementServiceHolder.getInstance().roleManager = roleManager;
return RoleManagerServiceHolder.SERVICE;
}

/**
* Method to get the organization user resident resolver OSGi service.
*
* @return OrganizationUserResidentResolverService.
*/
public OrganizationUserResidentResolverService getOrganizationUserResidentResolverService() {

return OrganizationRoleManagementServiceHolder.getInstance().organizationUserResidentResolverService;
}

/**
* Set OrganizationUserResidentResolverService OSGi service.
*
* @param organizationUserResidentResolverService OrganizationUserResidentResolverService.
*/
public void setOrganizationUserResidentResolverService(
OrganizationUserResidentResolverService organizationUserResidentResolverService) {
public static OrganizationUserResidentResolverService getOrganizationUserResidentResolverService() {

OrganizationRoleManagementServiceHolder.getInstance().organizationUserResidentResolverService
= organizationUserResidentResolverService;
return OrganizationUserResidentResolverServiceHolder.SERVICE;
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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
Expand Down Expand Up @@ -43,11 +43,6 @@
<artifactId>cxf-rt-rs-service-description</artifactId>
<scope>provided</scope>
</dependency>
<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,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
Expand All @@ -18,12 +18,12 @@

package org.wso2.carbon.identity.api.server.organization.role.management.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 java.util.List;

import org.wso2.carbon.identity.api.server.organization.role.management.v1.factories.OrganizationsApiServiceFactory;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.Error;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RoleGetResponse;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RoleObj;
Expand All @@ -34,7 +34,6 @@
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePutRequest;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePutResponse;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolesListResponse;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.OrganizationsApiService;

import javax.validation.Valid;
import javax.ws.rs.*;
Expand All @@ -48,8 +47,12 @@

public class OrganizationsApi {

@Autowired
private OrganizationsApiService delegate;
private final OrganizationsApiService delegate;

public OrganizationsApi() {

this.delegate = OrganizationsApiServiceFactory.getOrganizationsApi();
}

@Valid
@POST
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -21,12 +21,20 @@
import org.wso2.carbon.identity.api.server.organization.role.management.v1.OrganizationsApiService;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.impl.OrganizationsApiServiceImpl;

/**
* Factory class for OrganizationsApiService.
*/
public class OrganizationsApiServiceFactory {

private final static OrganizationsApiService service = new OrganizationsApiServiceImpl();
private final static OrganizationsApiService SERVICE = new OrganizationsApiServiceImpl();

/**
* Get OrganizationsApiService.
*
* @return OrganizationsApiService.
*/
public static OrganizationsApiService getOrganizationsApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.server.organization.role.management.v1.factories;

import org.wso2.carbon.identity.api.server.organization.role.management.common.OrganizationRoleManagementServiceHolder;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.service.RoleManagementService;
import org.wso2.carbon.identity.organization.management.role.management.service.RoleManager;
import org.wso2.carbon.identity.organization.management.service.OrganizationUserResidentResolverService;

/**
* Factory class for RoleManagementService.
*/
public class RoleManagementServiceFactory {

private RoleManagementServiceFactory() {

}

private static class RoleManagementServiceHolder {

private static final RoleManagementService SERVICE = createServiceInstance();
}

private static RoleManagementService createServiceInstance() {

RoleManager roleManager = getRoleManagerService();
OrganizationUserResidentResolverService organizationUserResidentResolverService =
getOrganizationUserResidentResolverService();

return new RoleManagementService(roleManager, organizationUserResidentResolverService);
}

/**
* Get RoleManagementService.
*
* @return RoleManagementService.
*/
public static RoleManagementService getRoleManagementService() {

return RoleManagementServiceHolder.SERVICE;
}

private static RoleManager getRoleManagerService() {

RoleManager service = OrganizationRoleManagementServiceHolder.getRoleManager();
if (service == null) {
throw new IllegalStateException("RoleManager service is not available from OSGi context.");
}

return service;
}

private static OrganizationUserResidentResolverService getOrganizationUserResidentResolverService() {

OrganizationUserResidentResolverService service = OrganizationRoleManagementServiceHolder
.getOrganizationUserResidentResolverService();
if (service == null) {
throw new IllegalStateException("OrganizationUserResidentResolverService is not available " +
"from OSGi context.");
}

return service;
}
}
Loading