Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RMI Policy File and Access Denied Exception

 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic