FileDocCategorySizeDatePackage
EJBSecurityManagerFactory.javaAPI DocGlassfish v2 API5578Fri May 04 22:35:32 BST 2007com.sun.enterprise.security.factory

EJBSecurityManagerFactory

public final class EJBSecurityManagerFactory extends AbstractSecurityManagerFactory
EJB Security Manager Factory Implementation
author
Harpreet Singh

Fields Summary
private static final ReadWriteLock
rwLock
private static SecurityManagerFactory
_theFactory
private Map
CONTEXT_ID
Constructors Summary
private EJBSecurityManagerFactory()
Creates a new instance of EJBSecurityManagerFactory


           
      
    
Methods Summary
public com.sun.enterprise.SecurityManagercreateSecurityManager(com.sun.enterprise.deployment.Descriptor descriptor)

        SecurityManager ejbSM = null;
        String contextId = null;
        String appName = null;
        try {
            ejbSM = EJBSecurityManager.getInstance(descriptor);
            // if the descriptor is not a EjbDescriptor the EJBSM will 
            // throw an exception. So the following will always work.
            EjbDescriptor ejbdes = (EjbDescriptor) descriptor;
            appName = ejbdes.getApplication().getRegistrationName();
            contextId = EJBSecurityManager.getContextID(ejbdes);
            if(_logger.isLoggable(Level.FINE)){
                _logger.log(Level.FINE,
                "[EJB-Security] EJB Security:Creating EJBSecurityManager for contextId = "
                +contextId);
            }

        } catch (Exception e){
            _logger.log(Level.FINE,
            "[EJB-Security] FATAl Exception. Unable to create EJBSecurityManager: "
            + e.getMessage() );
            throw new RuntimeException(e);
        } 

	synchronized (CONTEXT_ID) {
	    List lst = (List)CONTEXT_ID.get(appName);
	    if(lst == null){
		lst = new ArrayList();
		CONTEXT_ID.put(appName, lst);
	    }
	    if (!lst.contains(contextId)) {
		lst.add(contextId);
	    }
	}

        _poolPut(contextId, ejbSM);
        return ejbSM;     
    
public java.lang.String[]getAndRemoveContextIdForEjbAppName(java.lang.String appName)

	synchronized(CONTEXT_ID) {
            List contextId = (List) CONTEXT_ID.get(appName);
            if (contextId == null) {
                return null;
            }
            String[] rvalue = new String[contextId.size()];
            rvalue = (String[])contextId.toArray(rvalue);

	    CONTEXT_ID.remove(appName);
	    return rvalue;
	}
    
public static SecurityManagerFactorygetInstance()

        try {
            rwLock.readLock().lock();
            if (_theFactory != null) {
                return _theFactory;
            }
        } finally {
            rwLock.readLock().unlock();
        }

        try {
            rwLock.writeLock().lock();
            if (_theFactory == null) {
                _theFactory =
                    (SecurityManagerFactory)new EJBSecurityManagerFactory();
            }
            return _theFactory;
        } finally {
            rwLock.writeLock().unlock();
        }
    
public com.sun.enterprise.SecurityManagergetSecurityManager(java.lang.String contextId)

            
        if (_poolHas(contextId)){
            return (SecurityManager)_poolGet(contextId);
        }
        return null;