FileDocCategorySizeDatePackage
ConfigHelper.javaAPI DocGlassfish v2 API13777Tue Jul 24 05:01:34 BST 2007com.sun.enterprise.security.jmac.config

ConfigHelper

public abstract class ConfigHelper extends Object
This is based Helper class for 196 Configuration. This class implements RegistrationListener.

Fields Summary
private static final String
DEFAULT_HANDLER_CLASS
private static String
handlerClassName
protected static final javax.security.auth.message.config.AuthConfigFactory
factory
private ReadWriteLock
rwLock
private Lock
rLock
private Lock
wLock
protected String
layer
protected String
appCtxt
protected Map
map
protected CallbackHandler
cbh
protected AuthConfigRegistrationWrapper
listenerWrapper
Constructors Summary
Methods Summary
public voiddisable()

	listenerWrapper.disable();
    
public java.lang.StringgetAppContextID()

	return appCtxt;
    
protected javax.security.auth.message.config.AuthConfiggetAuthConfig(javax.security.auth.message.config.AuthConfigProvider p, boolean isServer)

	AuthConfig c = null; 
	if (p != null) {
	    if (isServer) { 
		c = p.getServerAuthConfig(layer, appCtxt, cbh);
	    } else {
		c = p.getClientAuthConfig(layer, appCtxt, cbh);
	    }
	}
	return c;
    
protected javax.security.auth.message.config.AuthConfiggetAuthConfig(boolean isServer)


	ConfigData d = null;
	AuthConfig c = null;
	boolean disabled = false;
	AuthConfigProvider lastP = null;

	try {
	    rLock.lock();
	    disabled = (!listenerWrapper.isEnabled());
	    if (!disabled) {
                d = listenerWrapper.getConfigData();
		if (d != null) {
		    c = (isServer ? d.sConfig : d.cConfig);
		    lastP = d.provider;
		}
	    }
	    
	} finally {
	    rLock.unlock();
	    if (disabled || c != null || (d != null && lastP == null)) {
		return c;
	    }
	} 


	// d == null || (d != null && lastP != null && c == null)
	if (d == null) {
	    try {
		wLock.lock();
                if (listenerWrapper.getConfigData()== null) {
                    AuthConfigProvider nextP =
                        factory.getConfigProvider(layer,appCtxt,this.getRegistrationListener());
                    if (nextP != null) {
                        listenerWrapper.setConfigData(new ConfigData(nextP,getAuthConfig(nextP,isServer)));
                    } else {
                        listenerWrapper.setConfigData(new ConfigData());
                    }
                }
                d = listenerWrapper.getConfigData();
	    } finally {
		wLock.unlock();
	    }
	} 

        return ((isServer)? d.sConfig : d.cConfig);
    
private javax.security.auth.callback.CallbackHandlergetCallbackHandler()
Get the callback default handler


        CallbackHandler rvalue = AuthMessagePolicy.getDefaultCallbackHandler();
        if (rvalue instanceof CallbackHandlerConfig) {
            ((CallbackHandlerConfig)rvalue).setHandlerContext
                    (getHandlerContext(map));
        }

        return rvalue;
    
public javax.security.auth.message.config.ClientAuthConfiggetClientAuthConfig()

        return (ClientAuthConfig)getAuthConfig(false);
    
public javax.security.auth.message.config.ClientAuthContextgetClientAuthContext(javax.security.auth.message.MessageInfo info, javax.security.auth.Subject s)

	ClientAuthConfig c = (ClientAuthConfig)getAuthConfig(false);
	if (c != null) {
	    return c.getAuthContext(c.getAuthContextID(info),s,map);
	}
	return null;
    
protected com.sun.enterprise.security.jmac.config.HandlerContextgetHandlerContext(java.util.Map map)
This method is invoked by the constructor and should be overrided by subclass.

        return null;
    
public java.lang.ObjectgetProperty(java.lang.String key)

	return map == null ? null : map.get(key);
    
public AuthConfigRegistrationWrapper.AuthConfigRegistrationListenergetRegistrationListener()

        return this.listenerWrapper.getListener();
    
public com.sun.enterprise.security.jmac.config.ConfigHelper$AuthConfigRegistrationWrappergetRegistrationWrapper()

        return this.listenerWrapper;
    
public javax.security.auth.message.config.ServerAuthConfiggetServerAuthConfig()

        return (ServerAuthConfig)getAuthConfig(true);
    
public javax.security.auth.message.config.ServerAuthContextgetServerAuthContext(javax.security.auth.message.MessageInfo info, javax.security.auth.Subject s)

	ServerAuthConfig c = (ServerAuthConfig)getAuthConfig(true);
	if (c != null) {
	    return c.getAuthContext(c.getAuthContextID(info),s,map);
	}
	return null;
    
protected booleanhasExactMatchAuthProvider()
Check if there is a provider register for a given layer and appCtxt.

        boolean exactMatch = false;
        // XXX this may need to be optimized
        AuthConfigProvider p = 
                factory.getConfigProvider(layer, appCtxt, null);
        if (p != null) {
            String[] IDs = factory.getRegistrationIDs(p);
            for (String i : IDs) {
                RegistrationContext c = factory.getRegistrationContext(i);
                if (layer.equals(c.getMessageLayer()) && 
                        appCtxt.equals(c.getAppContext())) {
                    exactMatch = true;
                    break;
                }
            }
        }

        return exactMatch;
    
protected voidinit(java.lang.String layer, java.lang.String appContext, java.util.Map map, javax.security.auth.callback.CallbackHandler cbh)


         
                

	this.layer = layer;
	this.appCtxt = appContext;
	this.map = map;
	this.cbh = cbh;
        if (this.cbh == null) {
            this.cbh = getCallbackHandler();
        }

	this.rwLock = new ReentrantReadWriteLock(true);
        this.rLock = rwLock.readLock();
        this.wLock = rwLock.writeLock();
        
        listenerWrapper =  new  AuthConfigRegistrationWrapper(this.layer, this.appCtxt);
        
    
public voidsetJmacProviderRegisID(java.lang.String jmacProviderRegisID)

        this.listenerWrapper.setJmacProviderRegisID(jmacProviderRegisID);
    
public voidsetRegistrationWrapper(com.sun.enterprise.security.jmac.config.ConfigHelper$AuthConfigRegistrationWrapper wrapper)

        this.listenerWrapper = wrapper;