1 7 package org.jboss.security.plugins; 8 9 import javax.naming.InvalidNameException ; 10 import javax.naming.NamingException ; 11 import javax.security.auth.Subject ; 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 23 public class SecurityDomainContext 24 { 25 static final String ACTIVE_SUBJECT = "subject"; 26 static final String AUTHENTICATION_MGR = "securityMgr"; 27 static final String AUTORIZATION_MGR = "realmMapping"; 28 static final String AUTH_CACHE = "authenticationCache"; 29 30 AuthenticationManager securityMgr; 31 CachePolicy authenticationCache; 32 33 34 public SecurityDomainContext(AuthenticationManager securityMgr, CachePolicy authenticationCache) 35 { 36 this.securityMgr = securityMgr; 37 this.authenticationCache = authenticationCache; 38 } 39 40 public Object lookup(String name) throws NamingException 41 { 42 Object binding = null; 43 if( name == null || name.length() == 0 ) 44 throw new InvalidNameException ("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 getSubject() 57 { 58 Subject 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 |