Class AuthenticatedRequest
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDetermines the current user principal and how to interpret that principal to extract user identity and allowed accounts. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <V> VallowAnonymous(Callable<V> closure) Allow a given HTTP call to be anonymous.static voidclear()get(com.netflix.spinnaker.kork.common.Header header) Returns or creates a spinnaker request ID.static <V> Callable<V>Propagates the current users authentication context when for the supplied actionstatic <V> Callable<V>Propagates the current users authentication context when for the supplied actionstatic <V> Callable<V>Deprecated.use runAs instead to switch to a different userstatic <V> Callable<V>Deprecated.use runAs instead to switch to a different userstatic <V> Callable<V>Prepare an authentication context to run as the supplied user wrapping the supplied actionstatic <V> Callable<V>runAs(String username, Collection<String> allowedAccounts, boolean restoreOriginalContext, Callable<V> closure) Prepare an authentication context to run as the supplied user wrapping the supplied actionstatic <V> Callable<V>runAs(String username, Collection<String> allowedAccounts, Callable<V> closure) Prepare an authentication context to run as the supplied user wrapping the supplied actionstatic <V> Callable<V>Prepare an authentication context to run as the supplied user wrapping the supplied actionstatic voidstatic voidstatic voidsetAccounts(String accounts) static voidsetApplication(String value) static voidsetExecutionId(String value) static voidsetExecutionType(String value) static voidsetPrincipalExtractor(AuthenticatedRequest.PrincipalExtractor principalExtractor) Replaces the PrincipalExtractor for ALL callers of AutheticatedRequest.static voidsetRequestId(String value) static voidstatic voidsetUserOrigin(String value)
-
Constructor Details
-
AuthenticatedRequest
public AuthenticatedRequest()
-
-
Method Details
-
setPrincipalExtractor
public static void setPrincipalExtractor(AuthenticatedRequest.PrincipalExtractor principalExtractor) Replaces the PrincipalExtractor for ALL callers of AutheticatedRequest.This is a gross and terrible thing, and exists because we made everything in AuthenticatedRequest static. This exists as a terrible DI mechanism to support supplying a different opinion on how to pull details from the current user principal, and should only be called at app initialization time to inject that opinion.
- Parameters:
principalExtractor- the PrincipalExtractor to use for AuthenticatedRequest.
-
allowAnonymous
Allow a given HTTP call to be anonymous. Normally, all requests to Spinnaker services should be authenticated (i.e. include USER & ACCOUNTS HTTP headers). However, in specific cases it is necessary to make an anonymous call. If an anonymous call is made that is not wrapped in this method, it will result in a log message and a metric being logged (indicating a potential bug). Use this method to avoid the log and metric. To make an anonymous call wrap it in this function, e.g.AuthenticatedRequest.allowAnonymous(() -> { // do HTTP call here }); -
runAs
Prepare an authentication context to run as the supplied user wrapping the supplied actionThe original authentication context is restored after the action completes.
- Type Parameters:
V- the return type of the supplied action- Parameters:
username- the username to run asclosure- the action to run as the user- Returns:
- an action that will run the supplied action as the supplied user
-
runAs
public static <V> Callable<V> runAs(String username, boolean restoreOriginalContext, Callable<V> closure) Prepare an authentication context to run as the supplied user wrapping the supplied action- Type Parameters:
V- the return type of the supplied action- Parameters:
username- the username to run asrestoreOriginalContext- whether the original authentication context should be restored after the action completesclosure- the action to run as the user- Returns:
- an action that will run the supplied action as the supplied user
-
runAs
public static <V> Callable<V> runAs(String username, Collection<String> allowedAccounts, Callable<V> closure) Prepare an authentication context to run as the supplied user wrapping the supplied actionThe original authentication context is restored after the action completes.
- Type Parameters:
V- the return type of the supplied action- Parameters:
username- the username to run asallowedAccounts- the allowed accounts for the user as an authorization fallbackclosure- the action to run as the user- Returns:
- an action that will run the supplied action as the supplied user
-
runAs
public static <V> Callable<V> runAs(String username, Collection<String> allowedAccounts, boolean restoreOriginalContext, Callable<V> closure) Prepare an authentication context to run as the supplied user wrapping the supplied action- Type Parameters:
V- the return type of the supplied action- Parameters:
username- the username to run asallowedAccounts- the allowed accounts for the user as an authorization fallbackrestoreOriginalContext- whether the original authentication context should be restored after the action completesclosure- the action to run as the user- Returns:
- an action that will run the supplied action as the supplied user
-
propagate
Propagates the current users authentication context when for the supplied actionThe original authentication context is restored after the action completes.
- Type Parameters:
V- the return type of the supplied action- Parameters:
closure- the action to run- Returns:
- an action that will run propagating the current users authentication context
-
propagate
Propagates the current users authentication context when for the supplied action- Type Parameters:
V- the return type of the supplied action- Parameters:
closure- the action to runrestoreOriginalContext- whether the original authentication context should be restored after the action completes- Returns:
- an action that will run propagating the current users authentication context
-
propagate
Deprecated.use runAs instead to switch to a different user -
propagate
@Deprecated public static <V> Callable<V> propagate(Callable<V> closure, boolean restoreOriginalContext, Object principal) Deprecated.use runAs instead to switch to a different user -
getAuthenticationHeaders
-
getSpinnakerUser
-
getSpinnakerAccounts
-
getSpinnakerRequestId
Returns or creates a spinnaker request ID.If a request ID already exists, it will be propagated without change. If a request ID does not already exist:
1. If an execution ID exists, it will create a hierarchical request ID using the execution ID, followed by a UUID. 2. If an execution ID does not exist, it will create a simple UUID request id.
-
getSpinnakerExecutionType
-
getSpinnakerUserOrigin
-
getSpinnakerExecutionId
-
getSpinnakerApplication
-
get
-
get
-
setAccounts
-
setUser
-
setUserOrigin
-
setRequestId
-
setExecutionId
-
setApplication
-
setExecutionType
-
set
-
set
-
clear
public static void clear()
-