Class OAuthIdentity
- All Implemented Interfaces:
Serializable
OAuthFilter class.
This class is concrete and can be instantiated as is since 1.13.0.
This class MUST no to be subclassed and will be marked final in a future release.
- Since:
- 1.3.0
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceOAuthIdentity.ImpersonationCallable<V,X extends Exception> A callable that throws a specific type of exception and that is to execute on behalf of a functional user. -
Constructor Summary
ConstructorsConstructorDescriptionOAuthIdentity(Person user) Creates a new identity instance for the specified user. -
Method Summary
Modifier and TypeMethodDescriptionstatic final <V,X extends Exception>
VexecuteImpersonated(Person functionalUser, OAuthIdentity.ImpersonationCallable<V, X> callable) Executes a callable on behalf of the given functional user.static Optional<OAuthIdentity> Returns the OAuth identity associated to the current thread, if any.getUser()Returns the authenticated user.static OAuthIdentityReturns the OAuth identityassociatedto the current thread.static voidsetThreadInstance(OAuthIdentity identity) Sets an OAuth identity to associate to the current thread.
-
Constructor Details
-
OAuthIdentity
Creates a new identity instance for the specified user.- Parameters:
user- the user who has authenticated.Cluster-compatible applications must NOT use a subclass of
Person.- Throws:
NullPointerException- ifuserisnull.
-
-
Method Details
-
getThreadInstance
Returns the OAuth identity associated to the current thread, if any.If a servlet request was
associatedto the current thread at the time the identity wasregistered, both objects are considered linked and sharing the same validity period. When the servlet request is no longer valid, i.e. when the servlet execution completed, the corresponding identity is also considered invalid and this method returns an empty optional.Caller may rather use
requireThreadInstance()if an identity is required to be present.- Returns:
- an identity if user is authenticated, an empty optional otherwise.
- Since:
- 4.0.0
- See Also:
-
requireThreadInstance
Returns the OAuth identityassociatedto the current thread. Throws an exception if called from a thread with no associated identity, e.g. when user has not yet authenticated in the current servlet request.Caller may use
getThreadInstance()if it uncertain an OAuth identity is present.- Returns:
- the identity of the authenticated user
- Throws:
IllegalStateException- if no OAuth identity is set for current thread- Since:
- 4.0.0
- See Also:
-
setThreadInstance
Sets an OAuth identity to associate to the current thread.If a servlet request is
associatedto the current thread at the time the method is called, both objects are considered linked and sharing the same validity period. When the servlet request is no longer valid, i.e. when the servlet execution completed, the corresponding identity is also considered invalid andgetThreadInstance()returns an empty optional.- Parameters:
identity- an OAuth identity,nullif there's no longer an identity for this thread
-
executeImpersonated
public static final <V,X extends Exception> V executeImpersonated(Person functionalUser, OAuthIdentity.ImpersonationCallable<V, X> callable) throws XExecutes a callable on behalf of the given functional user. Impersonation makes the functional user to become theOAuth identityof current thread for the lifetime of this method call. The servlet request possiblyassociatedto the current thread has no impact on the behavior of this method.- Type Parameters:
V- the result type of methodcallX- the type of exception potentially raised by the callable execution- Parameters:
functionalUser- the functional usercallable- the code to execute on behalf of the functional user- Returns:
- the result of
OAuthIdentity.ImpersonationCallable.call() - Throws:
X- if the callable throws such exception- Since:
- 4.2.0
-
getUser
Returns the authenticated user.- Returns:
- the authenticated user.
-