Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4292

Re: When Javascript call

From "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this>
Subject Re: When Javascript call
Message-ID <48ea1f2a$0$8740$7836cce5@newsrazor.net> (permalink)
Newsgroups comp.lang.java.gui
References <4bcc3b94-666a-4171-b115-4b625304a8d4@b38g2000prf.googlegroups.com>
Date 2011-04-27 15:49 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
crazytazo wrote:
> My test applet was signed and work well on applet viewer.
> In browser, when javascript call applet method f(), the applet throw
> java.security.AccessControlException
> But if call f() through Java code, it works well.
> f() method must called by javascript for arguments that created
> webpage.
> Give a solution please.

The problem is that the access level is that of the JS, not your signed 
Java applet. You need to use a AccessController and PrivilegedAction 
from the java.security package to elevate the permission level to your 
signed applet:


import javax.swing.JApplet;
import java.security.AccessController;
import java.security.PrivilegedAction;

public class MyApplet extends JApplet {
   public void javaScriptF() {
     AccessController.doPrivileged(new PrivilegedAction<Void>() {
        public Void run() {
          // Here is the call that was failing before.
          f();
          return null;
        }
     });
   }
}

BTW, when you find the problem passing JSObject from JavaScript to Java, 
search for an earlier post I made about the subject, I found a work-around.
-- 
Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Find similar


Thread

When Javascript call appl "crazytazo" <crazytazo@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000
  Re: When Javascript call "Daniel Pitts" <daniel.pitts@THRWHITE.remove-dii-this> - 2011-04-27 15:49 +0000

csiph-web