com.sap.cds.feature.mt.SaasClient Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cds-feature-mt Show documentation
Show all versions of cds-feature-mt Show documentation
Multi tenancy feature for CDS Services Java
/**************************************************************************
* (C) 2019-2024 SAP SE or an SAP affiliate company. All rights reserved. *
**************************************************************************/
package com.sap.cds.feature.mt;
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.BooleanNode;
import com.google.common.base.Objects;
import com.sap.cds.integration.cloudsdk.rest.client.JsonRestClient;
import com.sap.cds.services.runtime.CdsRuntime;
import com.sap.cds.services.utils.environment.ServiceBindingUtils;
import com.sap.cloud.environment.servicebinding.api.ServiceBinding;
import com.sap.cloud.environment.servicebinding.api.ServiceIdentifier;
import com.sap.cloud.sdk.cloudplatform.connectivity.DefaultOAuth2PropertySupplier;
import com.sap.cloud.sdk.cloudplatform.connectivity.OAuth2ServiceBindingDestinationLoader;
import com.sap.cloud.sdk.cloudplatform.connectivity.OnBehalfOf;
import com.sap.cloud.sdk.cloudplatform.connectivity.ServiceBindingDestinationOptions;
/**
* Implementation of the SaaS Registry REST client.
*/
public class SaasClient extends JsonRestClient {
private static final Logger logger = LoggerFactory.getLogger(SaasClient.class);
// could be configurable via CdsProperties
private static final int PAGE_SIZE = 500;
private static final String TENANT_STATE = "state";
private static final String SAAS_REGISTRY = "saas-registry";
private static final String SAAS_MANAGER_BASE = "/saas-manager/v1/";
private static final String APPLICATION_TENANTS_PATH = SAAS_MANAGER_BASE + "application/subscriptions";
private static final String SERVICE_TENANTS_PATH = SAAS_MANAGER_BASE + "service/subscriptions?includeIndirectSubscriptions=true";
private final String urlPath;
static {
OAuth2ServiceBindingDestinationLoader.registerPropertySupplier(
ServiceIdentifier.of(SAAS_REGISTRY),
OAuth2Supplier::new);
}
private static class OAuth2Supplier extends DefaultOAuth2PropertySupplier {
public OAuth2Supplier(ServiceBindingDestinationOptions options) {
super(options, Collections.emptyList());
}
@Override
public URI getServiceUri() {
return getCredentialOrThrow(URI.class, "saas_registry_url");
}
}
public static Optional findBinding(CdsRuntime runtime) {
return runtime.getEnvironment().getServiceBindings().filter(b -> ServiceBindingUtils.matches(b, null, SAAS_REGISTRY)).findFirst();
}
public SaasClient(ServiceBinding binding) {
super(ServiceBindingDestinationOptions.forService(binding).onBehalfOf(OnBehalfOf.TECHNICAL_USER_PROVIDER).build());
this.urlPath = "service".equals(binding.getServicePlan().orElse(null)) ? SERVICE_TENANTS_PATH : APPLICATION_TENANTS_PATH;
}
/**
* Retrieves the tenant info of all subscribed tenants
*
* @return tenants info
*
* @throws IOException throws when any connection problems occur
*/
public List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy