public class ThreadLocalUserProvider extends Object implements UserProvider
UserProvider is very useful if authentication has been implemented using a servlet
filter. It allows to store the current user in a ThreadLocal for the active thread. See the following code for an
example for how to user this class.
FeatureUser user = ....
ThreadLocalFeatureUserProvider.bind(user);
try {
chain.doFilter(request, response);
} finally {
ThreadLocalFeatureUserProvider.release();
}
Please not that it is very important to remove the user from the provider after| Constructor and Description |
|---|
ThreadLocalUserProvider() |
| Modifier and Type | Method and Description |
|---|---|
static void |
bind(FeatureUser featureUser)
Store the supplied FeatureUser in the thread context.
|
FeatureUser |
getCurrentUser()
Return a
FeatureUser instance representing the current user. |
static void |
release()
Removes the user associated with the current thread from the thread's context.
|
public static void bind(FeatureUser featureUser)
getCurrentUser()
from the active thread will return this feature user. Please don't forget to call release() before the thread is
put back to a thread pool to prevent memory leaks.featureUser - The feature user to storepublic static void release()
public FeatureUser getCurrentUser()
UserProviderFeatureUser instance representing the current user. This method should return null if the
implementation is unable to determine the user.getCurrentUser in interface UserProvidernullCopyright © 2018. All Rights Reserved.