KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > plugins > SecurityDomainContext


1 /*
2 * JBoss, the OpenSource J2EE webOS
3 *
4 * Distributable under LGPL license.
5 * See terms of license at gnu.org.
6 */

7 package org.jboss.security.plugins;
8
9 import javax.naming.InvalidNameException JavaDoc;
10 import javax.naming.NamingException JavaDoc;
11 import javax.security.auth.Subject JavaDoc;
12
13 import org.jboss.security.RealmMapping;
14 import org.jboss.security.AuthenticationManager;
15 import org.jboss.security.SubjectSecurityManager;
16 import org.jboss.util.CachePolicy;
17
18 /** An encapsulation of the JNDI security context infomation
19  *
20  * @author Scott.Stark@jboss.org
21  * @version
22  */

23 public class SecurityDomainContext
24 {
25    static final String JavaDoc ACTIVE_SUBJECT = "subject";
26    static final String JavaDoc AUTHENTICATION_MGR = "securityMgr";
27    static final String JavaDoc AUTORIZATION_MGR = "realmMapping";
28    static final String JavaDoc AUTH_CACHE = "authenticationCache";
29
30    AuthenticationManager securityMgr;
31    CachePolicy authenticationCache;
32
33    /** Creates new SecurityDomainContextHandler */
34    public SecurityDomainContext(AuthenticationManager securityMgr, CachePolicy authenticationCache)
35    {
36       this.securityMgr = securityMgr;
37       this.authenticationCache = authenticationCache;
38    }
39
40    public Object JavaDoc lookup(String JavaDoc name) throws NamingException JavaDoc
41    {
42       Object JavaDoc binding = null;
43       if( name == null || name.length() == 0 )
44          throw new InvalidNameException JavaDoc("name cannot be null or empty");
45
46       if( name.equals(ACTIVE_SUBJECT) )
47          binding = getSubject();
48       else if( name.equals(AUTHENTICATION_MGR) )
49          binding = securityMgr;
50       else if( name.equals(AUTORIZATION_MGR) )
51          binding = getRealmMapping();
52       else if( name.equals(AUTH_CACHE) )
53          binding = authenticationCache;
54       return binding;
55    }
56    public Subject JavaDoc getSubject()
57    {
58       Subject JavaDoc subject = null;
59       if( securityMgr instanceof SubjectSecurityManager )
60       {
61          subject = ((SubjectSecurityManager)securityMgr).getActiveSubject();
62       }
63       return subject;
64    }
65    public AuthenticationManager getSecurityManager()
66    {
67       return securityMgr;
68    }
69    public RealmMapping getRealmMapping()
70    {
71       RealmMapping realmMapping = null;
72       if( securityMgr instanceof RealmMapping )
73       {
74          realmMapping = (RealmMapping)securityMgr;
75       }
76       return realmMapping;
77    }
78    public CachePolicy getAuthenticationCache()
79    {
80       return authenticationCache;
81    }
82
83 }
84
Popular Tags