|
@@ -1,150 +1,147 @@
|
|
|
+/*
|
|
|
+ * Password Management Servlets (PWM)
|
|
|
+ * http://www.pwm-project.org
|
|
|
+ *
|
|
|
+ * Copyright (c) 2006-2009 Novell, Inc.
|
|
|
+ * Copyright (c) 2009-2018 The PWM Project
|
|
|
+ *
|
|
|
+ * This program is free software; you can redistribute it and/or modify
|
|
|
+ * it under the terms of the GNU General Public License as published by
|
|
|
+ * the Free Software Foundation; either version 2 of the License, or
|
|
|
+ * (at your option) any later version.
|
|
|
+ *
|
|
|
+ * This program is distributed in the hope that it will be useful,
|
|
|
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
+ * GNU General Public License for more details.
|
|
|
+ *
|
|
|
+ * You should have received a copy of the GNU General Public License
|
|
|
+ * along with this program; if not, write to the Free Software
|
|
|
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
+ */
|
|
|
+
|
|
|
package password.pwm;
|
|
|
|
|
|
-import org.apache.catalina.Context;
|
|
|
import org.apache.catalina.LifecycleException;
|
|
|
import org.apache.catalina.connector.Connector;
|
|
|
-import org.apache.catalina.connector.CoyoteAdapter;
|
|
|
import org.apache.catalina.startup.Tomcat;
|
|
|
import org.apache.catalina.util.ServerInfo;
|
|
|
-import org.apache.commons.cli.CommandLine;
|
|
|
-import org.apache.commons.cli.CommandLineParser;
|
|
|
-import org.apache.commons.cli.DefaultParser;
|
|
|
-import org.apache.commons.cli.HelpFormatter;
|
|
|
-import org.apache.commons.cli.Option;
|
|
|
-import org.apache.commons.cli.Options;
|
|
|
-import org.apache.commons.cli.ParseException;
|
|
|
|
|
|
import javax.servlet.ServletException;
|
|
|
import java.io.File;
|
|
|
-import java.io.FileInputStream;
|
|
|
+import java.io.FileWriter;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
-import java.net.Socket;
|
|
|
+import java.lang.reflect.InvocationTargetException;
|
|
|
+import java.lang.reflect.Method;
|
|
|
import java.net.URL;
|
|
|
+import java.net.URLClassLoader;
|
|
|
import java.nio.file.FileVisitOption;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
+import java.time.Duration;
|
|
|
+import java.time.Instant;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Properties;
|
|
|
import java.util.jar.Attributes;
|
|
|
import java.util.jar.Manifest;
|
|
|
-import java.util.logging.Logger;
|
|
|
+import java.util.zip.ZipEntry;
|
|
|
+import java.util.zip.ZipInputStream;
|
|
|
|
|
|
public class TomcatOneJarMain
|
|
|
{
|
|
|
- private static final Logger LOGGER = Logger.getLogger(TomcatOneJarMain.class.getName());
|
|
|
-
|
|
|
- private static final String ARG_APP_PATH = "applicationPath";
|
|
|
- private static final String ARG_WORK_PATH = "workPath";
|
|
|
- private static final String ARG_VERSION = "version";
|
|
|
- private static final String ARG_HELP = "help";
|
|
|
- private static final String ARG_WARFILE = "war";
|
|
|
- private static final String ARG_PORT = "port";
|
|
|
- private static final String ARG_CONTEXT = "context";
|
|
|
-
|
|
|
- private static final String DEFAULT_CONTEXT = "pwm";
|
|
|
- private static final int DEFAULT_PORT = 8080;
|
|
|
- private static final String DEFAULT_WORK_DIR_NAME = ".pwm-workpath";
|
|
|
+ //private static final String TEMP_WAR_FILE_NAME = "embed.war";
|
|
|
+ private static final String KEYSTORE_ALIAS = "https";
|
|
|
|
|
|
- private static final String EMBED_WAR_NAME = "embed.war";
|
|
|
-
|
|
|
- public static void main(final String[] args) throws ServletException, IOException, LifecycleException
|
|
|
+ public static void main( final String[] args )
|
|
|
{
|
|
|
- if (args == null || args.length == 0) {
|
|
|
- outputHelp();
|
|
|
- } else
|
|
|
+ final ArgumentParser argumentParser = new ArgumentParser();
|
|
|
+ TomcatConfig tomcatConfig = null;
|
|
|
+ try
|
|
|
{
|
|
|
- final CommandLine commandLine = parseOptions( args );
|
|
|
- if ( commandLine.hasOption( ARG_VERSION ) ) {
|
|
|
- System.out.println( getVersion() );
|
|
|
- } else if ( commandLine.hasOption( ARG_HELP ) ) {
|
|
|
- outputHelp();
|
|
|
- } else {
|
|
|
- final TomcatConfig tomcatConfig = makeTomcatConfig( commandLine );
|
|
|
- startTomcat(tomcatConfig);
|
|
|
+ tomcatConfig = argumentParser.parseArguments( args );
|
|
|
+ }
|
|
|
+ catch ( ArgumentParserException | TomcatOneJarException e )
|
|
|
+ {
|
|
|
+ out( "error parsing command line: " + e.getMessage() );
|
|
|
+ }
|
|
|
+ if ( tomcatConfig != null )
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ startTomcat( tomcatConfig );
|
|
|
+ }
|
|
|
+ catch ( TomcatOneJarException | ServletException | IOException e )
|
|
|
+ {
|
|
|
+ out( "error starting tomcat: " + e.getMessage() );
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static TomcatConfig makeTomcatConfig(final CommandLine commandLine) throws IOException
|
|
|
+ private static File getWarFolder( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
{
|
|
|
- final TomcatConfig tomcatConfig = new TomcatConfig();
|
|
|
- tomcatConfig.setApplicationPath( parseFileOption( commandLine, ARG_APP_PATH ) );
|
|
|
+ return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "war" );
|
|
|
+ }
|
|
|
|
|
|
- if (commandLine.hasOption( ARG_CONTEXT )) {
|
|
|
- tomcatConfig.setContext( commandLine.getOptionValue( ARG_CONTEXT ) );
|
|
|
- } else {
|
|
|
- tomcatConfig.setContext( DEFAULT_CONTEXT );
|
|
|
- }
|
|
|
+ private static File getKeystoreFile( final TomcatConfig tomcatConfig )
|
|
|
+ {
|
|
|
+ return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "keystore" );
|
|
|
+ }
|
|
|
|
|
|
- if (commandLine.hasOption( ARG_WARFILE )) {
|
|
|
- final File inputWarFile = new File (commandLine.getOptionValue( ARG_WARFILE ));
|
|
|
- if (!inputWarFile.exists()) {
|
|
|
- System.out.println( "output war file " + inputWarFile.getAbsolutePath() + "does not exist" );
|
|
|
- System.exit( -1 );
|
|
|
- return null;
|
|
|
- }
|
|
|
- tomcatConfig.setWar( new FileInputStream( inputWarFile ) );
|
|
|
- } else {
|
|
|
- tomcatConfig.setWar( getEmbeddedWar() );
|
|
|
- }
|
|
|
+ private static File getPwmAppPropertiesFile( final TomcatConfig tomcatConfig )
|
|
|
+ {
|
|
|
+ return new File( tomcatConfig.getWorkingPath().getAbsoluteFile() + File.separator + "application.properties" );
|
|
|
+ }
|
|
|
|
|
|
- tomcatConfig.setPort( DEFAULT_PORT );
|
|
|
- if (commandLine.hasOption( ARG_PORT )) {
|
|
|
- try {
|
|
|
- tomcatConfig.setPort( Integer.parseInt( commandLine.getOptionValue( ARG_PORT ) ) );
|
|
|
- } catch (NumberFormatException e) {
|
|
|
- System.out.println( ARG_PORT + " argument must be numeric" );
|
|
|
- System.exit( -1 );
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
- if ( checkIfPortInUse( tomcatConfig.getPort())) {
|
|
|
- System.out.println( "port " + tomcatConfig.getPort() + " is in use" );
|
|
|
- System.exit( -1 );
|
|
|
- }
|
|
|
+ private static void explodeWar( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
+ {
|
|
|
+ final InputStream warSource = tomcatConfig.getWar();
|
|
|
+ final ZipInputStream zipInputStream = new ZipInputStream( warSource );
|
|
|
+ final File outputFolder = getWarFolder( tomcatConfig );
|
|
|
+ outputFolder.mkdir();
|
|
|
|
|
|
- if (commandLine.hasOption( ARG_WORK_PATH )) {
|
|
|
- tomcatConfig.setWorkingPath( parseFileOption( commandLine, ARG_WORK_PATH ) );
|
|
|
- } else {
|
|
|
- tomcatConfig.setWorkingPath( figureDefaultWorkPath(tomcatConfig) );
|
|
|
- }
|
|
|
+ ZipEntry zipEntry = zipInputStream.getNextEntry();
|
|
|
|
|
|
- return tomcatConfig;
|
|
|
- }
|
|
|
+ while ( zipEntry != null )
|
|
|
+ {
|
|
|
+ final String fileName = zipEntry.getName();
|
|
|
+ final File newFile = new File( outputFolder + File.separator + fileName );
|
|
|
|
|
|
- private static File parseFileOption(final CommandLine commandLine, final String argName) {
|
|
|
- if (!commandLine.hasOption( argName )) {
|
|
|
- outAndExit( "option " + argName + " required");
|
|
|
- }
|
|
|
- final File file = new File(commandLine.getOptionValue( argName ));
|
|
|
- if (!file.isAbsolute()) {
|
|
|
- outAndExit( "a fully qualified file path name is required for " + argName);
|
|
|
- }
|
|
|
- if (!file.exists()) {
|
|
|
- outAndExit( "path specified by " + argName + " must exist");
|
|
|
+ if ( !zipEntry.isDirectory() )
|
|
|
+ {
|
|
|
+ newFile.getParentFile().mkdirs();
|
|
|
+ Files.copy( zipInputStream, newFile.toPath() );
|
|
|
+ }
|
|
|
+ zipEntry = zipInputStream.getNextEntry();
|
|
|
}
|
|
|
- return file;
|
|
|
- }
|
|
|
|
|
|
- private static void outputHelp() throws IOException
|
|
|
- {
|
|
|
- final HelpFormatter formatter = new HelpFormatter();
|
|
|
- System.out.println( getVersion() );
|
|
|
- System.out.println( "usage:" );
|
|
|
- formatter.printOptions( System.console().writer(), HelpFormatter.DEFAULT_WIDTH, makeOptions(),3 , 8);
|
|
|
}
|
|
|
|
|
|
- private static void startTomcat( final TomcatConfig tomcatConfig) throws ServletException, IOException
|
|
|
+ private static void startTomcat( final TomcatConfig tomcatConfig ) throws ServletException, IOException, TomcatOneJarException
|
|
|
{
|
|
|
+ final Instant startTime = Instant.now();
|
|
|
+
|
|
|
purgeDirectory( tomcatConfig.getWorkingPath().toPath() );
|
|
|
+
|
|
|
+ explodeWar( tomcatConfig );
|
|
|
+ out( "deployed war" );
|
|
|
+
|
|
|
+ try
|
|
|
{
|
|
|
- final Path outputPath = tomcatConfig.getWorkingPath().toPath().resolve( EMBED_WAR_NAME );
|
|
|
- final InputStream warSource = tomcatConfig.getWar();
|
|
|
- Files.copy(warSource, outputPath);
|
|
|
+ generatePwmKeystore( tomcatConfig );
|
|
|
+ out( "keystore generated" );
|
|
|
}
|
|
|
- System.setProperty( "PWM_APPLICATIONPATH", tomcatConfig.getApplicationPath().getAbsolutePath() );
|
|
|
+ catch ( Exception e )
|
|
|
+ {
|
|
|
+ throw new TomcatOneJarException( "error generating keystore: " + e.getMessage() );
|
|
|
+ }
|
|
|
+
|
|
|
+ outputPwmAppProperties( tomcatConfig );
|
|
|
+
|
|
|
+ setupEnv( tomcatConfig );
|
|
|
|
|
|
final Tomcat tomcat = new Tomcat();
|
|
|
|
|
@@ -165,171 +162,135 @@ public class TomcatOneJarMain
|
|
|
tomcat.getHost().setAppBase( workPath.getAbsolutePath() );
|
|
|
}
|
|
|
|
|
|
- tomcat.setConnector( makeConnector( tomcatConfig ) );
|
|
|
|
|
|
- tomcat.setPort( DEFAULT_PORT );
|
|
|
- tomcat.getConnector();
|
|
|
+ tomcat.getHost().setAutoDeploy( false );
|
|
|
+ tomcat.getHost().setDeployOnStartup( false );
|
|
|
|
|
|
- tomcat.getHost().setAutoDeploy(false);
|
|
|
- tomcat.getHost().setDeployOnStartup(false);
|
|
|
+ final String warPath = getWarFolder( tomcatConfig ).getAbsolutePath();
|
|
|
+ tomcat.addWebapp( "/" + tomcatConfig.getContext(), warPath );
|
|
|
|
|
|
- final String warPath = tomcatConfig.getWorkingPath().getAbsolutePath() + File.separator + EMBED_WAR_NAME;
|
|
|
- final Context pwmContext = tomcat.addWebapp( "/" + tomcatConfig.getContext(), warPath );
|
|
|
- LOGGER.info("Deployed " + pwmContext.getBaseName() + " as " + pwmContext.getBaseName());
|
|
|
-
|
|
|
- try {
|
|
|
+ try
|
|
|
+ {
|
|
|
tomcat.start();
|
|
|
- } catch (LifecycleException e) {
|
|
|
- outAndExit( "unable to start tomcat: " + e.getMessage() );
|
|
|
+
|
|
|
+ tomcat.setConnector( makeConnector( tomcatConfig ) );
|
|
|
+
|
|
|
+ out( "tomcat started in " + Duration.between( Instant.now(), startTime ).toString() );
|
|
|
+ }
|
|
|
+ catch ( LifecycleException e )
|
|
|
+ {
|
|
|
+ throw new TomcatOneJarException( "unable to start tomcat: " + e.getMessage() );
|
|
|
}
|
|
|
- LOGGER.info("tomcat started on " + tomcat.getHost());
|
|
|
|
|
|
tomcat.getServer().await();
|
|
|
- }
|
|
|
|
|
|
- private static Connector makeConnector(final TomcatConfig tomcatConfig) {
|
|
|
- final Connector connector = new Connector("HTTP/1.1");
|
|
|
- connector.setPort(tomcatConfig.getPort());
|
|
|
- return connector;
|
|
|
+ System.out.println( "\n" );
|
|
|
}
|
|
|
|
|
|
- private static CommandLine parseOptions(final String[] args) {
|
|
|
- final CommandLineParser parser = new DefaultParser();
|
|
|
- try {
|
|
|
- return parser.parse( makeOptions(), args);
|
|
|
- } catch ( ParseException e ) {
|
|
|
- outAndExit( "error parsing commandline: " + e.getMessage() );
|
|
|
+ private static Connector makeConnector( final TomcatConfig tomcatConfig )
|
|
|
+ {
|
|
|
+ final Connector connector = new Connector( "HTTP/1.1" );
|
|
|
+ connector.setPort( tomcatConfig.getPort() );
|
|
|
+
|
|
|
+ if ( tomcatConfig.getLocalAddress() != null && !tomcatConfig.getLocalAddress().isEmpty() )
|
|
|
+ {
|
|
|
+ connector.setProperty( "address", tomcatConfig.getLocalAddress() );
|
|
|
}
|
|
|
- return null;
|
|
|
- }
|
|
|
+ connector.setSecure( true );
|
|
|
+ connector.setScheme( "https" );
|
|
|
+ connector.setAttribute( "SSLEnabled", "true" );
|
|
|
+ connector.setAttribute( "keystoreFile", getKeystoreFile( tomcatConfig ).getAbsolutePath() );
|
|
|
+ connector.setAttribute( "keystorePass", tomcatConfig.getKeystorePass() );
|
|
|
+ connector.setAttribute( "keyAlias", KEYSTORE_ALIAS );
|
|
|
+ connector.setAttribute( "clientAuth", "false" );
|
|
|
|
|
|
- private static Options makeOptions() {
|
|
|
- final Map<String,Option> optionMap = new TreeMap<>( );
|
|
|
-
|
|
|
- optionMap.put(ARG_APP_PATH,Option.builder(ARG_APP_PATH)
|
|
|
- .desc( "application path (required)" )
|
|
|
- .numberOfArgs( 1 )
|
|
|
- .required(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- optionMap.put(ARG_WORK_PATH,Option.builder(ARG_WORK_PATH)
|
|
|
- .desc( "temporary work path" )
|
|
|
- .numberOfArgs( 1 )
|
|
|
- .required(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- optionMap.put(ARG_VERSION,Option.builder(ARG_VERSION)
|
|
|
- .desc( "show version" )
|
|
|
- .numberOfArgs( 0 )
|
|
|
- .required(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- optionMap.put(ARG_PORT,Option.builder()
|
|
|
- .longOpt( ARG_PORT )
|
|
|
- .desc( "web server port (default " + DEFAULT_PORT + ")" )
|
|
|
- .numberOfArgs( 1 )
|
|
|
- .build() );
|
|
|
-
|
|
|
- optionMap.put(ARG_CONTEXT,Option.builder()
|
|
|
- .longOpt( ARG_CONTEXT )
|
|
|
- .desc( "context (url path) name (default " + DEFAULT_CONTEXT + ")" )
|
|
|
- .numberOfArgs( 1 )
|
|
|
- .build() );
|
|
|
-
|
|
|
- optionMap.put(ARG_HELP,Option.builder(ARG_HELP)
|
|
|
- .desc( "show this help" )
|
|
|
- .numberOfArgs( 0 )
|
|
|
- .required(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- optionMap.put(ARG_WARFILE,Option.builder(ARG_WARFILE)
|
|
|
- .desc( "source war file (default embedded)" )
|
|
|
- .numberOfArgs( 1 )
|
|
|
- .required(false)
|
|
|
- .build());
|
|
|
-
|
|
|
- final Options options = new Options();
|
|
|
- optionMap.values().forEach( options::addOption );
|
|
|
- return options;
|
|
|
+ return connector;
|
|
|
}
|
|
|
|
|
|
- private static InputStream getEmbeddedWar() throws IOException
|
|
|
+ static String getVersion( ) throws TomcatOneJarException
|
|
|
{
|
|
|
- final Class clazz = TomcatOneJarMain.class;
|
|
|
- final String className = clazz.getSimpleName() + ".class";
|
|
|
- final String classPath = clazz.getResource(className).toString();
|
|
|
- if (!classPath.startsWith("jar")) {
|
|
|
- outAndExit("not running from war, war option must be specified");
|
|
|
- return null;
|
|
|
+ try
|
|
|
+ {
|
|
|
+ final Class clazz = TomcatOneJarMain.class;
|
|
|
+ final String className = clazz.getSimpleName() + ".class";
|
|
|
+ final String classPath = clazz.getResource( className ).toString();
|
|
|
+ if ( !classPath.startsWith( "jar" ) )
|
|
|
+ {
|
|
|
+ // Class not from JAR
|
|
|
+ return "version missing, not running inside jar";
|
|
|
+ }
|
|
|
+ final String manifestPath = classPath.substring( 0, classPath.lastIndexOf( "!" ) + 1 )
|
|
|
+ + "/META-INF/MANIFEST.MF";
|
|
|
+ final Manifest manifest = new Manifest( new URL( manifestPath ).openStream() );
|
|
|
+ final Attributes attr = manifest.getMainAttributes();
|
|
|
+ return attr.getValue( "Implementation-Version-Display" )
|
|
|
+ + " [" + ServerInfo.getServerInfo() + "]";
|
|
|
}
|
|
|
- final String warPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
|
|
|
- "/" + EMBED_WAR_NAME;
|
|
|
- return new URL(warPath).openStream();
|
|
|
- }
|
|
|
-
|
|
|
- private static String getVersion() throws IOException
|
|
|
- {
|
|
|
- final Class clazz = TomcatOneJarMain.class;
|
|
|
- final String className = clazz.getSimpleName() + ".class";
|
|
|
- final String classPath = clazz.getResource(className).toString();
|
|
|
- if (!classPath.startsWith("jar")) {
|
|
|
- // Class not from JAR
|
|
|
- return "--version missing--";
|
|
|
+ catch ( IOException e )
|
|
|
+ {
|
|
|
+ throw new TomcatOneJarException( "error reading internal version info: " + e.getMessage() );
|
|
|
}
|
|
|
- final String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
|
|
|
- "/META-INF/MANIFEST.MF";
|
|
|
- final Manifest manifest = new Manifest(new URL(manifestPath).openStream());
|
|
|
- final Attributes attr = manifest.getMainAttributes();
|
|
|
- return attr.getValue("Implementation-Version-Display")
|
|
|
- + ", " + ServerInfo.getServerInfo();
|
|
|
}
|
|
|
|
|
|
- private static void purgeDirectory(final Path rootPath)
|
|
|
+ private static void purgeDirectory( final Path rootPath )
|
|
|
throws IOException
|
|
|
{
|
|
|
- System.out.println("purging work directory: " + rootPath);
|
|
|
- Files.walk(rootPath, FileVisitOption.FOLLOW_LINKS)
|
|
|
- .sorted( Comparator.reverseOrder())
|
|
|
- .map(Path::toFile)
|
|
|
+ System.out.println( "purging work directory: " + rootPath );
|
|
|
+ Files.walk( rootPath, FileVisitOption.FOLLOW_LINKS )
|
|
|
+ .sorted( Comparator.reverseOrder() )
|
|
|
+ .map( Path::toFile )
|
|
|
.filter( file -> !rootPath.toString().equals( file.getPath() ) )
|
|
|
- .forEach(File::delete);
|
|
|
+ .forEach( File::delete );
|
|
|
}
|
|
|
|
|
|
- private static boolean checkIfPortInUse( final int portNumber) {
|
|
|
- boolean result;
|
|
|
|
|
|
- try {
|
|
|
- Socket s = new Socket("localhost", portNumber);
|
|
|
- s.close();
|
|
|
- result = true;
|
|
|
- } catch(IOException e) {
|
|
|
- result = false;
|
|
|
- }
|
|
|
-
|
|
|
- return(result);
|
|
|
+ static void out( final String output )
|
|
|
+ {
|
|
|
+ System.out.println( output );
|
|
|
}
|
|
|
|
|
|
- private static File figureDefaultWorkPath(final TomcatConfig tomcatConfig) {
|
|
|
- final String userHomePath = System.getProperty( "user.home" );
|
|
|
- if (userHomePath != null && !userHomePath.isEmpty()) {
|
|
|
- final File basePath = new File(userHomePath + File.separator
|
|
|
- + "." + DEFAULT_CONTEXT);
|
|
|
- basePath.mkdir();
|
|
|
- final File workPath = new File( basePath.getPath() + File.separator
|
|
|
- + "work-" + tomcatConfig.getContext() + "-" + Integer.toString( tomcatConfig.getPort() ));
|
|
|
- workPath.mkdir();
|
|
|
- System.out.println( "using work directory: " + workPath.getAbsolutePath() );
|
|
|
- return workPath;
|
|
|
+
|
|
|
+ static void generatePwmKeystore( final TomcatConfig tomcatConfig )
|
|
|
+ throws IOException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException
|
|
|
+ {
|
|
|
+ final File warPath = getWarFolder( tomcatConfig );
|
|
|
+ final String keystoreFile = getKeystoreFile( tomcatConfig ).getAbsolutePath();
|
|
|
+ final File webInfPath = new File( warPath.getAbsolutePath() + File.separator + "WEB-INF" + File.separator + "lib" );
|
|
|
+ final File[] jarFiles = webInfPath.listFiles();
|
|
|
+ final List<URL> jarURLList = new ArrayList<>();
|
|
|
+ for ( final File jarFile : jarFiles )
|
|
|
+ {
|
|
|
+ jarURLList.add( jarFile.toURI().toURL() );
|
|
|
}
|
|
|
+ final URLClassLoader classLoader = URLClassLoader.newInstance( jarURLList.toArray( new URL[ jarURLList.size() ] ) );
|
|
|
+ final Class pwmMainClass = classLoader.loadClass( "password.pwm.util.cli.MainClass" );
|
|
|
+ final Method mainMethod = pwmMainClass.getMethod( "main", String[].class );
|
|
|
+ final String[] arguments = new String[] {
|
|
|
+ "-applicationPath=" + tomcatConfig.getApplicationPath().getAbsolutePath(),
|
|
|
+ "ExportHttpsKeyStore",
|
|
|
+ keystoreFile,
|
|
|
+ KEYSTORE_ALIAS,
|
|
|
+ tomcatConfig.getKeystorePass(),
|
|
|
+ };
|
|
|
+
|
|
|
+ mainMethod.invoke( null, ( Object ) arguments );
|
|
|
+ classLoader.close();
|
|
|
+ }
|
|
|
|
|
|
- System.out.println( "cant locate user home directory" );
|
|
|
- System.exit( -1 );
|
|
|
- return null;
|
|
|
+ static void setupEnv( final TomcatConfig tomcatConfig )
|
|
|
+ {
|
|
|
+ System.setProperty( "PWM_APPLICATIONPATH", tomcatConfig.getApplicationPath().getAbsolutePath() );
|
|
|
+ System.setProperty( "PWM_APPLICATIONFLAGS", "ManageHttps" );
|
|
|
+ System.setProperty( "PWM_APPLICATIONPARAMFILE", getPwmAppPropertiesFile( tomcatConfig ).getAbsolutePath() );
|
|
|
}
|
|
|
|
|
|
- private static Object outAndExit(final String output) {
|
|
|
- System.out.println(output);
|
|
|
- System.exit( -1 );
|
|
|
- return null;
|
|
|
+ static void outputPwmAppProperties( final TomcatConfig tomcatConfig ) throws IOException
|
|
|
+ {
|
|
|
+ final Properties properties = new Properties();
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStoreFile", getKeystoreFile( tomcatConfig ).getAbsolutePath() );
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStorePassword", tomcatConfig.getKeystorePass() );
|
|
|
+ properties.setProperty( "AutoExportHttpsKeyStoreAlias", KEYSTORE_ALIAS );
|
|
|
+ final File propFile = getPwmAppPropertiesFile( tomcatConfig );
|
|
|
+ properties.store( new FileWriter( propFile ), "auto-generated file" );
|
|
|
}
|
|
|
}
|