Modifier and Type | Method and Description |
---|---|
static <T> T |
executeWithFallbackTenant(Supplier<Tenant> fallbackTenant,
Callable<T> callable)
Execute the given
Callable , using the given tenant as fallback if there is no other tenant available. |
static void |
executeWithFallbackTenant(Supplier<Tenant> fallbackTenant,
Executable executable)
Execute the given
Executable , using the given tenant as fallback if there is no other tenant available. |
static <T> T |
executeWithTenant(Tenant tenant,
Callable<T> callable)
Execute the given
Callable on behalf of a given tenant. |
static void |
executeWithTenant(Tenant tenant,
Executable executable)
Execute the given
Executable on behalf of a given tenant. |
static Tenant |
getCurrentTenant()
Returns the current
Tenant . |
static Supplier<Tenant> |
getFallbackTenant()
Global fallback
Tenant . |
static TenantFacade |
getTenantFacade()
Returns the
TenantFacade instance. |
static void |
setFallbackTenant(Supplier<Tenant> fallbackTenant)
Global fallback
Tenant . |
static void |
setTenantFacade(TenantFacade tenantFacade)
Replaces the default
TenantFacade instance. |
static io.vavr.control.Try<Tenant> |
tryGetCurrentTenant()
|
static io.vavr.control.Try<TenantFacade> |
tryGetTenantFacade()
Returns a
Try of the TenantFacade instance. |
@Nullable public static TenantFacade getTenantFacade()
TenantFacade
instance.TenantFacade
instance, or null
.@Nonnull public static io.vavr.control.Try<TenantFacade> tryGetTenantFacade()
Try
of the TenantFacade
instance.Try
of the TenantFacade
instance.public static void setTenantFacade(@Nullable TenantFacade tenantFacade)
TenantFacade
instance.tenantFacade
- An instance of TenantFacade
. Use null
to reset the facade.@Nonnull public static Tenant getCurrentTenant() throws TenantAccessException
Tenant
.Tenant
.TenantAccessException
- If there is an issue while accessing the Tenant
.@Nonnull public static io.vavr.control.Try<Tenant> tryGetCurrentTenant()
Try
of the current Tenant
, or, if the Try
is a failure, the global fallback.
On SAP Cloud Platform, the availability of a tenant is defined as follows:
Tenant available | Tenant not available | |
---|---|---|
SAP Cloud Platform Cloud Foundry | A request is present with an "Authorization" header that contains a valid JWT bearer with field "zid". As a fallback a JWT will be retrieved from a bound XSUAA instance. |
A request is not available, no "Authorization" header is present in the current request, the JWT bearer does not hold a field "zid", or there is no XSUAA service bound to this application. |
SAP Cloud Platform Neo | Successful JNDI lookup of TenantContext (part of Neo SDK, com.sap.cloud.account.TenantContext). | Never. If correctly configured, a TenantContext is always available. If not, a TenantAccessException
is thrown. |
Try
of the current Tenant
.@Nullable public static <T> T executeWithTenant(@Nonnull Tenant tenant, @Nonnull Callable<T> callable) throws ThreadContextExecutionException
Callable
on behalf of a given tenant.T
- The type of the callable.tenant
- The tenant to execute on behalf of.callable
- The callable to execute.ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.public static void executeWithTenant(@Nonnull Tenant tenant, @Nonnull Executable executable) throws ThreadContextExecutionException
Executable
on behalf of a given tenant.tenant
- The tenant to execute on behalf of.ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.@Nullable public static <T> T executeWithFallbackTenant(@Nonnull Supplier<Tenant> fallbackTenant, @Nonnull Callable<T> callable) throws ThreadContextExecutionException
Callable
, using the given tenant as fallback if there is no other tenant available.T
- The type of the callable.fallbackTenant
- The tenant to fall back to.callable
- The callable to execute.ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.public static void executeWithFallbackTenant(@Nonnull Supplier<Tenant> fallbackTenant, @Nonnull Executable executable) throws ThreadContextExecutionException
Executable
, using the given tenant as fallback if there is no other tenant available.fallbackTenant
- The tenant to fall back to.ThreadContextExecutionException
- If there is an issue while running the code on behalf of the tenant.@Nullable public static Supplier<Tenant> getFallbackTenant()
Tenant
. By default, no fallback is used, i.e., the fallback is null
. A global
fallback can be useful to ensure a safe fallback or to ease testing with a mocked tenant.Copyright © 2019 SAP SE. All rights reserved.