13
  • I am running RServe from Server machine using cmd

    Rserve.exe --RS-conf Rserv.conf --RS-port 12306
    
  • Rserv.conf file has following content:

    pwdfile RserveAuth.txt
    auth required
    remote enable
    plaintext disable

  • RserveAuth.txt has following contents:

    Admin 123456

  • I am connecting to R Server from JAVA

    import org.rosuda.REngine.REXPMismatchException;
    import org.rosuda.REngine.REngineException;
    import org.rosuda.REngine.Rserve.RConnection;
    import org.rosuda.REngine.Rserve.RserveException;
    import org.rosuda.REngine.REXP;
    import org.rosuda.REngine.*;
    public class ConnecttoR
    {
      ...
      ...
     public void connectR()
     {
         try 
        { 
            RConnection connection = new RConnection("172.16.33.242",12306); // Works if authentication is not required in Rserv.conf 
        }
        catch (RserveException e) {
        e.printStackTrace();
        } 
        catch(REXPMismatchException e){
        e.printStackTrace();
        }
        catch(REngineException e){
        e.printStackTrace();            
    } 
     }
    }
    
  • Connection to Rserve is open to all without username & Password. How shall I add security and allow connection only with valid credentials to access Rserve

Akki
  • 1,221
  • 3
  • 14
  • 33
  • it looks like your RServer is on Windows `Rserve.exe`, what is the client user running [Windows, MacOSX, Linux]? Is your production RServer on Windows? Just checking requirements. – Technophobe01 Nov 18 '17 at 17:45
  • @Technophobe01 RServer is on windows machine and my client can be any Windows/Linux/MacOSX connecting to it. The connection request to Rserver is made from JAVA class and later i run script on Rserve using connection object and pass the output of script to JSP page. – Akki Nov 19 '17 at 04:36
  • FYI. The version of RServe under Windows is limited. The most important limitation is "no parallel connections are supported, subsequent connections share the same namespace" / "sessions are not supported - this is a consequence of the fact that parallel connections are not supported". See https://www.rforge.net/Rserve/rserve-win.html under "Please read before downloading/using the Windows version of Rserve!" – Andrey Belykh Nov 20 '17 at 18:24
  • @AndreyBelykh Good point - you beat me to it. My sense is that one option is to run Rserve via Windows Ubuntu subsystem and then restrict access via ssh. – Technophobe01 Nov 21 '17 at 06:51

1 Answers1

4

As you have enabled the authentification after creating the connection as a first command you need to execute the login command. The Java library has a special wrapper for it.

See code below for example use case.

RConnection connection = new RConnection("127.0.0.1",12306);
connection.login("Admin", "123456");
REXP x = connection.eval("R.version.string");
System.out.println(x.asString());

Also, I would recommend using full path as the pwdfile value.

Babl
  • 7,446
  • 26
  • 37
  • Does it use ssh internally to connect? Is it a solution that would work for both Windows and linux box? – Madhavi Jouhari Feb 16 '18 at 11:46
  • Yes it will work for any system (I have tested it with MacOS X), and no it uses native socket connections. – Babl Feb 16 '18 at 12:15
  • bcz i followed your solution and got a org.rosuda.REngine.Rserve.RserveException: login failed, request status: authorization failed at org.rosuda.REngine.Rserve.RConnection.login(RConnection.java:399) error – Madhavi Jouhari Feb 16 '18 at 12:43
  • Are you sure that the credentials are correct? as You can see the systems are connected, only the username and password did not match. – Babl Feb 16 '18 at 12:44
  • the credentials are correct and also the same as present in the pwdfile in the rserv.conf file. Thanks for verifying though :) – Madhavi Jouhari Feb 16 '18 at 13:10