mirror of https://github.com/apache/cloudstack.git
UserContext: Threadsafe singleton, inject using ComponentContext, spring di failsafe
Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
parent
b6f780fa33
commit
b63b7ddf60
|
|
@ -16,12 +16,10 @@
|
|||
// under the License.
|
||||
package com.cloud.user;
|
||||
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
public class UserContext {
|
||||
@Inject AccountService _accountMgr;
|
||||
|
||||
private static ThreadLocal<UserContext> s_currentContext = new ThreadLocal<UserContext>();
|
||||
|
||||
private long userId;
|
||||
|
|
@ -30,9 +28,10 @@ public class UserContext {
|
|||
private long startEventId = 0;
|
||||
private long accountId;
|
||||
private String eventDetails;
|
||||
|
||||
private boolean apiServer;
|
||||
|
||||
@Inject private AccountService _accountMgr = null;
|
||||
|
||||
public UserContext() {
|
||||
}
|
||||
|
||||
|
|
@ -48,6 +47,9 @@ public class UserContext {
|
|||
}
|
||||
|
||||
public User getCallerUser() {
|
||||
if (_accountMgr == null) {
|
||||
_accountMgr = ComponentContext.getComponent(AccountService.class);
|
||||
}
|
||||
return _accountMgr.getActiveUser(userId);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue