1 23 24 29 30 package com.sun.enterprise.security.factory; 31 32 import java.util.ArrayList ; 33 import java.util.HashMap ; 34 import java.util.List ; 35 import java.util.Map ; 36 37 import com.sun.enterprise.SecurityManager; 38 import com.sun.enterprise.deployment.Descriptor; 39 import com.sun.enterprise.deployment.EjbDescriptor; 40 import com.sun.enterprise.security.application.EJBSecurityManager; 41 42 import java.util.logging.Level ; 43 47 public final class EJBSecurityManagerFactory 48 extends AbstractSecurityManagerFactory { 49 private Map CONTEXT_ID = new HashMap (); 50 51 52 private EJBSecurityManagerFactory() { 53 } 54 55 public static SecurityManagerFactory getInstance() { 56 if(_theFactory == null){ 57 _theFactory = (SecurityManagerFactory)new EJBSecurityManagerFactory(); 58 } 59 return _theFactory; 60 } 61 62 public SecurityManager getSecurityManager(String contextId){ 63 if (_poolHas(contextId)){ 64 return (SecurityManager )_poolGet(contextId); 65 } 66 return null; 67 } 68 69 public SecurityManager createSecurityManager(Descriptor descriptor) { 70 SecurityManager ejbSM = null; 71 String contextId = null; 72 String appName = null; 73 try { 74 ejbSM = EJBSecurityManager.getInstance(descriptor); 75 EjbDescriptor ejbdes = (EjbDescriptor) descriptor; 78 appName = ejbdes.getApplication().getRegistrationName(); 79 contextId = EJBSecurityManager.getContextID(ejbdes); 80 if(_logger.isLoggable(Level.FINE)){ 81 _logger.log(Level.FINE, 82 "[EJB-Security] EJB Security:Creating EJBSecurityManager for contextId = " 83 +contextId); 84 } 85 86 } catch (Exception e){ 87 _logger.log(Level.FINE, 88 "[EJB-Security] FATAl Exception. Unable to create EJBSecurityManager: " 89 + e.getMessage() ); 90 throw new RuntimeException (e); 91 } 92 93 synchronized (CONTEXT_ID) { 94 List lst = (List )CONTEXT_ID.get(appName); 95 if(lst == null){ 96 lst = new ArrayList (); 97 CONTEXT_ID.put(appName, lst); 98 } 99 if (!lst.contains(contextId)) { 100 lst.add(contextId); 101 } 102 } 103 104 _poolPut(contextId, ejbSM); 105 return ejbSM; 106 } 107 108 public String [] getAndRemoveContextIdForEjbAppName(String appName){ 109 synchronized(CONTEXT_ID) { 110 List contextId = (List ) CONTEXT_ID.get(appName); 111 if (contextId == null) { 112 return null; 113 } 114 String [] rvalue = new String [contextId.size()]; 115 rvalue = (String [])contextId.toArray(rvalue); 116 117 CONTEXT_ID.remove(appName); 118 return rvalue; 119 } 120 } 121 } 122 | Popular Tags |