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);
}
}
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);
}
}
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);
}
}
Aggregations