aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes RMI Policy File and Access Denied Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "RMI Policy File and Access Denied Exception" Watch "RMI Policy File and Access Denied Exception" New topic
Author

RMI Policy File and Access Denied Exception

Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

OK, I am getting an Access Denied Exception when trying to create my RMI binded object. OK, here's the thing. I have the object making an instance of the database in this object. So if I have the Data(db.db) in the code after the setting of the RMISecurityManager, I get an Access Denied exception. If I put it before setting the RMISecurityManager, I get the same error, but this time when I run the Naming.rebind() method.
I have created a policy file, which grants allPermission:
permission java.security.AllPermission "", "";
I have already spent almost 8 hours, just to get this one little part to work. There does not seem to be a good resource online that I have found to really explains what must be done for RMI to work. Do you have to have a policy file? Do you have to have a codebase if your stub and skeleton classes are in the same directory as the implementation class?
And do you have to start it up useing the -D option with policy file and codebase to run?
Help?
thanks
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17259
    
    6

Now please don't tell me I am wrong in doing this, but I removed the RMISecurityManager from the Server.
So now it works, but I have designed a test client, and when I do a Naming.lookup(url);
and try to compile the test class, it is asking me to cast the lookup to a ConnectionFactory_Stub, and not a ConnectionFactory.
my code is:
mport java.util.*;
import java.io.*;
import java.rmi.*;
import suncertify.db.*;
public class testRMI{
public testRMI(){
}
public static void main(String[] args){
String url = "//localhost/connectionFactory";
try{
ConnectionFactory c =(ConnectionFactory)Naming.lookup(url);
System.out.println ("Yeah");
DataAccessRemote data = c.getConnection();
System.out.println ("Yeah");
} catch(Exception e){
System.out.println ("Boo");
System.out.println(e);
}
}
}

any ideas?
Mark
Rit Faisal
Greenhorn

Joined: May 16, 2001
Posts: 7
Just create a policy file which looks like this
/* AUTOMATICALLY GENERATED ON Tue Sep 04 16:51:47 CDT 2001*/
/* DO NOT EDIT */
grant {
permission java.net.SocketPermission "*:1024-65535", "connect,accept";
permission java.net.SocketPermission "*:80", "connect,accept, resolve";
permission java.io.FilePermission "<<ALL FILES>>", "read, execute, write";
};

IT WORKS FOR ME
Regards,
Rit Faisal
Malin Bystrom
Greenhorn

Joined: Jan 28, 2002
Posts: 1
Hi, I have read all I can find about RMISecurityManager in this forum. However I haven't found the help I need, so if anyone could help me....
I try to instansiate an RMISecurityManager with
System.setSecuritymanager(new RMISecurityManager());
Properties props = new Properties();
props.put(policyFile, "policy");
The policyFile look like this:
grant {
permission java.net.SocketPermission "*:1024-65535", "connect,accept,resolve";
permission java.net.SocketPermission "*:80", "connect,accept, resolve";
permission java.io.FilePermission "<>", "read, execute, write";
};
But, I only get
"java.security.AccessControlException: access denied (java.io.FilePermission db.db read)"
am I doing something really stupid, since I can't get it to work ?
All help truly appreciated
Malin
Todd Harney
Greenhorn

Joined: Jan 25, 2002
Posts: 23
Mark,
Doesn't the url for Naming.lookup need the rmi:// in front of it to define the protocol? I am new to RMI so I don't know for sure, but everything I have seen has the url in the form rmi://localhost/connectionFactory
Just a thought.
Todd
 
wood burning stoves
 
subject: RMI Policy File and Access Denied Exception