Description
Name: tb29552 Date: 06/18/97
1.just javac MyApp.java
2.code for MyApp.java:
-------------------
import java.io.*;
import java.lang.*;
class MyApp {
public static PasswordSecurityManager PSM = new PasswordSecurityManager("abraca");
private static Secret a_secret;
public static String nom_fichier = "secret.txt";
public static void main(String[] args) {
// Firstly, set the security manager
try {
System.setSecurityManager(PSM) ;
} catch ( SecurityException se1) {
System.out.println("SecurityManager already set!");
};
// create the object to protect ( class Secret)
creerSecret();
//crypt it
//serialize it
//or implement checkSerialize in PMS
saveSecretOnDisk();
}
private static void saveSecretOnDisk(){
try {
FileOutputStream f = new FileOutputStream(nom_fichier);
ObjectOutput s = new ObjectOutputStream(f);
// verifie les droits de serialiser
//PSM.checkWriteObject(a_secret);
//System.out.println("droits verifies");
// serialise le secret
// s.writeObject("le secret est:");
//System.out.println("serialize le header:ok");
s.writeObject(a_secret);
// System.out.println("serialize le secret:ok");
s.flush();
s.close();
f.close();
} catch (java.io.IOException ie) {
System.out.println("Pb pour ouvrir un stream sur fichier");
} catch ( SecurityException se) {
System.out.println("SecurityManager said:not allowed to write secrets on the disk!");
}
}
private static void loadSecretFromDisk(){
try {
FileInputStream in = new FileInputStream(nom_fichier);
ObjectInputStream s = new ObjectInputStream(in);
String header = (String)s.readObject();
Secret the_secret = (Secret)s.readObject();
} catch (Exception ea){};
}
private static void creerSecret(){
DataInputStream dis = new DataInputStream(System.in);
System.out.println("Donner le secret:");
try{
a_secret = new Secret( dis.readLine());
} catch (java.io.IOException ioe) {};
}
}
-------------------------
end of code of MyApp.java
begining of code of PasswordSecurityManager.java
-------------------------
import java.io.*;
class PasswordSecurityManager extends SecurityManager {
private String password;
PasswordSecurityManager(String password) {
super();
this.password = password;
}
private boolean accessOK() {
int c;
DataInputStream dis = new DataInputStream(System.in);
String response;
System.out.println("What's the secret password?");
try {
response = dis.readLine();
if (response.equals(password))
return true;
else
return false;
} catch (IOException e) {
return false;
}
}
// my methods i added
public void checkWriteObject(Secret a_secret) {
if (!accessOK())
throw new SecurityException("no right to write a secret");
}
public void checkReadObject(Secret a_secret) {
if (!accessOK())
throw new SecurityException("No right to read a secret");
}
// end of methods i added
public void checkRead(FileDescriptor filedescriptor) {
if (!accessOK())
throw new SecurityException("Not a Chance!");
}
public void checkRead(String filename) {
if (!accessOK())
throw new SecurityException("No Way!");
}
public void checkRead(String filename, Object executionContext) {
if (!accessOK())
throw new SecurityException("Forget It!");
}
public void checkWrite(FileDescriptor filedescriptor) {
if (!accessOK())
throw new SecurityException("Not!");
}
public void checkWrite(String filename) {
if (!accessOK())
throw new SecurityException("Not Even!");
}
}
----------------------
end of code of PasswordSecurityManager.java
begining of code of Secret.java
---------------------
class Secret extends Object implements java.io.Serializable {
private static String this_is_the_secret;
// should have put transient to protect it from serialization
Secret(String a_new_secret){
super();
this.this_is_the_secret = a_new_secret;
}
// public static void writeObject(){
//this_is_the_secret.writeObject();
//}
}
---------------------------
end of Secret.java
end of all code source
3. exact message:
# javac MyApp.java
java.lang.NoClassDefFoundError: sun/tools/asm/Instruction
at sun.tools.asm.Assembler.<init>(Assembler.java)
at sun.tools.javac.SourceClass.compileClass(SourceClass.java)
at sun.tools.javac.SourceClass.compile(SourceClass.java)
at sun.tools.javac.Main.compile(Main.java)
at sun.tools.javac.Main.main(Main.java)
error: An error has occurred in the compiler; please file a bug report (http://java.sun.com/cgi-bin/bugreport.cgi).
Note: MyApp.java uses a deprecated API. Recompile with "-deprecation" for details.
1 error, 1 warning
company - university of bologna , email - ###@###.###
======================================================================
Attachments
Issue Links
- duplicates
-
JDK-4058658 "out of memory" error during class load misrepresented as NoClassDefFoundError
- Closed
- relates to
-
JDK-4054523 no access to an inner class declared in a method of another innner class
- Closed