javalola
Jul 17, 2012, 10:34 AM
Hi, I am a beginner in java. I am trying to create a rmi client- database server application in java, but I am struggling. The client and the database server are to work well even if placed in different computers, that is in separate packages.
My server seems to be working fine, but when I run my client I keep on getting the error: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve").
I read on security policies recently and I don't really know how to work with it in netbeans. I read that I am to create a security policy file and place it in the server package and client package too. I did so, I created a txt file with my policy and placed a copy of it in my netbeans projects, inside the server and client src file and in the package respectively. My policy looks as follows:
grant {
permission java.security.AllPermission;
};
My server looks as follows:
package wildanimalsserver;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author CTI
*/
public class WildAnimalsServer {
public WildAnimalsServer() {
}
public static void main(String [] args) {
try {
RMISecurityManager security = new RMISecurityManager();
System.setSecurityManager(new RMISecurityManager());
//Creating and getting the reference to the RMI registry
Registry registry = LocateRegistry.createRegistry(1099);
//Instantiating the object
AnimalObject ao = new AnimalObject();
//Registering the object
registry.rebind("Animal", ao);
System.out.println("Server ready...");
} catch (Exception e) {
System.out.println(e);
}
}
}
.. and my client:
package wildanimalsclient;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author CTI
*/
public class WildAnimalsClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
RMISecurityManager security = new RMISecurityManager();
System.setSecurityManager(new RMISecurityManager());
// Get reference to rmi registry server
Registry registry = LocateRegistry.getRegistry(1099);
// Looking up for the server object
IRemoteAnimal ra = (IRemoteAnimal)registry.lookup("Animal");
System.out.println("Client ready and responding...");
} catch (Exception e) {
System.out.println(e);
}
}
}
My Server consists of:
Animal.java(entity class mapping to database)
IRemoteanimal.java(RMI application interface)
AnimalObject.java(Animal object to be distributed)
WildAnimalsServer.java(server application)
WildAnimalsDBmanager.java(manage connection to database)
AnimalRepository.java(provides crud operations)
And my client:
Animal.java(same as server)
IRemoteanimal.java(same as server)
WildAnimalsClient.java(client application calling RMI server)
My server seems to be working fine, but when I run my client I keep on getting the error: java.security.AccessControlException: access denied ("java.net.SocketPermission" "127.0.0.1:1099" "connect,resolve").
I read on security policies recently and I don't really know how to work with it in netbeans. I read that I am to create a security policy file and place it in the server package and client package too. I did so, I created a txt file with my policy and placed a copy of it in my netbeans projects, inside the server and client src file and in the package respectively. My policy looks as follows:
grant {
permission java.security.AllPermission;
};
My server looks as follows:
package wildanimalsserver;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author CTI
*/
public class WildAnimalsServer {
public WildAnimalsServer() {
}
public static void main(String [] args) {
try {
RMISecurityManager security = new RMISecurityManager();
System.setSecurityManager(new RMISecurityManager());
//Creating and getting the reference to the RMI registry
Registry registry = LocateRegistry.createRegistry(1099);
//Instantiating the object
AnimalObject ao = new AnimalObject();
//Registering the object
registry.rebind("Animal", ao);
System.out.println("Server ready...");
} catch (Exception e) {
System.out.println(e);
}
}
}
.. and my client:
package wildanimalsclient;
import java.rmi.RMISecurityManager;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
/**
*
* @author CTI
*/
public class WildAnimalsClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try {
RMISecurityManager security = new RMISecurityManager();
System.setSecurityManager(new RMISecurityManager());
// Get reference to rmi registry server
Registry registry = LocateRegistry.getRegistry(1099);
// Looking up for the server object
IRemoteAnimal ra = (IRemoteAnimal)registry.lookup("Animal");
System.out.println("Client ready and responding...");
} catch (Exception e) {
System.out.println(e);
}
}
}
My Server consists of:
Animal.java(entity class mapping to database)
IRemoteanimal.java(RMI application interface)
AnimalObject.java(Animal object to be distributed)
WildAnimalsServer.java(server application)
WildAnimalsDBmanager.java(manage connection to database)
AnimalRepository.java(provides crud operations)
And my client:
Animal.java(same as server)
IRemoteanimal.java(same as server)
WildAnimalsClient.java(client application calling RMI server)