Article View: borland.public.jbuilder.java.api
Article #1671Security enforcing.
From: Nawa
Date: Sun, 28 Oct 2001 20:44
Date: Sun, 28 Oct 2001 20:44
95 lines
3523 bytes
3523 bytes
Dear,
I've tried to use the security of Java. Before that, I'd never done
something about security. I read in the Java document and found that every
class will have difference security policy up to its ProtectionDomain. I
have writen a program to test that. The program is mention below. The
program basicly read a text file name "C:\Test.txt". The program also show
its Proteciondomain.
From the result, we can see that the class have no permission to read or
write the file, but the program can actually do it. What happens? Why is not
the permission enforced to the class? And How can we enforce it?
What I actually want to do is create the new class loader that I can
control my own loaded class. Can I use this architecture?
Thanks for your time,
Nawa
### Note: In order to test the program, don't forget the create the emty
text file name "Test.txt" in "C:\" ("c:\Test.txt").
//**************** Permit1.java ***************
/**
* This class is created for testing Permission class.
*/
import java.io.*;
import java.util.*;
import java.security.*;
public class Permit1{
private FileReader File1 = null;
private FileWriter File2 = null;
private String filename1 = null;
public Permit1(String filename){
boolean Successful = true;
filename1 = filename;
System.out.println("Start testing.");
ProtectionDomain pDomain = this.getClass().getProtectionDomain();
System.out.println(pDomain.toString());
System.out.println("");
System.out.println(pDomain.getCodeSource());
System.out.println(pDomain.getPermissions().toString());
System.out.println(pDomain.getPermissions().elements().toString());
//Provider[] Ps = Security.getProviders();
//System.out.println(Ps.length);
try{
System.out.print("Change from: ");
Show();
Change();
System.out.print("Change to : ");
Show();
}
catch(Exception e){
System.out.println("Fail to do so.");
Successful = false;
}
if(Successful) System.out.println("Congraturation!! It's successful.");
System.out.println("Finish testing.");
}
public void Show() throws IOException, SecurityException {
File1 = new FileReader(new File(filename1));
int c;
c = File1.read();
while(c != -1) {
System.out.print((char)c);
c = File1.read();
}
File1.close();
}
public void Change() throws IOException, SecurityException {
File2 = new FileWriter(new File(filename1));
File2.write("Add a line at " + new Date() + "\n");
File2.close();
}
public static void main(String[] arg){
new Permit1("e:/Test.txt");
}
}
Technical Details
Message-ID:
<3bdc6e43$1_2@dnews>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!newsfeed.mesh.ad.jp!uunet!osa.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnewsShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,b5b20b97934630e3,start X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2001-10-28 12:53:58 PST Reply-To: "Nawa" <mutant@iname.com> From: "Nawa" <mutant@iname.com> Newsgroups: borland.public.jbuilder.java.api Subject: Security enforcing. Date: Sun, 28 Oct 2001 14:44:40 -0600 Lines: 97 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 142.3.104.18 Message-ID: <3bdc6e43$1_2@dnews> X-Trace: dnews 1004301891 142.3.104.18 (28 Oct 2001 12:44:51 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!newshub2.rdc1.sfba.home.com!news.home.com!newsfeed.mesh.ad.jp!uunet!osa.uu.net!newsfeeds.ihug.co.nz!ihug.co.nz!dnews