Applet: best way to protect public methods?
I am having an applet extends Applet that does Java <=> JavaScript
either way communication on the page. The problem I'm having is with
init(), start(), run(), stop(), destroy() redefined applet methods.
They are public and I can do nothing easy about it: "attempting to
assign weaker access privileges; was public".
The problem is that in the way JavaScript => Java LiveConnect
interface was made, as long as interop is enabled, all public applet
methods can be called from JavaScript, say
window.alert( document.applets['MyApplet'].getAppletInfo() );
Unfortunately it also means that the infamous "malicious user" - or
simply a careless one - can easily bring the system into very sorry
state by calling say
document.applets['MyApplet'].init();
or
document.applets['MyApplet'].start();
etc. over and over again from within JavaScript. So far I am using
"single-use locker" wrapper like:
boolean isFirstInit = true;
public void init() {
if (isFirstInit) {
// DO init stuff
isFirstInit = false;
}
}
so the same for isFirstStart. I don't think it may work for run() as
if understand properly its whole purpose is to be called over and
over. The problem is to make sure that it's an auto call on
myThread.start() and not some bored mind call from JavaScript.
Any suggestions and corrections are most welcome.