开发者

Signed applet with code inside a PrivilegedAction throws PrivilegedAccessException when called from Javascript

开发者 https://www.devze.com 2023-04-03 21:45 出处:网络
I have a signed applet that executes some code inside the PrivilegedAction. public String somePublicMethod()

I have a signed applet that executes some code inside the PrivilegedAction.

public String somePublicMethod()
{
        String str = (String) AccessController.doPrivileged(new PrivilegedAction() 
        {
            public Object run() 
            {
                return someMethodThatReturnsAString();
            }
        });
        return str;
}

Here the method someMethodThatReturnsAString is in the super class and that class is in a third party jar which is also signed. somePublicMethod throws the following exception when called from Javascript

java.security.PrivilegedActionException: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation.CallMethod(SecureInvocation.java:128)
at sun.plugin.liveconnect.SecureInvocation.access$300(SecureInvocation.java:51)
at sun.plugin.liveconnect.SecureInvocation$CallMethodThread.run(SecureInvocation.java:177)
Caused by: java.security.PrivilegedActionException: java.lang.reflect.InvocationTargetException
at java.security.AccessController.doPrivileged(Native Method)
at sun.plugin.liveconnect.SecureInvocation$2.run(SecureInvocation.java:147)
... 4 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMeth开发者_StackOverflowodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.plugin.javascript.JSInvoke.invoke(JSInvoke.java:20)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at sun.plugin.javascript.JSClassLoader.invoke(JSClassLoader.java:72)
at sun.plugin.liveconnect.PrivilegedCallMethodAction.run(SecureInvocation.java:651)
... 6 more
Caused by: java.lang.NullPointerException
at java.lang.String.replace(String.java:2207)
... 16 more

This only happens in Safari in Mac OS X with Java 1.6 installed. Works as expected when Java 1.5 is installed on the client machine.

I saw similar questions here on StackOverflow that talked about AccessControlException thrown from signed applets. But this is different as the exception thrown is PrivilegedAccessException and the applet executes the code as a Privileged Action as suggested in the answers to those questions.

I have even tried using PrivilegedExceptionAction but that did not help. Has anybody encountered this before?


I found the solution for this. The problem was not with the applet but with the code in JavaScript which manipulates the string returned by the applet method. The string was treated as a Java object and not a JavaScript object and this was causing issues in Safari. Converting the Java string to JavaScript string solved the issue.

I could not get the full stack trace in the browser's error console so I relied on the Java console logs. The log messages were a bit misleading as it made appear that this error originated from the applet.

0

精彩评论

暂无评论...
验证码 换一张
取 消