FileDocCategorySizeDatePackage
AsadminTruststore.javaAPI DocGlassfish v2 API6112Fri May 04 22:36:24 BST 2007com.sun.enterprise.admin.jmx.remote.https

AsadminTruststore

public class AsadminTruststore extends Object
This class implements an adapter for password manipulation a JCEKS.
author
Shing Wai Chan

Fields Summary
private static final String
ASADMIN_TRUSTSTORE
private KeyStore
_keyStore
private File
_keyFile
private char[]
_password
public static final String
CLIENT_TRUSTSTORE_PROPERTY
public static final String
CLIENT_TRUSTSTORE_PASSWORD_PROPERTY
Constructors Summary
public AsadminTruststore()

                 
        this(getAsadminTruststorePassword());
    
public AsadminTruststore(String password)

                 
        init(getAsadminTruststore(), password);
    
Methods Summary
public voidaddCertificate(java.lang.String alias, java.security.cert.Certificate cert)

        _keyStore.setCertificateEntry(alias, cert);
        writeStore();
    
public booleancertificateExists(java.security.cert.Certificate cert)

        return (_keyStore.getCertificateAlias(cert) == null ? false : true);
    
public static java.io.FilegetAsadminTruststore()

    
       
    
        String location = System.getProperty(CLIENT_TRUSTSTORE_PROPERTY);
        if (location == null) {
            return new File(System.getProperty("user.home") + File.separator + ASADMIN_TRUSTSTORE);
        } else {
            return new File(location);
        }
    
public static java.lang.StringgetAsadminTruststorePassword()

        return System.getProperty(CLIENT_TRUSTSTORE_PASSWORD_PROPERTY, 
            "changeit");
    
private voidinit(java.io.File keyfile, java.lang.String password)

        _keyFile = keyfile;
        _keyStore = KeyStore.getInstance("JKS"); 
        _password = password.toCharArray();
        BufferedInputStream bInput = null;        
        if (_keyFile.exists()) {
            bInput = new BufferedInputStream(new FileInputStream(_keyFile));
        }
        try {            
            //load must be called with null to initialize an empty keystore
            _keyStore.load(bInput, _password);
            if (bInput != null) {
                bInput.close();
                bInput = null;
            } 
        } finally {
             if (bInput != null) {
                 try {
                     bInput.close();
                 } catch(Exception ex) {
                     //ignore we are cleaning up
                 }
             }
        }        
    
public voidwriteStore()

         BufferedOutputStream boutput = null;

         try {
             boutput = new BufferedOutputStream(
                     new FileOutputStream(_keyFile));
             _keyStore.store(boutput, _password);
             boutput.close();
             boutput = null;
         } finally {
             if (boutput != null) {
                 try {
                     boutput.close();
                 } catch(Exception ex) {
                     //ignore we are cleaning up
                 }
             }
         }