KickJava   Java API By Example, From Geeks To Geeks.

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


1 package org.jbpm.security.authenticator;
2
3 import java.security.AccessController JavaDoc;
4 import java.security.Principal JavaDoc;
5 import java.util.Set JavaDoc;
6
7 import javax.security.auth.Subject JavaDoc;
8
9 import org.jbpm.JbpmConfiguration;
10 import org.jbpm.instantiation.ClassLoaderUtil;
11
12 /**
13  * gets the authenticated actor id from the current Subject.
14  * This Authenticator requires another configuration parameter
15  * 'jbpm.authenticator.principal.classname'. This configuration property
16  * specifies the class name of the principal that should be used from
17  * the current subject. The name of that principal is used as the
18  * currently authenticated actorId.
19  */

20 public class SubjectAuthenticator implements Authenticator {
21   
22   private static final String JavaDoc principalClassName = JbpmConfiguration.getString("jbpm.authenticator.principal.classname");
23   private static Class JavaDoc principalClass = ClassLoaderUtil.loadClass(principalClassName);
24
25   public String JavaDoc getAuthenticatedActorId() {
26     String JavaDoc authenticatedActorId = null;
27     Subject JavaDoc subject = Subject.getSubject(AccessController.getContext());
28     Set JavaDoc principals = subject.getPrincipals(principalClass);
29     if ( (principals!=null)
30          && (!principals.isEmpty())
31        ) {
32       Principal JavaDoc principal = (Principal JavaDoc) principals.iterator().next();
33       authenticatedActorId = principal.getName();
34     }
35     return authenticatedActorId;
36   }
37 }
38
Popular Tags