0

I have developed a code in java using RMI on ubuntu server. It works well when RMI client and server are located on the same machine. When I use two machines (one as server and another as client - both ubuntu) it gives me "RMI Connection refused exception". In an attempt to solve this issue, I tried to override java policy files using code below:

System.setSecurityManager(new RMISecurityManager());
System.setProperty("java.security.policy","file:///home/{local path}/client.policy");

I used similar code at server side too.

The contents of client and server policy files are as follows:

grant codebase  {
    permission java.security.AllPermission;
};

Now I am getting following exception at client side on "System.setProperty(....)" line shown above.

java.security.AccessControlException: access denied (java.util.PropertyPermission java.security.policy write)
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:374)
    at java.security.AccessController.checkPermission(AccessController.java:546)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
    at java.lang.System.setProperty(System.java:725)
    at ParaselectionServlet.doPost(ParaselectionServlet.java:106)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:185)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:151)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:269)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

I am not expert in java or ubuntu, but can anyone help me in fixing the above issue?

-Rashmi

user207421
  • 305,947
  • 44
  • 307
  • 483
  • What EJB package are you using and on what server? I know that some of the newer EJB updates added security on making remote EJB connections because we migrated from EJB2 to EJB3 and I remember the JBoss AS7 doc mentioning this. I believe for JBoss this happened in EJB3.1, which required a bit more configuration so that a client could make a remote connection. – mikemil Feb 24 '14 at 02:08
  • Note, there is no need to use `RMISecurityManager`. It's deprecated in Java 8. Just use `SecurityManager`. – Stuart Marks Feb 24 '14 at 04:45
  • It's been deprecated since Java 1.2 actually, in 1998. – user207421 Feb 24 '14 at 11:45

1 Answers1

1

You need to set the security policy before the security manager.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Certainly system properties are unlikely to be reread every time their value is used. So really, you want to set them somewhere on the command line, or avoid their use because they're such a hack. – Tom Hawtin - tackline Feb 24 '14 at 11:44