FileDocCategorySizeDatePackage
PasswordConfReader.javaAPI DocGlassfish v2 API6715Fri May 04 22:33:18 BST 2007com.sun.enterprise.admin.common

PasswordConfReader

public final class PasswordConfReader extends Object
Provides api to read passwords from password conf file.

Fields Summary
public static final String
KEY_STORE_ALIAS
public static final String
TRUST_STORE_ALIAS
public static final String
PASSWORD_FILE_PROPERTY
static final String
CONFIG
static final String
PASSWORD_CONF
private static final String
INSTANCE_ROOT
private static final String
SERVER_NAME_PROPERTY
private static PasswordFile
pf
private static Hashtable
entries
Constructors Summary
private PasswordConfReader()


    /* Constructs new PasswordConfReader object */
     
    
    
Methods Summary
private static synchronized java.lang.Stringget(java.lang.String key)

        final String password = (String)entries.get(key);
        if (password == null)
        {
            throw new IOException("No entry found for " + key);
        }
        return password;
    
private static java.lang.StringgetDefaultPasswordConf()

        String defaultConf = null;
        if (INSTANCE_ROOT != null)
        {
            defaultConf =   INSTANCE_ROOT + File.separator
                            + File.separator + CONFIG + File.separator
                            + PASSWORD_CONF;
        }
        return defaultConf;
    
public static java.lang.StringgetKeyStorePassword()

        return getPassword(KEY_STORE_ALIAS);
    
public static java.lang.StringgetPassword(java.lang.String alias)

        if (!isInSync()) { sync(); }
        return get(alias);
    
private static com.sun.enterprise.admin.common.PasswordConfReader$PasswordFilegetPasswordFile()

        final String prop = System.getProperty(PASSWORD_FILE_PROPERTY);
        PasswordFile f;
        if ((prop != null) && (prop.length() > 0))
        {
            f = new PasswordFile(prop);
        }
        else
        {
            f = new PasswordFile(getDefaultPasswordConf());
        }
        return f;
    
public static java.lang.StringgetTrustStorePassword()

        return getPassword(TRUST_STORE_ALIAS);
    
private static booleanisInSync()

        return getPasswordFile().equals(pf);
    
public static java.util.EnumerationlistAliases()

        if (!isInSync()) { sync(); }
        return entries.keys();
    
private static synchronized voidloadEntries()

        if (entries == null)
        {
            entries = new Hashtable();
        }
        BufferedReader reader = null;
        try
        {
            reader = new BufferedReader(new FileReader(pf.getPath()));
            String str;
            while ((str = reader.readLine()) != null)
            {
                int index = str.indexOf(':");
                if (index > 0)
                {
                    entries.put(str.substring(0, index),
                                str.substring(index+1));
                }
            }
        }
        finally
        {
            if (reader != null) { reader.close(); }
        }
    
private static voidsync()

        synchronized (PasswordConfReader.class)
        {
            pf = getPasswordFile();
        }
        loadEntries();