FileDocCategorySizeDatePackage
PolicyConfigurationFactoryImpl.javaAPI DocGlassfish v2 API10127Fri May 04 22:36:02 BST 2007com.sun.enterprise.security.provider

PolicyConfigurationFactoryImpl

public class PolicyConfigurationFactoryImpl extends PolicyConfigurationFactory
Implementation of jacc PolicyConfigurationFactory class
author
Harpreet Singh
author
Ron Monzillo
version

Fields Summary
static Map
polConfTable
private static Logger
logger
private static ReadWriteLock
rwLock
private static Lock
rLock
private static Lock
wLock
Constructors Summary
public PolicyConfigurationFactoryImpl()

 
     
    
Methods Summary
private static PolicyConfigurationImplgetPolicyConfigImpl(java.lang.String contextId)

        try {
            rLock.lock(); 
            return (PolicyConfigurationImpl) polConfTable.get(contextId);
        } finally {
            rLock.unlock();
        }
    
public PolicyConfigurationgetPolicyConfiguration(java.lang.String contextId, boolean remove)
This method is used to obtain an instance of the provider specific class that implements the PolicyConfiguration interface that corresponds to the identified policy context within the provider. The methods of the PolicyConfiguration interface are used to define the policy statements of the identified policy context.

If at the time of the call, the identified policy context does not exist in the provider, then the policy context will be created in the provider and the Object that implements the context's PolicyConfiguration Interface will be returned. If the state of the identified context is "deleted" or "inService" it will be transitioned to the "open" state as a result of the call. The states in the lifecycle of a policy context are defined by the PolicyConfiguration interface.

For a given value of policy context identifier, this method must always return the same instance of PolicyConfiguration and there must be at most one actual instance of a PolicyConfiguration with a given policy context identifier (during a process context).

To preserve the invariant that there be at most one PolicyConfiguration object for a given policy context, it may be necessary for this method to be thread safe.

param
contextID A String identifying the policy context whose PolicyConfiguration interface is to be returned. The value passed to this parameter must not be null.

param
remove A boolean value that establishes whether or not the policy statements of an existing policy context are to be removed before its PolicyConfiguration object is returned. If the value passed to this parameter is true, the policy statements of an existing policy context will be removed. If the value is false, they will not be removed.
return
an Object that implements the PolicyConfiguration Interface matched to the Policy provider and corresponding to the identified policy context.
throws
java.lang.SecurityException when called by an AccessControlContext that has not been granted the "setPolicy" SecurityPermission.
throws
javax.security.jacc.PolicyContextException if the implementation throws a checked exception that has not been accounted for by the getPolicyConfiguration method signature. The exception thrown by the implementation class will be encapsulated (during construction) in the thrown PolicyContextException.


	PolicyConfigurationImpl.checkSetPolicyPermission();
	
	if(logger.isLoggable(Level.FINE)){
	    logger.fine("JACC Policy Provider: Getting PolicyConfiguration object with id = "+ contextId);	
	}

	PolicyConfigurationImpl pci = getPolicyConfigImpl(contextId);

	// if the pc is not in the table, see if it was copied into the
        // filesystem (e.g. by the DAS)
	if (pci == null){
	    pci = getPolicyConfigurationImplFromDirectory(contextId,true,remove);
	    if (pci == null) {
		pci = new PolicyConfigurationImpl(contextId);
		putPolicyConfigurationImpl(contextId,pci);
	    }
	} else {
	    // return the policy configuration to the open state, value of
	    // remove will determine if statements are removed
	    pci.initialize(true,remove,false);
	}
	return pci;
    
protected static PolicyConfigurationImplgetPolicyConfigurationImpl(java.lang.String contextId)

	PolicyConfigurationImpl pci = getPolicyConfigImpl(contextId); 
	if (pci == null) {
	    // check if pc was copied into the filesystem after the repository 
	    // was initialized (do not open pc or remove policy statements).
	    pci = getPolicyConfigurationImplFromDirectory(contextId,false,false);
	    if (pci == null) {
		logger.log(Level.WARNING,"pc.unknown_policy_context",
			   new Object[]{contextId});
	    }
	}
	return pci;
    
private static PolicyConfigurationImplgetPolicyConfigurationImplFromDirectory(java.lang.String contextId, boolean open, boolean remove)

	PolicyConfigurationImpl pci = null;
	File f = new File(PolicyConfigurationImpl.getContextDirectoryName(contextId));
	if (f.exists()) {
	    pci = new PolicyConfigurationImpl(f,open,remove);
	    if (pci != null) {
		putPolicyConfigurationImpl(contextId,pci);
	    }
	}
	return pci;
    
protected static PolicyConfigurationImpl[]getPolicyConfigurationImpls()


        PolicyConfigurationImpl[] rvalue = null;

        try {
            rLock.lock();

            Collection c = polConfTable.values();

            if (c != null) {

                rvalue = (PolicyConfigurationImpl[]) 
                    c.toArray( new PolicyConfigurationImpl[c.size()] );
            }

        } finally {
            rLock.unlock();
        }

        return rvalue;
    
public booleaninService(java.lang.String contextID)
This method determines if the identified policy context exists with state "inService" in the Policy provider associated with the factory.

param
contextID A string identifying a policy context
return
true if the identified policy context exists within the provider and its state is "inService", false otherwise.
throws
java.lang.SecurityException when called by an AccessControlContext that has not been granted the "setPolicy" SecurityPermission.
throws
javax.security.jacc.PolicyContextException if the implementation throws a checked exception that has not been accounted for by the inService method signature. The exception thrown by the implementation class will be encapsulated (during construction) in the thrown PolicyContextException.

	PolicyConfigurationImpl.checkSetPolicyPermission();
	PolicyConfiguration pc = getPolicyConfigImpl(contextID);

	// if the pc is not in the table, see if it was copied into the
        // filesystem (e.g. by the DAS)
	if (pc == null) {
	    pc = getPolicyConfigurationImplFromDirectory(contextID,false,false);
	}
	return pc == null ? false : pc.inService();
    
protected static PolicyConfigurationImplputPolicyConfigurationImpl(java.lang.String contextID, PolicyConfigurationImpl pci)

        try {
            wLock.lock(); 
            return (PolicyConfigurationImpl) polConfTable.put(contextID,pci);
        } finally {
            wLock.unlock();
        }