Skip to content

Commit

Permalink
Merge pull request #704 from hwupathum/put-tenant-api
Browse files Browse the repository at this point in the history
Introduce a PUT and GET operation to the Tenant Management API (v1)
  • Loading branch information
hwupathum authored Oct 17, 2024
2 parents 31d9635 + 449c4fd commit 94f9af3
Show file tree
Hide file tree
Showing 30 changed files with 1,243 additions and 349 deletions.
Original file line number Diff line number Diff line change
@@ -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.api.server.tenant.management.common;

Expand All @@ -31,6 +33,7 @@ private TenantManagementConstants() {
public static final String PAGINATION_WITH_FILTER_LINK_FORMAT = "?offset=%d&limit=%d&filter=%s";
public static final String PAGE_LINK_REL_NEXT = "next";
public static final String PAGE_LINK_REL_PREVIOUS = "previous";
public static final String NON_EXISTING_USER_CODE = "30007 - ";

/**
* Enum for error messages.
Expand All @@ -43,6 +46,12 @@ public enum ErrorMessage {
ERROR_CODE_TENANT_LIMIT_REACHED("TM-60019",
"Unable to create a tenant.",
"Maximum number of allowed tenants have been reached."),
ERROR_CODE_OWNER_NOT_FOUND("TM-60020",
"Unable to retrieve the tenant owner.",
"Tenant owner cannot be found for the provided tenant id: %s."),
ERROR_CODE_PARTIALLY_CREATED_OR_UPDATED("TM-60021",
"Tenant creation / update was completed with errors.",
"Tenant creation / update was completed with error: %s"),
ERROR_CODE_ERROR_LISTING_TENANTS("TM-65001",
"Unable to list existing tenants.",
"Server encountered an error while listing the tenants."),
Expand All @@ -64,7 +73,11 @@ public enum ErrorMessage {
"Unable to check availability of domain.",
"Server encountered an error while checking for tenant domain"),
ERROR_CODE_DELETE_TENANT_METADATA("TM-65008", "Error while deleting the tenant metadata.",
"Server encountered an error while deleting the tenant metadata identified by %s .");
"Server encountered an error while deleting the tenant metadata identified by %s."),
ERROR_CODE_ERROR_RETRIEVING_OWNER("TM-65009", "Unable to retrieve the tenant owner.",
"Server encountered an error while retrieving the owner identified by tenant id %s."),
ERROR_CODE_ERROR_UPDATING_OWNER("TM-65010", "Unable to update the tenant owner.",
"Server encountered an error while updating the owner identified by tenant id %s.");

private final String code;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
* Copyright (c) 2020-2024, WSO2 LLC. (http://www.wso2.com).
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.identity.api.server.tenant.management.common;

import org.wso2.carbon.tenant.mgt.services.TenantMgtService;
import org.wso2.carbon.user.core.service.RealmService;

/**
* Service holder class for tenant management.
*/
public class TenantManagementServiceHolder {

private static TenantMgtService tenantMgtService;
private static RealmService realmService;

/**
* Get TenantMgtService osgi service.
Expand All @@ -43,4 +47,24 @@ public static void setTenantMgtService(TenantMgtService tenantMgtService) {

TenantManagementServiceHolder.tenantMgtService = tenantMgtService;
}

/**
* Get RealmService osgi service.
*
* @return RealmService
*/
public static RealmService getRealmService() {

return realmService;
}

/**
* Set RealmService osgi service.
*
* @param realmService RealmService.
*/
public static void setRealmService(RealmService realmService) {

TenantManagementServiceHolder.realmService = realmService;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.tenant.management.common.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.core.service.RealmService;

/**
* Factory Beans serves as a factory for creating other beans within the IOC container. This factory bean is used to
* instantiate the RealmService inside the container.
*/
public class RealmServiceOSGIServiceFactory extends AbstractFactoryBean<RealmService> {

private RealmService realmService;

@Override
public Class<?> getObjectType() {

return Object.class;
}

@Override
protected RealmService createInstance() throws Exception {

if (this.realmService == null) {
RealmService realmService = (RealmService)
PrivilegedCarbonContext.getThreadLocalCarbonContext()
.getOSGiService(RealmService.class, null);
if (realmService != null) {
this.realmService = realmService;
} else {
throw new Exception("Unable to retrieve RealmService service.");
}
}
return this.realmService;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright (c) 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.tenant.management.v1;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Authorization;
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.tenant.management.v1.model.ChannelVerifiedTenantModel;
import org.wso2.carbon.identity.api.server.tenant.management.v1.model.Error;
import org.wso2.carbon.identity.api.server.tenant.management.v1.ChannelVerifiedTenantsApiService;

import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import io.swagger.annotations.*;

import javax.validation.constraints.*;

@Path("/channel-verified-tenants")
@Api(description = "The channel-verified-tenants API")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
/*
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
* Copyright (c) 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.tenant.management.v1;

import org.wso2.carbon.identity.api.server.tenant.management.v1.*;
import org.wso2.carbon.identity.api.server.tenant.management.v1.model.*;
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.tenant.management.v1.model.ChannelVerifiedTenantModel;
import org.wso2.carbon.identity.api.server.tenant.management.v1.model.Error;

import javax.ws.rs.core.Response;


Expand Down
Loading

0 comments on commit 94f9af3

Please sign in to comment.