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 #814

Merged
merged 4 commits into from
Jan 25, 2025
Merged
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
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
Expand Up @@ -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,38 @@
*/
public class OrganizationRoleManagementServiceHolder {

private static OrganizationRoleManagementServiceHolder instance = new OrganizationRoleManagementServiceHolder();
private OrganizationRoleManagementServiceHolder() {}

private RoleManager roleManager;

private OrganizationUserResidentResolverService organizationUserResidentResolverService;

private OrganizationRoleManagementServiceHolder() {
private static class RoleManagerServiceHolder {

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

public static OrganizationRoleManagementServiceHolder getInstance() {
private static class OrganizationUserResidentResolverServiceHolder {

return instance;
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
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
Expand Up @@ -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
Expand Up @@ -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 static final OrganizationsApiService SERVICE = new OrganizationsApiServiceImpl();

/**
* Get OrganizationsApiService.
*
* @return OrganizationsApiService.
*/
public static OrganizationsApiService getOrganizationsApi() {

public static OrganizationsApiService getOrganizationsApi()
{
return service;
return SERVICE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2025, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.api.server.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 static final RoleManagementService SERVICE;

static {
RoleManager roleManager = OrganizationRoleManagementServiceHolder.getRoleManager();
OrganizationUserResidentResolverService organizationUserResidentResolverService =
OrganizationRoleManagementServiceHolder.getOrganizationUserResidentResolverService();

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

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

SERVICE = new RoleManagementService(roleManager, organizationUserResidentResolverService);
}

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

return SERVICE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

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

import org.springframework.beans.factory.annotation.Autowired;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.OrganizationsApiService;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.factories.RoleManagementServiceFactory;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePatchRequest;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePostRequest;
import org.wso2.carbon.identity.api.server.organization.role.management.v1.model.RolePutRequest;
Expand All @@ -32,8 +32,16 @@
*/
public class OrganizationsApiServiceImpl implements OrganizationsApiService {

@Autowired
private RoleManagementService roleManagementService;
private final RoleManagementService roleManagementService;

public OrganizationsApiServiceImpl() {

try {
this.roleManagementService = RoleManagementServiceFactory.getRoleManagementService();
} catch (IllegalStateException e) {
throw new RuntimeException("Error occurred while initiating role management service.", e);
}
}

@Override
public Response createRole(String organizationId, RolePostRequest rolePostRequest) {
Expand Down
Loading
Loading