初始化,读取和写入安全令牌的小程序显示以下例外:
com.sun.deploy.security.BlockedException: User has denied the privileges to the code
sun.plugin2.applet.Plugin2ClassLoader.getPermissions(Unknown Source)
sun.plugin2.applet.Applet2ClassLoader.getPermissions(Unknown Source)
java.security.SecureClassLoader.getProtectionDomain(Unknown Source)
java.security.SecureClassLoader.defineClass(Unknown Source)
sun.plugin2.applet.Applet2ClassLoader.findClass(Unknown Source)
sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Unknown Source)
sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
sun.plugin2.applet.Plugin2ClassLoader.loadClass(Unknown Source)
java.lang.ClassLoader.loadClass(Unknown Source)
和
User has denied the privileges to the code
代码如下,JTextArea用于显示结果。
public static void test(final JTextArea textArea) throws Exception {
AccessController.doPrivileged(new PrivilegedAction() {
@Override
public Object run() {
try{
final String label = "Test123";
textArea.setText(textArea.getText() + "\n\n\t" + Misc.getMethod());
initializeToken(textArea, label, "123456".toCharArray());
textArea.setText(textArea.getText() + "\n\n\t\tinit OK");
writeDataToToken(label, new byte[]{0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f}, "123456".toCharArray());
textArea.setText(textArea.getText() + "\n\n\t\twrite OK");
byte[] dataRead = readDataFromToken(label, "123456".toCharArray());
for (byte i : dataRead) {
System.out.println((int) i);
}
textArea.setText(textArea.getText() + "\n\n\t\tread OK");
}
catch(Exception e){
textArea.setText(textArea.getText() + "\n\n\t\t" + Misc.getStackTrace(e));
}
return null;
}
});
}
以下是HTML
中的applet代码<applet code = 'test.GUI'
archive = 'TestApplet.jar, lib/TestLib.jar'
width = 700
height = 500>
<resources>
<nativelib href="nativeLib.dll"/>
</resources>
<param name="permissions" value="all-permissions" />
</applet>
appletPolicy.txt
Permissions: all-permissions
Application-Name: TestApplet
Codebase: https://www.localhost.com:8443/TestApplet.jar
...然后将其应用于applet jar TestApplet.jar并使用以下内容重新签名:
jar ufm dist\TestApplet.jar appletPolicy.txt
jar ufm dist\lib\TestLib.jar appletPolicy.txt
jarsigner dist\TestApplet.jar -keystore web.jks" web -storepass password
jarsigner dist\lib\TestLib.jar -keystore web.jks" web -storepass password
如何摆脱异常并使applet工作?
UPDATE :文件IO操作没有问题 - 即使文件IO操作的代码不在AccessController.doPrivileged中,Applet也能够读取和写入而不会导致任何安全异常()方法。
我也尝试过签署nativeLib.dll,但没有区别。