Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#FFcccc
public class Password { 
  public static void changePassword(final String password_file) throws FileNotFoundException {
    FileInputStream fin;
    fin = openPasswordFile(password_file);
  }
	
  public static FileInputStream openPasswordFile(String password_file) throws FileNotFoundException {
    // Declare as final and assign before the body of the anonymous inner class
    // Array f[] is used to maintain language semantics while using final 
    final FileInputStream f[]={null};
    // Use own privilege to open the sensitive password file
    AccessController.doPrivileged(new PrivilegedAction() {
      public Object run() {   
        try {
          f[0] = new FileInputStream("c:\\" + passowrdpassword_file);	//Perform privileged action
        }catch(FileNotFoundException cnf) { System.err.println(cnf.getMessage()); }
        return null;    //Still mandatory to return from run()
      }
    });
   return f[0];  //Returns a reference to privileged objects (inappropriate)
 }	
}

...