Class PrincipalAccessor
java.lang.Object
com.sap.cloud.sdk.cloudplatform.security.principal.PrincipalAccessor
Accessor for retrieving the current
Principal
.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
executeWithFallbackPrincipal
(Supplier<Principal> fallbackPrincipal, Executable executable) Execute the givenExecutable
, using the given principal as fallback if there is no other principal available.static <T> T
executeWithFallbackPrincipal
(Supplier<Principal> fallbackPrincipal, Callable<T> callable) Execute the givenCallable
, using the given principal as fallback if there is no other principal available.static void
executeWithPrincipal
(Principal principal, Executable executable) Execute the givenExecutable
on behalf of a given principal.static <T> T
executeWithPrincipal
(Principal principal, Callable<T> callable) Execute the givenCallable
on behalf of a given principal.static Principal
Returns the currentPrincipal
.Global fallbackPrincipal
.static PrincipalFacade
Returns thePrincipalFacade
instance.static void
setFallbackPrincipal
(Supplier<Principal> fallbackPrincipal) Global fallbackPrincipal
.static void
setPrincipalFacade
(PrincipalFacade principalFacade) Replaces the defaultPrincipalFacade
instance.static io.vavr.control.Try<Principal>
static io.vavr.control.Try<PrincipalFacade>
Returns aTry
of thePrincipalFacade
instance.
-
Method Details
-
getPrincipalFacade
Returns thePrincipalFacade
instance.- Returns:
- The
PrincipalFacade
instance.
-
tryGetPrincipalFacade
Returns aTry
of thePrincipalFacade
instance.- Returns:
- A
Try
of thePrincipalFacade
instance.
-
setPrincipalFacade
Replaces the defaultPrincipalFacade
instance.- Parameters:
principalFacade
- An instance ofPrincipalFacade
. Usenull
to reset the facade to default.
-
getCurrentPrincipal
Returns the currentPrincipal
.- Returns:
- The current
Principal
. - Throws:
PrincipalAccessException
- If there is an issue while accessing thePrincipal
.
-
tryGetCurrentPrincipal
- Returns:
- A
Try
of the currentPrincipal
.
-
executeWithPrincipal
@Nullable public static <T> T executeWithPrincipal(@Nonnull Principal principal, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallable
on behalf of a given principal.- Type Parameters:
T
- The type of the callable.- Parameters:
principal
- The principal to execute on behalf of.callable
- The callable to execute.- Returns:
- The value computed by the callable.
- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the principal.
-
executeWithPrincipal
public static void executeWithPrincipal(@Nonnull Principal principal, @Nonnull Executable executable) throws ThreadContextExecutionException Execute the givenExecutable
on behalf of a given principal.- Parameters:
principal
- The principal to execute on behalf of.executable
- The executable to execute.- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the principal.
-
executeWithFallbackPrincipal
@Nullable public static <T> T executeWithFallbackPrincipal(@Nonnull Supplier<Principal> fallbackPrincipal, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallable
, using the given principal as fallback if there is no other principal available.- Type Parameters:
T
- The type of the callable.- Parameters:
fallbackPrincipal
- The principal to fall back to.callable
- The callable to execute.- Returns:
- The value computed by the callable.
- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the principal.
-
executeWithFallbackPrincipal
public static void executeWithFallbackPrincipal(@Nonnull Supplier<Principal> fallbackPrincipal, @Nonnull Executable executable) throws ThreadContextExecutionException Execute the givenExecutable
, using the given principal as fallback if there is no other principal available.- Parameters:
fallbackPrincipal
- The principal to fall back to.executable
- The executable to execute.- Throws:
ThreadContextExecutionException
- If there is an issue while running the code on behalf of the principal.
-
getFallbackPrincipal
Global fallbackPrincipal
. By default, no fallback is used, i.e., the fallback isnull
. A global fallback can be useful to ensure a safe fallback or to ease testing with a mocked principal. -
setFallbackPrincipal
Global fallbackPrincipal
. By default, no fallback is used, i.e., the fallback isnull
. A global fallback can be useful to ensure a safe fallback or to ease testing with a mocked principal.
-