Search in sources :

Example 1 with EmbeddedFileSystem

use of org.glassfish.internal.embedded.EmbeddedFileSystem in project Payara by payara.

the class EmbeddedSecurityLifeCycle method creation.

@Override
public void creation(Server server) {
    // If the instanceRoot is not set to a non-embedded GF install,
    // copy the security config files from the security.jar to the instanceRoot/config dir
    EmbeddedFileSystem fileSystem = server.getFileSystem();
    File instanceRoot = fileSystem.instanceRoot;
    if (instanceRoot == null) {
        return;
    }
    try {
        // Get the keyfile names from the security service
        List<String> keyFileNames = embeddedSecurity.getKeyFileNames(securityService);
        for (String keyFileName : keyFileNames) {
            // Copy the keyfiles in instanceRoot/config. If file is already present, then exit (handled by getManagedFile)
            FileUtils.getManagedFile("config" + File.separator + embeddedSecurity.parseFileName(keyFileName), instanceRoot);
        }
        // Copy the other security files to instanceRoot/config
        // Assuming that these files are present as config/filename in the embedded jar file and are to be extracted that way/
        FileUtils.getManagedFile("config" + File.separator + "login.conf", instanceRoot);
        FileUtils.getManagedFile("config" + File.separator + "server.policy", instanceRoot);
        FileUtils.getManagedFile("config" + File.separator + "cacerts.jks", instanceRoot);
        FileUtils.getManagedFile("config" + File.separator + "keystore.jks", instanceRoot);
        String keystoreFile = null;
        String truststoreFile = null;
        try {
            keystoreFile = Util.writeConfigFileToTempDir("keystore.jks").getAbsolutePath();
            truststoreFile = Util.writeConfigFileToTempDir("cacerts.jks").getAbsolutePath();
        } catch (IOException ex) {
            _logger.log(Level.SEVERE, SecurityLoggerInfo.obtainingKeyAndTrustStoresError, ex);
        }
        System.setProperty(SecuritySupport.keyStoreProp, keystoreFile);
        System.setProperty(SecuritySupport.trustStoreProp, truststoreFile);
    } catch (IOException ioEx) {
        _logger.log(Level.WARNING, SecurityLoggerInfo.copyingSecurityConfigFilesIOError, ioEx);
    }
}
Also used : EmbeddedFileSystem(org.glassfish.internal.embedded.EmbeddedFileSystem) IOException(java.io.IOException) File(java.io.File)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 EmbeddedFileSystem (org.glassfish.internal.embedded.EmbeddedFileSystem)1