Solved

Security Exception: checkwrite:FILENAME

Posted on 1998-08-26
3
164 Views
Last Modified: 2013-12-29
I have my main code called "oracle_supply.java", it calls
Create_Html.java (class) like this:

if ("Create HTML".equals(s)){
         new Create_Htmls();
}

In Create_Htmls, all i'm tring to do is open a file on the
server and write text to it like this:

public class Create_Htmls{
   static String buf1=null;
   static PrintWriter output = null;
   static String in = "test.dat";

   public Create_Htmls() {
      System.out.println ("Now in Create_Htmls code");
      try {
        output = new PrintWriter(new FileWriter(in));
      } catch (Exception e) {
      System.out.println("Couldn't create output file");
      System.exit(1);
      }

      output.println("This is test.dat");

What happens is nothing, in the java console window
I get this:

Now in Create_Htmls code
# Security Exception: checkwrite:test.dat

Now if on the server, I say "java Create_Htmls" it
creates the test.dat file fine, but NOT when I call
it from "oracle_supply".

I have other code that I have written that does similiar
things, and it works fine. But I missing something
in this project. Any suggestions?
Basically, i'm running an applet, and from that applet,
i'm calling another piece of code that will create a
file on the server.  Hum... on further review, I have just
remembered that in my other code writing files on the
server, I used a socket. Is that what I need to do here?
I will try that (I know it works) while I wait for an answer.
So new question is can I create a file on my server from
an applet with out using sockets?

Thanx!
Don
0
Comment
Question by:afsac
  • 2
3 Comments
 

Author Comment

by:afsac
ID: 1222597
Edited text of question
0
 
LVL 8

Accepted Solution

by:
diakov earned 250 total points
ID: 1222598
Hi,

Let's first clear some basics that I sence may be are not very clear to you.
- First the applet is a piece of code, transported through the net via the HTTP protocol to the client machine and run there.

- The applet runs in the browser's JVM and is very restricted on usage of the local client machine resources.

- The only place it could contact without a security exception is the web server it originates from.

- Apparently, when you run your 'file creating code' from the applet, it loads in the local machine and tries to create a file on it. Which in case of applet come from a server, will lead to the described security exception.

- What you need to do is to write an apllication that runs on the server and anticipates calls from the applets on the client machines connected to the web server there.

- There are several ways to do this:
  - Using sockets. There again are several ways:
   . simple socket communication. the server program listens to a port on the server machine, and the client program (the applet) opens a socket to this port. There quite many examples on the net, I can send you a chat application if you want.
   . some middleware, like JavaRMI, that hides the socket communication from you and provides classes for doing this quite transparently. For example, on the applet, you can create an Java object, which actually is on the server, but your code uses it like it is in the applet itself.

Problem with sockets is that if you have a firewall, it disallows the direct socket communication except on some legal ports like the ftp - 21, web server - 80, telnet - 23, etc. And it is a big problem, because a lot of companies use corporate firewalls.

 - using HTTP/CGI tunneling. You can write a server application which is an extension of the web server. Some web servers allow scripting, like MSIIE, Oracle web server, etc. Some of them have extensions for Java, and you can write so called servlets.


I suggest the HTTP/CGI, which differs in form according to the scripting language or CGI programs that are used on the web server.

So the scenario is:

Your applet loads, and opens the URL where the server script processes the request for creating a file. After receiving the data for the file, the server object creates a file locally on the server, and returns result.

If you have more comments, please send them.

Cheers,
  Nikolay


0
 

Author Comment

by:afsac
ID: 1222599
Nikolay,
     I have it working now by using a socket.  At this time, we don't
have a firewall, but probably will in the future.  The Java code is loaded
from my server, and the file to be created is on the same server. So
the Socket thing is working for me for now.

     Thank you for your quick response.

Don
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now