View Javadoc
1   package com.atlassian.refapp.sal.executor;
2   
3   import com.atlassian.plugin.spring.scanner.annotation.export.ExportAsService;
4   import com.atlassian.sal.api.executor.ThreadLocalContextManager;
5   import com.atlassian.seraph.auth.AuthenticationContext;
6   
7   import javax.inject.Inject;
8   import javax.inject.Named;
9   import java.security.Principal;
10  
11  @ExportAsService
12  @Named("refimplThreadLocalContextManager")
13  public class RefimplThreadLocalContextManager implements ThreadLocalContextManager<Principal> {
14      private final AuthenticationContext authenticationContext;
15  
16      @Inject
17      public RefimplThreadLocalContextManager(AuthenticationContext authenticationContext) {
18          this.authenticationContext = authenticationContext;
19      }
20  
21      /**
22       * Get the thread local context of the current thread
23       *
24       * @return The thread local context
25       */
26      public Principal getThreadLocalContext() {
27          return authenticationContext.getUser();
28      }
29  
30      /**
31       * Set the thread local context on the current thread
32       *
33       * @param context The context to set
34       */
35      public void setThreadLocalContext(Principal context) {
36          authenticationContext.setUser(context);
37      }
38  
39      /**
40       * Clear the thread local context on the current thread
41       */
42      public void clearThreadLocalContext() {
43          authenticationContext.setUser(null);
44      }
45  }