dcsimg
RMI security problem
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   motiff_none
Posted On:   Wednesday, November 22, 2006 10:22 PM

/*Client source file */ import java.rmi.*; import java.rmi.server.*; import java.rmi.registry.*; import java.lang.*; import java.io.*; import java.util.*; import org.apache.log4j.*; import org.apache.log4j.helpers.*; import java.util.concurrent.*; interface DontHaveThis extends Serializable { public String onlyOne(); } class ClassDontHave implements DontHaveThis { public String onlyOne() { return "HELLO!"; } } interface MineInterface extends Remote { public void doSomething(DontHaveThis e) throws RemoteException; } public class C   More>>

			
/*Client source file */
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import org.apache.log4j.*;
import org.apache.log4j.helpers.*;
import java.util.concurrent.*;

interface DontHaveThis extends Serializable
{
public String onlyOne();
}

class ClassDontHave implements DontHaveThis
{
public String onlyOne()
{
return "HELLO!";
}
}

interface MineInterface extends Remote
{
public void doSomething(DontHaveThis e) throws RemoteException;
}

public class Client
{
public static void main(String args[])
{
MineInterface o;
System.setErr(System.out);
ClassDontHave mm = new ClassDontHave();
try{
Registry r1 = LocateRegistry.getRegistry("localhost", 1099);
o = (MineInterface)r1.lookup("name");
o.doSomething(mm);

}catch(RemoteException e){
e.printStackTrace();
}catch(NotBoundException f){
System.out.println("NotBoundException!");
}
}
}

/*SERVER SOURCE FILE*/
import java.rmi.*;
import java.rmi.server.*;
import java.rmi.registry.*;
import java.lang.*;
import java.io.*;
import java.util.*;
import org.apache.log4j.*;
import org.apache.log4j.helpers.*;
import java.util.concurrent.*;
import java.io.Serializable;

interface DontHaveThis extends Serializable
{
public String onlyOne();
}

interface MineInterface extends Remote
{
public void doSomething(DontHaveThis e) throws RemoteException;
}

class MyClass implements MineInterface
{
public void doSomething(DontHaveThis e)
{
System.out.println(e.onlyOne());
}
}

public class Server
{

public static void main(String args[])
{
try{
MyClass o1 = new MyClass();
MineInterface o = (MineInterface)UnicastRemoteObject.exportObject(o1, 0);
Registry r = LocateRegistry.getRegistry("localhost", 1099);
r.bind("name", o);
}catch(RemoteException e){
e.printStackTrace();//System.out.println("RemoteException!");
}catch(AlreadyBoundException f){
System.out.println("AlreadyBoundException!");
}
}
}

I get the following exceptions:

java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is:
java.lang.ClassNotFoundException: ClassDontHave (no security manager: RMI class loader disabled)

at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)

at sun.rmi.transport.Transport$1.run(Unknown Source)

at java.security.AccessController.doPrivileged(Native Method)

.....


The client source file is in the Client folder, the server
source file is in the Server folder and I've tried in all
possible ways to compile and execute this such that it would
work. I just don't seem to manage it. Please someone tell
me what i should set -Djava.rmi.server.codebase to and what
should i write in client.policy file that i will pass with
-Djava.security.policy to the java command. I'm new to RMI
and I find it pretty hard to grasp. I would appreciate a
hand of help.


I'm currently running things like this:
the client:
java -Djava.rmi.server.codebase=file:../Server -Djava.security.policy=cl.policy Client
where cl.policy contains:
grant { permission java.security.AllPermission; };

the server:
java -Djava.rmi.server.codebase=file:../Client -Djava.security.policy=cl.policy Server
where sv.policy contains:
grant { permission java.security.AllPermission; };

what else is missing? what is wrong about the way i'm running things? is this also a classpath issue?
Do i have to use jars in order for it to work?

thank you :)
   <<Less

Re: RMI security problem

Posted By:   Genady_Beryozkin  
Posted On:   Friday, November 24, 2006 06:36 PM

The exception tells you exactly what's wrong - you must install a security manager.



Add the following to your main() method:




System.setSecurityManager(new RMISecurityManager());


Genady Beryozkin,

Author of the RMI Plugin for Eclipse

http://www.genady.net/rmi/

About | Sitemap | Contact