1

I have a Java Applet that was running fine using an early version of Java 7 but now on Java 8 I'm having permission issues. Here is the specific error I'm getting:

May 28, 2015 12:57:15 PM [com.sun.xml.internal.ws.assembler.MetroConfigLoader]  init
WARNING: MASM0010: Unable to unmarshall metro config file from location [ jar:file:/C:/Program%20Files/Java/jre1.8.0_45/lib/resources.jar!/com/sun/xml/internal/ws/assembler/jaxws-tubes-default.xml ]
java.security.AccessControlException: access denied ("java.lang.RuntimePermission" "accessDeclaredMembers")

It seems that due to a permissions issue it can't access the xml file to load the configuration. I've tried updating my java policy files to allow that permission but it doesn't seem to be helping. In javaws.policy & java.policy for both my JDK and JRE I've added the following inside the 'grant {' and at the top inside 'grant codeBase "file:${{java.ext.dirs}}/*" {':

permission java.lang.RuntimePermission "accessDeclaredMembers";

The above line doesn't seem to make any difference though.

I'm also signing my main JAR and all the supporting library JARs using an Ant build script. Here is the part of my Ant

    <mkdir dir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/org.apache.wink/wink-client/jars/wink-client-1.1-incubating.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/org.apache.wink/wink-common/jars/wink-common-1.1-incubating.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/org.slf4j/slf4j-api/jars/slf4j-api-1.5.11.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/org.slf4j/slf4j-jdk14/jars/slf4j-jdk14-1.5.11.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/javax.xml.bind/jaxb-api/jars/jaxb-api-2.1.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/javax.xml.stream/stax-api/jars/stax-api-1.0-2.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/javax.activation/activation/jars/activation-1.1.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/com.sun.xml.bind/jaxb-impl/jars/jaxb-impl-2.1.4.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/javax.ws.rs/jsr311-api/jars/jsr311-api-1.1.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/commons-codec/commons-codec/jars/commons-codec-1.3.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <copy file="D:/Users/user/.ivy2/cache/xpp3/xpp3_min/jars/xpp3_min-1.1.4c.jar" todir="H:/Eclipse Projects/myProgram/dist/myProgram_lib"/>
    <signjar alias="xxxxxxxxxxxxxxxxx" keystore="xxxxxxxxxxxxxx" storepass="xxxxxx" lazy="true">
         <path>
           <fileset dir="dist" includes="**/*.jar" />
         </path>
           </signjar>

I've got this inside the part of the Ant script that updates the manifest file:

<manifest>
<attribute name="Permissions" value="all-permissions"/>
<attribute name="Main-Class" value="myProgram.MainFrame"/>
</manifest>

Does anyone know what I can to to get rid of this permissions issue so my code can get the necessary configuration file and run?

Thanks!

1 Answer 1

2

In Java 8 you really need to sign all your JARs with a valid certificate. You are saying that you are doing this with ANT, but please check with the command below if they were really signed.

jarsigner -verify yourjar.jar

Try to add more attributes to your manifest.

<codebase>http://location.of.your.jar/</codebase>
<permissions>all-permissions</permissions>
<Application-Library-Allowable-Codebase>http://location.of.your.jar/</Application-Library-Allowable-Codebase>
<Manifest-Version>1.0</Manifest-Version>
<Implementation-Title>App Name</Implementation-Title>
<Implementation-Version>0.1.0</Implementation-Version>
<Application-Name></Application-Name>
<Created-By>1.8.0_45</Created-By>
<Main-Class>package.YourClass</Main-Class>
<mode>development (or production)</mode>
<url>url of the application</url>

Besides that, you need add some more code - related to security - to work, please check an example below:

package io.github.ulymarins;

import java.applet.Applet;
import java.security.AccessController;
import java.security.PrivilegedAction;

/**
 *
 * @author Ulysses Marins <[email protected]>
 */
public final class TestApplet extends Applet
{

	private static final long serialVersionUID = 1L;

	String ret;  

	@SuppressWarnings({ "rawtypes", "unchecked" })
	public String signFile(final String pmessage)
	{
		AccessController.doPrivileged(new PrivilegedAction()
		{
			public Object run()
			{  
				try
				{                             
					String sl = "{\"success\":true," + "\"message\":\"" + pmessage + "\"}";
					ret = sl;					
				}
				catch (Exception e)
				{
					String sl = "{\"success\":false," + "\"message\":\"" + e.getMessage() + "\"}";
					ret = sl;
					System.out.println(sl);					
				}
				
				return null;
			}
		});
				
		return ret;
	}
	
	
	public void init(){		
		// Here you can put the code which will be executed when the applet starts
	}
	
	public void destroy(){	
		// Here you can put the code which will be executed when the applet stops
	}
	
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.