summaryrefslogtreecommitdiffstats
path: root/base/common/src/com/netscape/certsrv/base
diff options
context:
space:
mode:
authorEndi S. Dewata <edewata@redhat.com>2015-04-21 16:29:45 -0400
committerEndi S. Dewata <edewata@redhat.com>2015-05-05 15:16:12 -0400
commitcb32779617947a16a0bfdc519a5ecbd0ae7019aa (patch)
treec494909409b00b53a43acacc0bcef9b931bc5474 /base/common/src/com/netscape/certsrv/base
parent31d96e0ba756fd05bad0c9a577bf27ef9041d490 (diff)
downloadpki-cb32779617947a16a0bfdc519a5ecbd0ae7019aa.tar.gz
pki-cb32779617947a16a0bfdc519a5ecbd0ae7019aa.tar.xz
pki-cb32779617947a16a0bfdc519a5ecbd0ae7019aa.zip
Fixed authentication data in audit log.
The REST methods may be executed by different threads even though they are invoked in the same session. A new interceptor has been added to all subsystems to make sure the SessionContext is created properly for each thread. This will fix the authentication data in the audit log. The SessionContext has also been improved to use ThreadLocal instead of a global Hashtable. https://fedorahosted.org/pki/ticket/1054
Diffstat (limited to 'base/common/src/com/netscape/certsrv/base')
-rw-r--r--base/common/src/com/netscape/certsrv/base/SessionContext.java42
1 files changed, 9 insertions, 33 deletions
diff --git a/base/common/src/com/netscape/certsrv/base/SessionContext.java b/base/common/src/com/netscape/certsrv/base/SessionContext.java
index 79b75508f..81debaee8 100644
--- a/base/common/src/com/netscape/certsrv/base/SessionContext.java
+++ b/base/common/src/com/netscape/certsrv/base/SessionContext.java
@@ -82,26 +82,12 @@ public class SessionContext extends Hashtable<Object, Object> {
*/
public static final String IPADDRESS = "ipAddress";
- private static Hashtable<Thread, SessionContext> mContexts = new Hashtable<Thread, SessionContext>();
+ private static ThreadLocal<SessionContext> instance = new ThreadLocal<SessionContext>();
/**
* Constructs a session context.
*/
public SessionContext() {
- super();
- }
-
- /**
- * Creates a new context and associates it with
- * the current thread. If the current thread is
- * also associated with a old context, the old
- * context will be replaced.
- */
- private static SessionContext createContext() {
- SessionContext sc = new SessionContext();
-
- setContext(sc);
- return sc;
}
/**
@@ -114,7 +100,7 @@ public class SessionContext extends Hashtable<Object, Object> {
* @param sc session context
*/
public static void setContext(SessionContext sc) {
- mContexts.put(Thread.currentThread(), sc);
+ instance.set(sc);
}
/**
@@ -125,12 +111,12 @@ public class SessionContext extends Hashtable<Object, Object> {
* @return sesssion context
*/
public static SessionContext getContext() {
- SessionContext sc = mContexts.get(Thread.currentThread());
-
- if (sc == null) {
- sc = createContext();
+ SessionContext context = instance.get();
+ if (context == null) {
+ context = new SessionContext();
+ instance.set(context);
}
- return sc;
+ return context;
}
/**
@@ -141,23 +127,13 @@ public class SessionContext extends Hashtable<Object, Object> {
* @return sesssion context
*/
public static SessionContext getExistingContext() {
- SessionContext sc = mContexts.get(Thread.currentThread());
-
- if (sc == null) {
- return null;
- }
-
- return sc;
+ return instance.get();
}
/**
* Releases the current session context.
*/
public static void releaseContext() {
- SessionContext sc = mContexts.get(Thread.currentThread());
-
- if (sc != null) {
- mContexts.remove(Thread.currentThread());
- }
+ instance.set(null);
}
}