diff options
Diffstat (limited to 'netx')
-rw-r--r-- | netx/net/sourceforge/jnlp/JNLPFile.java | 121 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/PluginBridge.java | 13 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/ResourcesDesc.java | 29 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java | 27 | ||||
-rw-r--r-- | netx/net/sourceforge/jnlp/security/CertWarningPane.java | 21 |
5 files changed, 181 insertions, 30 deletions
diff --git a/netx/net/sourceforge/jnlp/JNLPFile.java b/netx/net/sourceforge/jnlp/JNLPFile.java index 9f38d4b..65c4538 100644 --- a/netx/net/sourceforge/jnlp/JNLPFile.java +++ b/netx/net/sourceforge/jnlp/JNLPFile.java @@ -27,9 +27,11 @@ import java.util.Calendar; import java.util.LinkedList; import java.util.List; import java.util.Locale; +import java.util.jar.Attributes; import net.sourceforge.jnlp.cache.ResourceTracker; import net.sourceforge.jnlp.cache.UpdatePolicy; +import net.sourceforge.jnlp.runtime.JNLPClassLoader; import net.sourceforge.jnlp.runtime.JNLPRuntime; import net.sourceforge.jnlp.util.logging.OutputController; @@ -51,6 +53,13 @@ import net.sourceforge.jnlp.util.logging.OutputController; * @version $Revision: 1.21 $ */ public class JNLPFile { + + + public static final String APP_NAME = "Application-Name"; + public static final String CALLER_ALLOWABLE = "Caller-Allowable-Codebase"; + public static final String APP_LIBRARY_ALLOWABLE = "Application-Library-Allowable-Codebase"; + + // todo: save the update policy, then if file was not updated // then do not check resources for being updated. @@ -121,6 +130,10 @@ public class JNLPFile { * List of acceptable properties (not-special) */ private String[] generalProperties = SecurityDesc.getJnlpRIAPermissions(); + + /** important manifests' attributes */ + private final ManifestsAttributes manifestsAttributes = new ManifestsAttributes(); + { // initialize defaults if security allows try { @@ -293,10 +306,46 @@ public class JNLPFile { /** * Returns the JNLP file's best localized title. This method returns the same * value as InformationDesc.getTitle(). + * + * Since jdk7 u45, also manifest title, and mainclass are taken to consideration; + * See PluginBridge */ public String getTitle() { + String jnlpTitle = getTitleFromJnlp(); + String manifestTitle = getTitleFromManifest(); + if (jnlpTitle != null && manifestTitle != null) { + if (jnlpTitle.equals(manifestTitle)) { + return jnlpTitle; + } + return jnlpTitle+" ("+manifestTitle+")"; + } + if (jnlpTitle != null && manifestTitle == null) { + return jnlpTitle; + } + if (jnlpTitle == null && manifestTitle != null) { + return manifestTitle; + } + String mainClass = getManifestsAttributes().getMainClass(); + return mainClass; + } + + /** + * Returns the JNLP file's best localized title. This method returns the same + * value as InformationDesc.getTitle(). + */ + public String getTitleFromJnlp() { return getInformation().getTitle(); } + + public String getTitleFromManifest() { + String inManifestTitle = getManifestsAttributes().getApplicationName(); + if (inManifestTitle == null && getManifestsAttributes().isLoader()){ + OutputController.getLogger().log(OutputController.Level.WARNING_ALL,"Application title was not found in manifest. Check with application vendor"); + } + return inManifestTitle; + } + + /** * Returns the JNLP file's best localized vendor. This method returns the same @@ -818,4 +867,76 @@ public class JNLPFile { public void setSignedJNLPAsMissing() { missingSignedJNLP = true; } + + public ManifestsAttributes getManifestsAttributes() { + return manifestsAttributes; + } + + + public class ManifestsAttributes{ + private JNLPClassLoader loader; + + + public void setLoader(JNLPClassLoader loader) { + this.loader = loader; + } + + public boolean isLoader() { + return loader != null; + } + + + + /** + * main class can be defined outside of manifest. + * This method is mostly for completeness + */ + public String getMainClass(){ + if (loader == null) { + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Jars not ready to provide main class"); + return null; + } + return loader.getMainClass(); + } + + /** + * http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html#app_name + */ + public String getApplicationName(){ + return getAttribute(APP_NAME); + } + + /** + * http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html#caller_allowable + */ + public String getCallerAllowableCodebase(){ + return getAttribute(CALLER_ALLOWABLE); + } + + /** + * http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html#app_library + */ + public String getApplicationLibraryAllowableCodebase(){ + return getAttribute(APP_LIBRARY_ALLOWABLE); + } + + /** + * get custom attribute. + */ + public String getAttribute(String name){ + return getAttribute(new Attributes.Name(name)); + } + + /** + * get standard attribute + */ + public String getAttribute(Attributes.Name name){ + if (loader == null) { + OutputController.getLogger().log(OutputController.Level.ERROR_DEBUG, "Jars not ready to provide attribute "+ name); + return null; + } + return loader.checkForAttributeInJars(Arrays.asList(getResources().getJARs()), name); + } + } + } diff --git a/netx/net/sourceforge/jnlp/PluginBridge.java b/netx/net/sourceforge/jnlp/PluginBridge.java index 3b1cf37..7228521 100644 --- a/netx/net/sourceforge/jnlp/PluginBridge.java +++ b/netx/net/sourceforge/jnlp/PluginBridge.java @@ -184,7 +184,7 @@ public class PluginBridge extends JNLPFile { // the class name should be of the form foo.bar.Baz not foo/bar/Baz String mainClass = main.replace('/', '.'); - launchType = new AppletDesc(params.getAppletTitle(), mainClass, documentBase, width, + launchType = new AppletDesc(getTitle(), mainClass, documentBase, width, height, params.getUnmodifiableMap()); if (main.endsWith(".class")) //single class file only @@ -231,7 +231,18 @@ public class PluginBridge extends JNLPFile { return new DownloadOptions(usePack, useVersion); } + @Override public String getTitle() { + String inManifestTitle = super.getTitleFromManifest(); + if (inManifestTitle != null) { + return inManifestTitle; + } + //specification is recommending main class instead of html parameter + //http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/manifest.html#app_name + String mainClass = getManifestsAttributes().getMainClass(); + if (mainClass != null) { + return mainClass; + } return params.getAppletTitle(); } diff --git a/netx/net/sourceforge/jnlp/ResourcesDesc.java b/netx/net/sourceforge/jnlp/ResourcesDesc.java index 42eec01..988c55b 100644 --- a/netx/net/sourceforge/jnlp/ResourcesDesc.java +++ b/netx/net/sourceforge/jnlp/ResourcesDesc.java @@ -67,23 +67,30 @@ public class ResourcesDesc { return resources.toArray(new JREDesc[resources.size()]); } - /** - * Returns the main JAR for these resources. There first JAR - * is returned if no JARs are specified as the main JAR, and if - * there are no JARs defined then null is returned. - */ - public JARDesc getMainJAR() { - JARDesc jars[] = getJARs(); + public static JARDesc getMainJAR(JARDesc jars[] ) { + return getMainJAR(Arrays.asList(jars)); + } + public static JARDesc getMainJAR(List<JARDesc> jars) { for (JARDesc jar : jars) { - if (jar.isMain()) + if (jar.isMain()) { return jar; + } } - if (jars.length > 0) - return jars[0]; - else + if (jars.size() > 0) { + return jars.get(0); + } else { return null; + } + } + /** + * Returns the main JAR for these resources. There first JAR + * is returned if no JARs are specified as the main JAR, and if + * there are no JARs defined then null is returned. + */ + public JARDesc getMainJAR() { + return getMainJAR(getJARs()); } /** diff --git a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java index a9a84ba..e694b9e 100644 --- a/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java +++ b/netx/net/sourceforge/jnlp/runtime/JNLPClassLoader.java @@ -115,7 +115,7 @@ public class JNLPClassLoader extends URLClassLoader { /** Signed JNLP File and Template */ final public static String TEMPLATE = "JNLP-INF/APPLICATION_TEMPLATE.JNLP"; final public static String APPLICATION = "JNLP-INF/APPLICATION.JNLP"; - + /** Actions to specify how cache is to be managed **/ public static enum DownloadAction { DOWNLOAD_TO_CACHE, REMOVE_FROM_CACHE, CHECK_CACHE @@ -200,7 +200,7 @@ public class JNLPClassLoader extends URLClassLoader { /** Name of the application's main class */ private String mainClass = null; - + /** * Variable to track how many times this loader is in use */ @@ -245,6 +245,9 @@ public class JNLPClassLoader extends URLClassLoader { this.mainClass = mainName; + //as it is harmless, we can set is as soon as possible. + file.getManifestsAttributes().setLoader(this); + AppVerifier verifier; if (file instanceof PluginBridge && !((PluginBridge)file).useJNLPHref()) { @@ -259,13 +262,15 @@ public class JNLPClassLoader extends URLClassLoader { initializeExtensions(); initializeResources(); + // initialize permissions initializePermissions(); setSecurity(); - + installShutdownHooks(); + } @@ -786,7 +791,7 @@ public class JNLPClassLoader extends URLClassLoader { String result = null; // Check main jar - JARDesc mainJarDesc = file.getResources().getMainJAR(); + JARDesc mainJarDesc = ResourcesDesc.getMainJAR(jars); result = getManifestAttribute(mainJarDesc.getLocation(), name); if (result != null) { @@ -803,10 +808,10 @@ public class JNLPClassLoader extends URLClassLoader { // Still not found? Iterate and set if only 1 was found for (JARDesc jarDesc: jars) { - String mainClassInThisJar = getManifestAttribute(jarDesc.getLocation(), name); - if (mainClassInThisJar != null) { + String attributeInThisJar = getManifestAttribute(jarDesc.getLocation(), name); + if (attributeInThisJar != null) { if (result == null) { // first main class - result = mainClassInThisJar; + result = attributeInThisJar; } else { // There is more than one main class. Set to null and break. result = null; break; @@ -2193,6 +2198,10 @@ public class JNLPClassLoader extends URLClassLoader { return new AccessControlContext(new ProtectionDomain[] { pd }); } + + public String getMainClass() { + return mainClass; + } /* * Helper class to expose protected URLClassLoader methods. @@ -2317,6 +2326,6 @@ public class JNLPClassLoader extends URLClassLoader { return null; } } - - + + } diff --git a/netx/net/sourceforge/jnlp/security/CertWarningPane.java b/netx/net/sourceforge/jnlp/security/CertWarningPane.java index f9273fa..dae8030 100644 --- a/netx/net/sourceforge/jnlp/security/CertWarningPane.java +++ b/netx/net/sourceforge/jnlp/security/CertWarningPane.java @@ -107,13 +107,14 @@ public class CertWarningPane extends SecurityDialogPanel { //these strings -- we just want to fill in as many as possible. try { if ((certVerifier instanceof HttpsCertVerifier) && - (c instanceof X509Certificate)) + (c instanceof X509Certificate)) { name = SecurityUtil.getCN(((X509Certificate) c) .getSubjectX500Principal().getName()); - else if (file instanceof PluginBridge) + } else if (file instanceof PluginBridge) { name = file.getTitle(); - else + } else { name = file.getInformation().getTitle(); + } } catch (Exception e) { } @@ -126,10 +127,11 @@ public class CertWarningPane extends SecurityDialogPanel { } try { - if (file instanceof PluginBridge) + if (file instanceof PluginBridge) { from = file.getCodeBase().getHost(); - else + } else { from = file.getInformation().getHomepage().toString(); + } } catch (Exception e) { } @@ -146,7 +148,7 @@ public class CertWarningPane extends SecurityDialogPanel { topLabelText = R("SHttpsUnverified") + " " + R("Continue"); propertyName = "OptionPane.warningIcon"; iconLocation += "warning.png"; - } else + } else { switch (type) { case VERIFIED: topLabelText = R("SSigVerified"); @@ -167,7 +169,7 @@ public class CertWarningPane extends SecurityDialogPanel { bottomLabelText += " " + R("SWarnFullPermissionsIgnorePolicy"); break; } - + } ImageIcon icon = new ImageIcon((new sun.misc.Launcher()) .getClassLoader().getResource(iconLocation)); JLabel topLabel = new JLabel(htmlWrap(topLabelText), icon, SwingConstants.LEFT); @@ -195,8 +197,9 @@ public class CertWarningPane extends SecurityDialogPanel { infoPanel.add(nameLabel); infoPanel.add(publisherLabel); - if (!(certVerifier instanceof HttpsCertVerifier)) + if (!(certVerifier instanceof HttpsCertVerifier)) { infoPanel.add(fromLabel); + } infoPanel.add(alwaysTrust); infoPanel.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25)); @@ -225,7 +228,7 @@ public class CertWarningPane extends SecurityDialogPanel { add(infoPanel); add(buttonPanel); - JLabel bottomLabel = new JLabel(htmlWrap(bottomLabelText));; + JLabel bottomLabel = new JLabel(htmlWrap(bottomLabelText)); JButton moreInfo = new JButton(R("ButMoreInformation")); moreInfo.addActionListener(new MoreInfoButtonListener()); |