problem with access denied
This is my first Java project so I can be doing something stupid.
I want to have the client give the server an sql command and then the server execute the command and return a ResultSet to the client.
It registers on the rmi, the server starts and listens and the client starts. Then the client sends its request and the server picks it up. All this is just fine. However when the server calls Class.forName it gives:
Exception: access denied (java.lang.RuntimePermission accessClassInPackage.sun.jdbc.odbc)
Probably something is wrong with my security policy, so here it is:
grant codeBase"file:${java.home}/lib/ext/*"{
permission java.security.AllPermission;
};
grant{
permission java.net.SocketPermission"*:1024-65535","connect,accept";
permission java.net.SocketPermission"*:80","connect";
};
I just added the grant codeBase, but it didn't help. The SocketPermission was already in place.
My code is still fairly simple (the server)
package engine;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import contract.Query;
publicclass StudiesEngineextends UnicastRemoteObjectimplements Query{
privatestaticfinallong serialVersionUID = 1;
public StudiesEngine()throws RemoteException{
}
public ResultSet executeQuery(String sql)throws RemoteException{
ResultSet rSet =null;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection dbConn = DriverManager.getConnection("jdbc:odbc:bk2dicom");
Statement stm = dbConn.createStatement();
rSet = stm.executeQuery(sql);
stm.close();
dbConn.close();
}
catch(Exception e){
System.out.println("Exception: " + e.getMessage());
}
return rSet;
}
/**
* @param args
*/
publicstaticvoid main(String[] args){
// Create and install a security manager
if( System.getSecurityManager() ==null){
System.setSecurityManager(new RMISecurityManager());
}
try{
StudiesEngine obj =new StudiesEngine();
// Bind this object instace to the name "StudiesServer"
Naming.rebind("//home-ilan/StudiesServer", obj);
System.out.println("StudiesEngine bound in registry");
}
catch(Exception e){
System.out.println("StudiesEngine err: " + e.getMessage());
e.printStackTrace();
}
}
}
The client code is
package client;
import java.rmi.Naming;
import java.rmi.RMISecurityManager;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import contract.Query;
publicclass StudiesClient{
public StudiesClient(){
initialize();
QueryServer();
}
privatevoid initialize(){
if(System.getSecurityManager() ==null){
System.setSecurityManager(new RMISecurityManager());
}
}
/**
* @param args
*/
publicstaticvoid main(String[] args){
new StudiesClient();
}
privatevoid QueryServer(){
try{
int i;
ResultSetMetaData meta;
ResultSet rSet;
String name ="//home-ilan/StudiesServer";
Query q1 = (Query) Naming.lookup(name);
rSet = q1.executeQuery("select name, id from patients where name like a%");
meta = rSet.getMetaData();
int columns = meta.getColumnCount();
for( i=1; i<=columns; i++){
System.out.println(meta.getColumnName(i) +", " + meta.getColumnTypeName(i));
}
}
catch(Exception e){
System.out.println("QueryServer err: " + e.getMessage());
}
}
}
And the interface
package contract;
import java.rmi.Remote;
import java.rmi.RemoteException;
import java.sql.ResultSet;
publicinterface Queryextends Remote{
ResultSet executeQuery(String sql)throws RemoteException;
}
Could someone suggest where I went wrong?
Thanks,
Ilan

