Solved

Security Exception: checkwrite:FILENAME

Posted on 1998-08-26
3
165 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Android studio getdrawable(int) is deprecated 4 43
Java - Why doesn't this JFrame work 3 44
stackato and cloud 4 74
custom annotations 9 32
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

895 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

12 Experts available now in Live!

Get 1:1 Help Now