Package com.atlassian.confluence.user
Enum AuthenticatedUserImpersonator
- java.lang.Object
-
- java.lang.Enum<AuthenticatedUserImpersonator>
-
- com.atlassian.confluence.user.AuthenticatedUserImpersonator
-
- All Implemented Interfaces:
Serializable
,Comparable<AuthenticatedUserImpersonator>
public enum AuthenticatedUserImpersonator extends Enum<AuthenticatedUserImpersonator>
Impersonates an authenticated user during the execution of the given callback.The authenticated user is stored on
a thread local variable
for theHTTP workers
. This variable is, amongst other things, used todetermine the locale
fori18n
.This behaviour makes sense for most cases. But if you want to e.g. render a Soy template for an email (on an HTTP worker) ahead of being sent, you'd want to set the locale to the recipient's locale. If the recipient is unknown to Confluence, you'd want the lookup to default to
the site's locale
instead of the sender's locale.- Since:
- 5.1.5
- See Also:
AuthenticatedUserThreadLocal
,UserThreadLocalFilter
,ConfluenceI18nResolver
,com.atlassian.soy.impl.GetTextFunction
,DefaultLocaleManager
-
-
Enum Constant Summary
Enum Constants Enum Constant Description REQUEST_AGNOSTIC
Use this instance if you'd want the thread to be agnostic of therequest cache
during the execution of the given callback.REQUEST_AWARE
Use this instance if you'd want the thread to be aware of therequest cache
during the execution of the given callback.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> T
asAnonymousUser(Callable<T> callback)
<T> T
asUser(Callable<T> callback, @Nullable com.atlassian.user.User user)
Impersonates the given user during the execution of the given callback.static AuthenticatedUserImpersonator
valueOf(String name)
Returns the enum constant of this type with the specified name.static AuthenticatedUserImpersonator[]
values()
Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
REQUEST_AWARE
public static final AuthenticatedUserImpersonator REQUEST_AWARE
Use this instance if you'd want the thread to be aware of therequest cache
during the execution of the given callback.This would mean that the
locale lookup
would fall back tothe Browser's locale
.- See Also:
RequestCacheThreadLocal
,RequestCacheThreadLocalFilter
-
REQUEST_AGNOSTIC
public static final AuthenticatedUserImpersonator REQUEST_AGNOSTIC
Use this instance if you'd want the thread to be agnostic of therequest cache
during the execution of the given callback.This would mean that the
locale lookup
would fall back to thethe site's locale
.- See Also:
RequestCacheThreadLocal
,RequestCacheThreadLocalFilter
-
-
Method Detail
-
values
public static AuthenticatedUserImpersonator[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (AuthenticatedUserImpersonator c : AuthenticatedUserImpersonator.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static AuthenticatedUserImpersonator valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is null
-
asAnonymousUser
public <T> T asAnonymousUser(Callable<T> callback)
- See Also:
asUser(Callable, User)
-
asUser
public <T> T asUser(Callable<T> callback, @Nullable com.atlassian.user.User user)
Impersonates the given user during the execution of the given callback.- Parameters:
callback
- the callback to be executeduser
- the user to be impersonated- Returns:
- the return value of the given callback
-
-