• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

java.security AccessControlException : access denied?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello All
I'm trying to run the server class to create remote objects and registers them,I'm having that Exception.
Do i need to set up anything on my machine?
please any help?
Here is the full output:
============================
C:\>java -Djava.rmi..server.codebase=file:/..\..\-Djava.security.policy=RMI
Security.policy examples.network.StudentEnrollment
java.security.AccessControlException: access denied (java.net.SocketPermiss
ion 127.0.0.1:1099 connect,resolve)
at java.security.AccessControlContext.checkPermission(Unknown Sourc
e)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkConnect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(Unkn
own Source)
at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(Unkn
own Source)
at sun.rmi.transport.tcp.TCPEndpoint.newSocket(Unknown Source)
at sun.rmi.transport.tcp.TCPChannel.createConnection(Unknown Source
)
at sun.rmi.transport.tcp.TCPChannel.newConnection(Unknown Source)
at sun.rmi.server.UnicastRef.newCall(Unknown Source)
===========================
Here are all files that i have:
====================================
package examples.network;
import java.rmi.Remote;
import java.rmi.RemoteException;
public interface Student extends Remote
{
public int getID() throws RemoteException;
public void setName(String name) throws RemoteException;
public String getName() throws RemoteException;
public int getCredits() throws RemoteException;
public int addCredits(int credits) throws RemoteException;

}
=============================================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentClient
{
private static final String HOST_NAME="localhost";
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}

try
{
Student s1001=(Student) Naming.lookup("//"+HOST_NAME+"/Student1001");
Student s1002=(Student) Naming.lookup("//"+HOST_NAME+"/Student1002");
System.out.println(s1001.getName());
System.out.println(s1002.getName());
System.out.println(s1001.getCredits());
s1001.addCredits(3);
s1001.setName("Elaine Goldman");
System.out.println(s1001.getName());
System.out.println(s1001.getCredits());
}
catch(Exception x)
{
x.printStackTrace();
}
}
=============================================
package examples.network;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
public class StudentEnrollment
{
public static void main(String s[])
{
if(System.getSecurityManager()==null)
{
System.setSecurityManager(new RMISecurityManager());
}

try
{
StudentImpl[] students=
{
new StudentImpl(1001,"Matt1 Seif1"),
new StudentImpl(1002,"Matt2 Seif2"),
new StudentImpl(1003,"Matt3 Seif3")
};
for(int i=0;i<students.length;i++)
{
int id =students[i].getID();
Naming.rebind("student"+id,students[i]);
}
System.out.println("student objects bound .");
}
catch(Exception x)
{
x.printStackTrace();
}
}

}
===============================================
package examples.network;
import java.rmi.server.UnicastRemoteObject;
import java.rmi.RemoteException;
public class StudentImpl extends UnicastRemoteObject
implements Student
{
private int ID;
private String name;
private int credits=0;
public StudentImpl(int ID,String name)throws RemoteException
{
this.ID=ID;
this.name=name;
}
public int getID() throws RemoteException
{
return ID;
}
public void setName(String name) throws RemoteException
{
this.name=name;
}
public String getName() throws RemoteException
{
return name;
}
public int getCredits() throws RemoteException
{
return credits;
}
public int addCredits(int credits) throws RemoteException
{
return (this.credits +=credits);
}

}
===========================================
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
-Djava.security.policy=RMISecurity.policy
Your problem is in this policy file. You probably need to edit it to setup the correct permissions to associate with your application. Since RMI is loading code remotely you need to protect the client for a malicious server sending you bad code (security hole central). This looks like an example program maybe your tutorial has more info on how to properly edit this file so this example will run. You can try since this is just a simple example program:
grant {
java.security.AllPermissions;
}
This is NOT secure for production though.
charlie
 
reply
    Bookmark Topic Watch Topic
  • New Topic