This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
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

Win a copy of Building Microservices this week in the Design forum!
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

RMI Policy File and Access Denied Exception

Mark Spritzler

Joined: Feb 05, 2001
Posts: 17271

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 "", "";
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?

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

Joined: Feb 05, 2001
Posts: 17271

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.rmi.*;
import suncertify.db.*;
public class testRMI{
public testRMI(){
public static void main(String[] args){
String url = "//localhost/connectionFactory";
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");

any ideas?
Rit Faisal

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*/
grant {
permission "*:1024-65535", "connect,accept";
permission "*:80", "connect,accept, resolve";
permission "<<ALL FILES>>", "read, execute, write";

Rit Faisal
Malin Bystrom

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 "*:1024-65535", "connect,accept,resolve";
permission "*:80", "connect,accept, resolve";
permission "<>", "read, execute, write";
But, I only get
" access denied ( db.db read)"
am I doing something really stupid, since I can't get it to work ?
All help truly appreciated
Todd Harney

Joined: Jan 25, 2002
Posts: 23
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.
I agree. Here's the link:
subject: RMI Policy File and Access Denied Exception
It's not a secret anymore!