FileDocCategorySizeDatePackage
SecurableObjectHolder.javaAPI DocGlassfish v2 API5866Tue May 22 16:54:42 BST 2007oracle.toplink.essentials.internal.security

SecurableObjectHolder

public class SecurableObjectHolder extends Object
Holder of a SecurableObject. Securable objects should not be held onto directly, instead they should be accessed via this holder.
author
Guy Pelletier
date
June 26, 2003

Fields Summary
private static final String
JCE_ENCRYPTION_CLASS_NAME
The JCE encryption class name
private String
m_securableClassName
The encryption class name
private Securable
m_securableObject
The actual encryption object
Constructors Summary
public SecurableObjectHolder()


      
        this(null);
    
public SecurableObjectHolder(String securableClassName)

        m_securableObject = null;
        m_securableClassName = securableClassName;
    
Methods Summary
public oracle.toplink.essentials.internal.security.SecurablegetSecurableObject()

        if (m_securableObject == null) {
            initSecurableObject();
        }

        return m_securableObject;
    
public booleanhasSecurableObject()

        return m_securableObject != null;
    
private voidinitSecurableObject()
Convert a String into a Securable object Class name must be fully qualified, eg. oracle.toplink.essentials.internal.security.JCEEncryptor Default is the JCEEncryptor

        boolean initPassThroughEncryptor = false;

        if (m_securableClassName == null) {
            // Since we are defaulting, hence, assuming they can initialize the JCE
            // libraries, if the init fails, this flag tells us to assume no encryption.
            // However, if the JCE init does work, the JCEEncryptor will need to 
            // determine that a password was not encrypted by it, therefore, assume 
            // clear text. See JCEEncryptor.
            initPassThroughEncryptor = true;
            m_securableClassName = JCE_ENCRYPTION_CLASS_NAME;
        }

        try {
            ConversionManager cm = ConversionManager.getDefaultManager();
            Class securableClass = (Class)cm.convertObject(m_securableClassName, Class.class);
            if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()){
                try {
                    m_securableObject = (Securable)AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(securableClass));
                } catch (PrivilegedActionException exception) {
                    throw exception.getException();
                }
            } else {
                m_securableObject = (Securable)PrivilegedAccessHelper.newInstanceFromClass(securableClass);
            }
        } catch (Throwable e) {
            if (initPassThroughEncryptor) {// default failed, so perform no encryption.
                m_securableObject = new PassThroughEncryptor();
            } else {
                throw ValidationException.invalidEncryptionClass(m_securableClassName, e);
            }
        }
    
public voidsetEncryptionClassName(java.lang.String securableClassName)

        m_securableClassName = securableClassName;