Search in sources :

Example 1 with RepositoryException

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

the class DomainBuilder method run.

/**
 * Performs all the domain configurations which includes security, configuration processing,
 * substitution of parameters... etc.
 *
 * @throws DomainException If any exception occurs in configuration.
 */
public void run() throws RepositoryException, DomainException {
    // Create domain directories.
    File domainDir = FileUtils.safeGetCanonicalFile(new File(_domainConfig.getRepositoryRoot(), _domainConfig.getDomainName()));
    createDirectory(domainDir);
    try {
        // Extract other jar entries
        byte[] buffer = new byte[10000];
        for (Enumeration<JarEntry> entry = _templateJar.entries(); entry.hasMoreElements(); ) {
            JarEntry jarEntry = (JarEntry) entry.nextElement();
            String entryName = jarEntry.getName();
            if (entryName.startsWith(META_DIR_NAME)) {
                // Skipping the extraction of jar meta data.
                continue;
            }
            if (_extractedEntries.contains(entryName)) {
                continue;
            }
            if (jarEntry.isDirectory()) {
                File dir = new File(domainDir, jarEntry.getName());
                if (!dir.exists()) {
                    if (!dir.mkdir()) {
                        _logger.log(Level.WARNING, SLogger.DIR_CREATION_ERROR, dir.getName());
                    }
                }
                continue;
            }
            InputStream in = null;
            BufferedOutputStream outputStream = null;
            try {
                in = _templateJar.getInputStream(jarEntry);
                outputStream = new BufferedOutputStream(new FileOutputStream(new File(domainDir.getAbsolutePath(), jarEntry.getName())));
                int i = 0;
                while ((i = in.read(buffer)) != -1) {
                    outputStream.write(buffer, 0, i);
                }
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (Exception io) {
                    /**
                     * ignore
                     */
                    }
                }
                if (outputStream != null) {
                    try {
                        outputStream.close();
                    } catch (Exception io) {
                    /**
                     * ignore
                     */
                    }
                }
            }
        }
        File configDir = new File(domainDir, DomainConstants.CONFIG_DIR);
        String user = (String) _domainConfig.get(DomainConfig.K_USER);
        String password = (String) _domainConfig.get(DomainConfig.K_PASSWORD);
        String[] adminUserGroups = ((String) _domainConfig.get(DomainConfig.K_INITIAL_ADMIN_USER_GROUPS)).split(",");
        String masterPassword = (String) _domainConfig.get(DomainConfig.K_MASTER_PASSWORD);
        Boolean saveMasterPassword = (Boolean) _domainConfig.get(DomainConfig.K_SAVE_MASTER_PASSWORD);
        // Process domain security.
        DomainSecurity domainSecurity = new DomainSecurity();
        domainSecurity.processAdminKeyFile(new File(configDir, DomainConstants.ADMIN_KEY_FILE), user, password, adminUserGroups);
        try {
            domainSecurity.createSSLCertificateDatabase(configDir, _domainConfig, masterPassword);
        } catch (Exception e) {
            String msg = _strings.getString("SomeProblemWithKeytool", e.getMessage());
            System.err.println(msg);
            FileOutputStream fos = null;
            try {
                File keystoreFile = new File(configDir, DomainConstants.KEYSTORE_FILE);
                fos = new FileOutputStream(keystoreFile);
                fos.write(_keystoreBytes);
            } catch (Exception ex) {
                getLogger().log(Level.SEVERE, UNHANDLED_EXCEPTION, ex);
            } finally {
                if (fos != null)
                    fos.close();
            }
        }
        domainSecurity.changeMasterPasswordInMasterPasswordFile(new File(configDir, DomainConstants.MASTERPASSWORD_FILE), masterPassword, saveMasterPassword);
        domainSecurity.createPasswordAliasKeystore(new File(configDir, DomainConstants.DOMAIN_PASSWORD_FILE), masterPassword);
        // Add customized tokens in domain.xml.
        CustomTokenClient tokenClient = new CustomTokenClient(_domainConfig);
        Map<String, String> generatedTokens = tokenClient.getSubstitutableTokens();
        // Perform string substitution.
        if (_domainTempalte.hasStringsubs()) {
            StringSubstitutor substitutor = _domainTempalte.getStringSubs();
            Map<String, String> lookUpMap = SubstitutableTokens.getSubstitutableTokens(_domainConfig);
            lookUpMap.putAll(generatedTokens);
            substitutor.setAttributePreprocessor(new AttributePreprocessorImpl(lookUpMap));
            substitutor.substituteAll();
        }
        // Change the permission for bin & config directories.
        try {
            File binDir = new File(domainDir, DomainConstants.BIN_DIR);
            if (binDir.exists() && binDir.isDirectory()) {
                domainSecurity.changeMode("-R u+x ", binDir);
            }
            domainSecurity.changeMode("-R g-rwx,o-rwx ", configDir);
        } catch (Exception e) {
            throw new DomainException(_strings.get("setPermissionError"), e);
        }
        // Generate domain-info.xml
        DomainInfoManager domainInfoManager = new DomainInfoManager();
        domainInfoManager.process(_domainTempalte, domainDir);
    } catch (DomainException de) {
        // roll-back
        FileUtils.liquidate(domainDir);
        throw de;
    } catch (Exception ex) {
        // roll-back
        FileUtils.liquidate(domainDir);
        throw new DomainException(ex);
    }
}
Also used : DomainException(com.sun.enterprise.admin.servermgmt.DomainException) InputStream(java.io.InputStream) JarEntry(java.util.jar.JarEntry) DomainException(com.sun.enterprise.admin.servermgmt.DomainException) RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException) StringSubstitutor(com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutor) AttributePreprocessorImpl(com.sun.enterprise.admin.servermgmt.stringsubs.impl.AttributePreprocessorImpl) FileOutputStream(java.io.FileOutputStream) JarFile(java.util.jar.JarFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 2 with RepositoryException

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

the class PEFileLayout method createJbiSystemComponentsLayout.

/**
 * This method is used to create the file layout for
 * JBI system components, HttpSoapBC, JavaEESE, WSDLSL
 */
public void createJbiSystemComponentsLayout() throws RepositoryException {
    try {
        createDirectory(getHttpBcDir());
        createDirectory(getHttpBcInstallRoot());
        createDirectory(getJavaEESEDir());
        createDirectory(getJavaEESEInstallRoot());
        createDirectory(getWSDLSLDir());
        createDirectory(getWSDLSLInstallRoot());
        createDirectory(getHttpBcWorkSpace());
        createDirectory(getJavaEESEWorkSpace());
    } catch (Exception e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException) RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException)

Example 3 with RepositoryException

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

the class DomainSecurity method createPasswordAliasKeystore.

/**
 * Create the password alias keystore (initially empty)
 *
 * @param pwFile File to store encrypted password.
 * @param password password protecting the keystore
 * @throws RepositoryException if any error occurs in creation.
 */
void createPasswordAliasKeystore(File pwFile, String password) throws RepositoryException {
    try {
        PasswordAdapter p = new PasswordAdapter(pwFile.getAbsolutePath(), password.toCharArray());
        p.writeStore();
    } catch (Exception ex) {
        throw new RepositoryException(_strMgr.getString("passwordAliasKeystoreNotCreated", pwFile), ex);
    }
}
Also used : RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException) PasswordAdapter(com.sun.enterprise.security.store.PasswordAdapter) IOException(java.io.IOException) RepositoryException(com.sun.enterprise.admin.servermgmt.RepositoryException)

Aggregations

RepositoryException (com.sun.enterprise.admin.servermgmt.RepositoryException)3 DomainException (com.sun.enterprise.admin.servermgmt.DomainException)1 StringSubstitutor (com.sun.enterprise.admin.servermgmt.stringsubs.StringSubstitutor)1 AttributePreprocessorImpl (com.sun.enterprise.admin.servermgmt.stringsubs.impl.AttributePreprocessorImpl)1 PasswordAdapter (com.sun.enterprise.security.store.PasswordAdapter)1 BufferedOutputStream (java.io.BufferedOutputStream)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 JarEntry (java.util.jar.JarEntry)1 JarFile (java.util.jar.JarFile)1