Search in sources :

Example 11 with PEFileLayout

use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.

the class UpgradeLogging method doUpgrade.

private void doUpgrade(Config config) {
    // v3 uses logging.properties to configure the logging facility.
    // move all log-service elements to logging.properties
    final LogService logService = config.getLogService();
    // check if null and exit
    if (logService == null)
        return;
    try {
        RepositoryConfig rc = new RepositoryConfig();
        String configDir = rc.getRepositoryRoot() + File.separator + rc.getRepositoryName() + File.separator + rc.getInstanceName() + File.separator + "config";
        PEFileLayout layout = new PEFileLayout(rc);
        File src = new File(layout.getTemplatesDir(), PEFileLayout.LOGGING_PROPERTIES_FILE);
        File dest = new File(configDir, PEFileLayout.LOGGING_PROPERTIES_FILE);
        if (!dest.exists())
            FileUtils.copy(src, dest);
    } catch (IOException ioe) {
        getLogger().log(Level.SEVERE, FAIL_CREATE_LOG_PROPS, ioe);
    }
    try {
        // Get the logLevels
        ModuleLogLevels mll = logService.getModuleLogLevels();
        Map<String, String> logLevels = mll.getAllLogLevels();
        String file = logService.getFile();
        String payaraNotificationFile = logService.getPayaraNotificationFile();
        String instanceRoot = System.getProperty("com.sun.aas.instanceRoot");
        if (file.contains(instanceRoot)) {
            file = file.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        if (payaraNotificationFile.contains(instanceRoot)) {
            payaraNotificationFile = payaraNotificationFile.replace(instanceRoot, "${com.sun.aas.instanceRoot}");
        }
        logLevels.put("file", file);
        logLevels.put("payara-notification-file", payaraNotificationFile);
        logLevels.put("use-system-logging", logService.getUseSystemLogging());
        // this can have multiple values so need to add
        logLevels.put("log-handler", logService.getLogHandler());
        logLevels.put("log-filter", logService.getLogFilter());
        logLevels.put("log-to-file", logService.getLogToFile());
        logLevels.put("payara-notification-log-to-file", logService.getPayaraNotificationLogToFile());
        logLevels.put("log-to-console", logService.getLogToConsole());
        logLevels.put("log-rotation-limit-in-bytes", logService.getLogRotationLimitInBytes());
        logLevels.put("payara-notification-log-rotation-limit-in-bytes", logService.getPayaraNotificationLogRotationLimitInBytes());
        logLevels.put("log-rotation-timelimit-in-minutes", logService.getLogRotationTimelimitInMinutes());
        logLevels.put("payara-notification-log-rotation-timelimit-in-minutes", logService.getPayaraNotificationLogRotationTimelimitInMinutes());
        logLevels.put("alarms", logService.getAlarms());
        logLevels.put("retain-error-statistics-for-hours", logService.getRetainErrorStatisticsForHours());
        final Map<String, String> m = new HashMap<String, String>(logLevels);
        ConfigSupport.apply(new SingleConfigCode<Config>() {

            public Object run(Config c) throws PropertyVetoException, TransactionFailure {
                try {
                    // update logging.properties
                    logConfig.updateLoggingProperties(m);
                    c.setLogService(null);
                } catch (IOException e) {
                    getLogger().log(Level.SEVERE, FAIL_UPDATE_LOG_PROPS, e);
                }
                return null;
            }
        }, config);
    } catch (TransactionFailure tf) {
        getLogger().log(Level.SEVERE, FAIL_UPGRADE_LOG_SERVICE, tf);
        throw new RuntimeException(tf);
    }
}
Also used : RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) TransactionFailure(org.jvnet.hk2.config.TransactionFailure) HashMap(java.util.HashMap) RepositoryConfig(com.sun.enterprise.admin.servermgmt.RepositoryConfig) IOException(java.io.IOException) PropertyVetoException(java.beans.PropertyVetoException) PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) File(java.io.File)

Example 12 with PEFileLayout

use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.

the class KeystoreManager method changeSSLCertificateDatabasePassword.

/**
 * Changes the password of the keystore, truststore and the key password of
 * the s1as alias. It is expected that the key / truststores may not exist.
 * This is due to the fact that the user may have deleted them and wishes to
 * set up their own key/truststore
 *
 * @param config
 * @param storePassword
 * @param oldKeyPassword
 * @param newKeyPassword
 */
protected void changeSSLCertificateDatabasePassword(RepositoryConfig config, String oldPassword, String newPassword) throws RepositoryException {
    final PEFileLayout layout = getFileLayout(config);
    File keystore = layout.getKeyStore();
    File truststore = layout.getTrustStore();
    if (keystore.exists()) {
        // Change the password on the keystore
        changeKeystorePassword(oldPassword, newPassword, keystore);
        // database password.
        try {
            changeS1ASAliasPassword(config, newPassword, oldPassword, newPassword);
        } catch (Exception ex) {
            // For now we eat all exceptions and dump to the log if the password
            // alias could not be changed.
            getLogger().log(Level.SEVERE, UNHANDLED_EXCEPTION, ex);
        }
    }
    if (truststore.exists()) {
        // Change the password on the truststore
        changeKeystorePassword(oldPassword, newPassword, truststore);
    }
}
Also used : PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) SmartFile(com.sun.enterprise.universal.io.SmartFile) File(java.io.File) CertificateNotYetValidException(java.security.cert.CertificateNotYetValidException) KeyStoreException(java.security.KeyStoreException) CertificateExpiredException(java.security.cert.CertificateExpiredException) ExecException(com.sun.enterprise.util.ExecException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) FileNotFoundException(java.io.FileNotFoundException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 13 with PEFileLayout

use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.

the class MasterPasswordFileManager method readMasterPasswordFile.

/**
 * Return the master password stored in the master password keystore.
 * @param config
 * @throws RepositoryException
 * @return
 */
public String readMasterPasswordFile(RepositoryConfig config) throws RepositoryException {
    final PEFileLayout layout = getFileLayout(config);
    final File pwdFile = layout.getMasterPasswordFile();
    if (pwdFile.exists()) {
        try {
            PasswordAdapter p = new PasswordAdapter(pwdFile.getAbsolutePath(), getMasterPasswordPassword());
            return p.getPasswordForAlias(MASTER_PASSWORD_ALIAS);
        } catch (Exception ex) {
            throw new RepositoryException(_strMgr.getString("masterPasswordFileNotRead", pwdFile), ex);
        }
    } else {
        // Return null if the password file does not exist.
        return null;
    }
}
Also used : PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) File(java.io.File)

Example 14 with PEFileLayout

use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.

the class RepositoryManager method createJBIInstance.

/**
 * Create JBI instance.
 */
protected void createJBIInstance(String instanceName, RepositoryConfig config) throws RepositoryException {
    final PEFileLayout layout = getFileLayout(config);
    layout.createJBIDirectories();
    final TokenValueSet tvSet = new TokenValueSet();
    final String tvDelimiter = "@";
    final String tJbiInstanceName = "JBI_INSTANCE_NAME";
    final String tJbiInstanceRoot = "JBI_INSTANCE_ROOT";
    try {
        final TokenValue tvJbiInstanceName = new TokenValue(tJbiInstanceName, instanceName, tvDelimiter);
        final TokenValue tvJbiInstanceRoot = new TokenValue(tJbiInstanceRoot, layout.getRepositoryDir().getCanonicalPath(), tvDelimiter);
        tvSet.add(tvJbiInstanceName);
        tvSet.add(tvJbiInstanceRoot);
        final File src = layout.getJbiTemplateFile();
        final File dest = layout.getJbiRegistryFile();
        generateFromTemplate(tvSet, src, dest);
        final File httpConfigSrc = layout.getHttpBcConfigTemplate();
        final File httpConfigDest = layout.getHttpBcConfigFile();
        // tokens will be added in a follow-up integration
        final TokenValueSet httpTvSet = new TokenValueSet();
        generateFromTemplate(httpTvSet, httpConfigSrc, httpConfigDest);
        createHttpBCInstallRoot(layout);
        createJavaEESEInstallRoot(layout);
        createWSDLSLInstallRoot(layout);
    } catch (Exception ioe) {
        throw new RepositoryException(_strMgr.getString("jbiRegistryFileNotCreated"), ioe);
    }
}
Also used : TokenValueSet(com.sun.enterprise.admin.util.TokenValueSet) PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) ZipFile(com.sun.enterprise.util.zip.ZipFile) TokenValue(com.sun.enterprise.admin.util.TokenValue)

Example 15 with PEFileLayout

use of com.sun.enterprise.admin.servermgmt.pe.PEFileLayout in project Payara by payara.

the class RepositoryManager method validateMasterPassword.

/**
 * We validate the master password by trying to open the password alias
 * keystore. This means that the keystore must already exist.
 *
 * @param config
 * @param password
 * @throws RepositoryException
 */
public void validateMasterPassword(RepositoryConfig config, String password) throws RepositoryException {
    final PEFileLayout layout = getFileLayout(config);
    final File passwordAliases = layout.getPasswordAliasKeystore();
    try {
        // WBN July 2007
        // we are constructing this object ONLY to see if it throws
        // an Exception.  We do not use the object.
        new PasswordAdapter(passwordAliases.getAbsolutePath(), password.toCharArray());
    } catch (IOException ex) {
        throw new RepositoryException(_strMgr.getString("masterPasswordInvalid"));
    } catch (Exception ex) {
        throw new RepositoryException(_strMgr.getString("couldNotValidateMasterPassword", passwordAliases), ex);
    }
}
Also used : PEFileLayout(com.sun.enterprise.admin.servermgmt.pe.PEFileLayout) PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) ZipFile(com.sun.enterprise.util.zip.ZipFile)

Aggregations

PEFileLayout (com.sun.enterprise.admin.servermgmt.pe.PEFileLayout)15 ZipFile (com.sun.enterprise.util.zip.ZipFile)8 File (java.io.File)6 PasswordAdapter (com.sun.enterprise.security.store.PasswordAdapter)5 IOException (java.io.IOException)3 TokenValue (com.sun.enterprise.admin.util.TokenValue)2 TokenValueSet (com.sun.enterprise.admin.util.TokenValueSet)2 SmartFile (com.sun.enterprise.universal.io.SmartFile)2 ExecException (com.sun.enterprise.util.ExecException)2 FileNotFoundException (java.io.FileNotFoundException)2 KeyStoreException (java.security.KeyStoreException)2 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 CertificateException (java.security.cert.CertificateException)2 CertificateExpiredException (java.security.cert.CertificateExpiredException)2 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)2 RepositoryConfig (com.sun.enterprise.admin.servermgmt.RepositoryConfig)1 PropertyVetoException (java.beans.PropertyVetoException)1 FileInputStream (java.io.FileInputStream)1 KeyStore (java.security.KeyStore)1 ArrayList (java.util.ArrayList)1