dev@glassfish.java.net

Re: code review request: GFLauncher

From: Bobby Bissett <bobby.bissett_at_oracle.com>
Date: Fri, 10 Dec 2010 13:38:49 -0500

I swear the string substitution wasn't working for me yesterday, but now it's fine. Anyway, "final" diff is below.

------------------------------------------
Index: admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java
===================================================================
--- admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java (revision 43670)
+++ admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/GFLauncher.java (working copy)
@@ -51,6 +51,7 @@
 import com.sun.enterprise.universal.process.ProcessStreamDrainer;
 import com.sun.enterprise.universal.xml.MiniXmlParserException;
 import com.sun.enterprise.util.OS;
+import com.sun.enterprise.util.io.FileUtils;
 import com.sun.enterprise.util.net.NetUtils;
 import com.sun.enterprise.universal.glassfish.ASenvPropertyReader;
 import com.sun.enterprise.universal.xml.MiniXmlParser;
@@ -156,6 +157,7 @@
         info.setAdminAddresses(parser.getAdminAddresses());
         javaConfig = new JavaConfig(parser.getJavaConfig());
         setupProfilerAndJvmOptions(parser);
+ setupUpgradeSecurity();
         setupMonitoring(parser);
         sysPropsFromXml = parser.getSystemProperties();
         asenvProps.put(INSTANCE_ROOT_PROPERTY, getInfo().getInstanceRootDir().getPath());
@@ -666,6 +668,31 @@
         jvmOptions = new JvmOptions(rawJvmOptions);
     }
 
+ private void setupUpgradeSecurity() throws GFLauncherException {
+ // If this is an upgrade and the security manager is on,
+ // copy the current server.policy file to the domain
+ // before the upgrade.
+ if (info.isUpgrade() &&
+ jvmOptions.sysProps.containsKey("java.security.manager")) {
+
+ GFLauncherLogger.info(strings.get("copy_server_policy"));
+
+ File source = new File(new File(new File(info.installDir, "lib"),
+ "templates"), "server.policy");
+ File target = new File(info.getConfigDir(), "server.policy");
+
+ try {
+ FileUtils.copyFile(source, target);
+ } catch (IOException ioe) {
+ // the actual error is wrapped differently depending on
+ // whether the problem was with the source or target
+ Throwable cause = ioe.getCause() == null ? ioe : ioe.getCause();
+ throw new GFLauncherException(strings.get(
+ "copy_server_policy_error", cause.getMessage()));
+ }
+ }
+ }
+
     private void setupMonitoring(MiniXmlParser parser) throws GFLauncherException {
         // As usual we have to be very careful.
 
Index: admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/LocalStrings.properties
===================================================================
--- admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/LocalStrings.properties (revision 43670)
+++ admin/launcher/src/main/java/com/sun/enterprise/admin/launcher/LocalStrings.properties (working copy)
@@ -80,4 +80,7 @@
 #'ssh' message from Sathyan Catari see IT 13862 October 19, 2010
 ssh=Attempting to start {0}.... Please look at the server log for more details.....
 
-
+# issue 11665
+copy_server_policy=Will copy glassfish/lib/templates/server.policy file to domain before upgrading.
+copy_server_policy_error=Could not copy server.policy to domain. You may need to turn off the \
+ security manager before upgrading.\nCause: {0}