简体   繁体   中英

java.security.AccessControlException: access denied in Java RMI Telephone Directory

I got this source over the internet for my academic assignment purpose. Its just a practical of Java RMI. Here i am posting the code of my server file.

   import java.io.*;
   import java.util.*;
   import java.rmi.*;
   import java.rmi.server.*;

   public class LookupServer extends UnicastRemoteObject implements Lookup {
      private Vector save = new Vector();

      public LookupServer(String db) throws RemoteException
      {
         try {
            FileReader fr = new FileReader(db);
            BufferedReader br = new BufferedReader(fr);
            String s = null;
            while ((s = br.readLine()) != null)
               save.addElement(s);
            fr.close();        
         }
         catch (Throwable e) {
            System.err.println("Exception in Lookupserver():"+e);
            System.exit(1);
         }
      }

      public String findInfo(String info)
      {
         if (info == null)
         return null;

         info = info.toLowerCase();
         int n = save.size();
         for (int i = 0; i < n; i++) {
            String dbs = (String)save.elementAt(i);
            if (dbs.toLowerCase().indexOf(info) != -1)
            return dbs;
         }

         return null;
      }

      public static void main(String args[])
      {
         try {
             RMISecurityManager security = new RMISecurityManager();

             System.setSecurityManager(security);

             String db = args[0];

             LookupServer server = new LookupServer(db);

             Naming.rebind("LookupServer", server);
             System.err.println("LookupServer ready...");
         }
         catch (Throwable e) {
            System.err.println("Exception in main: " + e);
            System.exit(1);
         }
      }
}

My Policy file (policy.policy) includes

grant
{
// Allow everything for now
permission java.security.AllPermission;
};

Now i am stuck at :

C:/>java LookupServer Database.txt java.security.policy=policy.policy

Exception in main: java.security.AccessControlException: access denied (java.net.SocketPermission 127.0.0.1:1099 connect,resolve)

Please Help me...!

应使用-D而不是参数将策略文件作为属性传递

C:/>java -Djava.security.policy=policy.policy LookupServer Database.txt 

Thanks Dear

Actually i have gone through several ppts and pdfs of RMI and I get to knew about running and compiling the programs. Almost all documents was suggesting me to pass -D as a properties not as parameter. but when i did, it was giving me an error message of access exception. Then i have placed my policy file in my C drive and used the command

C:/>java -Djava.security.policy=C:/policy.policy LookupServer Database.txt

And It worked... :) My RMI applications is running successfully. Thanks for your response.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM