Class PrincipalAccessor
java.lang.Object
com.sap.cloud.sdk.cloudplatform.security.principal.PrincipalAccessor
Accessor for retrieving the current
Principal.-
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecuteWithFallbackPrincipal(Supplier<Principal> fallbackPrincipal, Executable executable) Execute the givenExecutable, using the given principal as fallback if there is no other principal available.static <T> TexecuteWithFallbackPrincipal(Supplier<Principal> fallbackPrincipal, Callable<T> callable) Execute the givenCallable, using the given principal as fallback if there is no other principal available.static voidexecuteWithPrincipal(Principal principal, Executable executable) Execute the givenExecutableon behalf of a given principal.static <T> TexecuteWithPrincipal(Principal principal, Callable<T> callable) Execute the givenCallableon behalf of a given principal.static PrincipalReturns the currentPrincipal.Global fallbackPrincipal.static PrincipalFacadeReturns thePrincipalFacadeinstance.static voidsetFallbackPrincipal(Supplier<Principal> fallbackPrincipal) Global fallbackPrincipal.static voidsetPrincipalFacade(PrincipalFacade principalFacade) Replaces the defaultPrincipalFacadeinstance.static io.vavr.control.Try<Principal>static io.vavr.control.Try<PrincipalFacade>Returns aTryof thePrincipalFacadeinstance.
-
Method Details
-
getPrincipalFacade
Returns thePrincipalFacadeinstance.- Returns:
- The
PrincipalFacadeinstance.
-
tryGetPrincipalFacade
Returns aTryof thePrincipalFacadeinstance.- Returns:
- A
Tryof thePrincipalFacadeinstance.
-
setPrincipalFacade
Replaces the defaultPrincipalFacadeinstance.- Parameters:
principalFacade- An instance ofPrincipalFacade. Usenullto 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
Tryof the currentPrincipal.
-
executeWithPrincipal
@Nullable public static <T> T executeWithPrincipal(@Nonnull Principal principal, @Nonnull Callable<T> callable) throws ThreadContextExecutionException Execute the givenCallableon 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 givenExecutableon 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.
-