“access denied” when using JDBC from a browser applet

后端 未结 2 1013
一整个雨季
一整个雨季 2021-01-27 18:12

I have a java applet that queries an Oracle database for data. When run from inside an IDE, it functions just fine. But when I run it as an applet embedded in a webpage, I get a

相关标签:
2条回答
  • 2021-01-27 18:35

    Applets runs in an environment with very restrictive security rules. You need at least to sign your applet.

    But, the problem is bigger here, doing JDBC inside an applet is a very bad idea. The applet's source code is publicitly available and is thus sensitive for easy hacks. You should really create a webservice for that instead and then let your applet access that webservice instead. With a webservice, your applet will be able to exchange information with the DB by just HTTP requests/responses. With a webservice you hide the DB access details, JDBC and SQL code from the public.

    How exactly to create a webservice depends on the server environment and the programming language used. In Java EE for example, you could already use a simple Servlet for this, but also JAX-RS and JAX-WS is supported for restful (XML/JSON) and XML webservices respectively. An applet is without any security restrictions allowed to connect with its host whose address is available by getCodeBase() E.g.

    InputStream response = new URL(getCodeBase(), "servlet?foo=bar").openStream();
    // ...
    
    0 讨论(0)
  • 2021-01-27 18:36

    Note that if you follow the advice of BalusC and hide the DB behind a an active page (e.g. a servlet, PHP, ASP etc.) that is on the same server as the applet, the applet could most probably remain sand-boxed. It would be the active page that is trying to access class-loaders (as well as the DB).

    0 讨论(0)
提交回复
热议问题