mirror of https://github.com/apache/cloudstack.git
Cleanup UserContext after execution for better security
This commit is contained in:
parent
319ae4e6b2
commit
244d8c198b
|
|
@ -20,7 +20,6 @@ package com.cloud.user;
|
|||
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.utils.component.ComponentLocator;
|
||||
|
||||
|
||||
public class UserContext {
|
||||
|
||||
|
|
@ -81,11 +80,18 @@ public class UserContext {
|
|||
}
|
||||
|
||||
public static UserContext current() {
|
||||
UserContext context = s_currentContext.get();
|
||||
if (context == null) {
|
||||
UserContext context = s_currentContext.get();
|
||||
if(context == null) {
|
||||
//
|
||||
// TODO: we should enforce explicit UserContext setup at major entry-points for security concerns,
|
||||
// however, there are many places that run background jobs assume the system context.
|
||||
//
|
||||
// If there is a security concern, all entry points from user (including the front end that takes HTTP request in and
|
||||
// the core async-job manager that runs commands from user) have explicitly setup the UserContext.
|
||||
//
|
||||
return s_adminContext;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
public static void updateContext(long userId, Account accountObject, String sessionId) {
|
||||
|
|
@ -101,8 +107,8 @@ public class UserContext {
|
|||
s_currentContext.set(new UserContext(userId, accountObject, sessionId, apiServer));
|
||||
}
|
||||
|
||||
public static void unregisterContext() {
|
||||
s_currentContext.set(null);
|
||||
public static void unregisterContext() {
|
||||
s_currentContext.set(null);
|
||||
}
|
||||
|
||||
public void setStartEventId(long startEventId) {
|
||||
|
|
@ -120,5 +126,4 @@ public class UserContext {
|
|||
public void setAccountId(long accountId) {
|
||||
this.accountId = accountId;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -380,12 +380,15 @@ public class AsyncJobManagerImpl implements AsyncJobManager, ClusterManagerListe
|
|||
}
|
||||
|
||||
UserContext.registerContext(userId, accountObject, null, false);
|
||||
|
||||
// dispatch could ultimately queue the job
|
||||
_dispatcher.dispatch(cmdObj, params);
|
||||
|
||||
// serialize this to the async job table
|
||||
completeAsyncJob(jobId, AsyncJobResult.STATUS_SUCCEEDED, 0, cmdObj.getResponseObject());
|
||||
try {
|
||||
// dispatch could ultimately queue the job
|
||||
_dispatcher.dispatch(cmdObj, params);
|
||||
|
||||
// serialize this to the async job table
|
||||
completeAsyncJob(jobId, AsyncJobResult.STATUS_SUCCEEDED, 0, cmdObj.getResponseObject());
|
||||
} finally {
|
||||
UserContext.unregisterContext();
|
||||
}
|
||||
|
||||
// commands might need to be queued as part of synchronization here, so they just have to be re-dispatched from the queue mechanism...
|
||||
if (job.getSyncSource() != null) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue