KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jbpm > security > authenticator > JbpmDefaultAuthenticator


1 package org.jbpm.security.authenticator;
2
3 import java.util.LinkedList JavaDoc;
4
5 /**
6  * maintains a thread local stack of actorId's, the authenticated
7  * actorId is the first one on the stack. Use {@link #pushAuthenticatedActorId(String)}
8  * and {@link #popAuthenticatedActorId()} to manage the stack in a
9  * try-finally block.
10  */

11 public class JbpmDefaultAuthenticator implements Authenticator {
12
13   static ThreadLocal JavaDoc authenticatedActorIdStack = new ThreadLocal JavaDoc();
14   
15   public static void pushAuthenticatedActorId(String JavaDoc actorId) {
16     LinkedList JavaDoc stack = (LinkedList JavaDoc) authenticatedActorIdStack.get();
17     if (stack==null) {
18       stack = new LinkedList JavaDoc();
19       authenticatedActorIdStack.set(stack);
20     }
21     stack.addFirst(actorId);
22   }
23   
24   public String JavaDoc getAuthenticatedActorId() {
25     String JavaDoc authenticatedActorId = null;
26     LinkedList JavaDoc stack = (LinkedList JavaDoc) authenticatedActorIdStack.get();
27     if ( (stack!=null)
28          && (!stack.isEmpty())
29        ) {
30       authenticatedActorId = (String JavaDoc) stack.getFirst();
31     }
32     return authenticatedActorId;
33   }
34
35   public static void popAuthenticatedActorId() {
36     LinkedList JavaDoc stack = (LinkedList JavaDoc) authenticatedActorIdStack.get();
37     stack.removeFirst();
38   }
39 }
40
Popular Tags