How to make use of .jsp LDAP code and other java files in ruby on rails? - ruby-on-rails

I am very exited to join this community. Here is my problem.
I am doing a project in ruby on rails which basically is to develop an interface to take applications from people then run some algorithm like Gale-Shapely for example in background after deadline and then output the results in a new page. I had the gale shapely algo coded in Java and C++ languages. The problem is we have to contact LDAP server in our institute in-order to verify the credentials of the person who is willing to fill the form. And there is a proper Java code written for that purpose which should only be used in order to contact LDAP server as per our insti rules. I ran the .jsp code by installing tomcat7 and it is working perfectly. But, now the problem I had written some code for filling form etc.. in ruby on rails. But, I am not able to use this .jsp file in the login form in rails. I searched a lot on net but I didnt found any.
Apart from this another problem is how to run my java Gale-Shapely code in background? One solution is again re-writing the entire code in ruby and use database info to run algo. Is there any method that I can give my database info to this java program and capture its output?

I solved this by using netldap gem present in rails. I realized that similar to the java code which uses an LDAP library, there is this netldap library in ruby. So, I used it to get the credentials and verify the identity of person and also to get other details from LDAP server.

Related

Using Orbeon Forms "List Forms Attachments" API

We have the requirement to fetch an attachment to an Orbeon form from a simple automation script. We found the "List Forms Attachments" API (https://doc.orbeon.com/form-runner/api/persistence/list-form-data-attachments.html) and are trying to call it using a simple "curl" script that runs on the same host as the Orbeon Tomcat instance:
curl -v "http://localhost:8080/orbeon/fr/service/$app/$form/attachments?document=$docid"
This returns an HTTP 403 (Forbidden), and even after reading whatever doc we can find on Orbeon security, we're still scratching our heads over how to configure Orbeon. Is there a simple configuration example showing an Orbeon configuration that would allow the API to be called from a local script like ours? We are running Orbeon CE 2017.1.
If getting this API to work is an ordeal, the other option we'd consider would be a database solution. We have Orbeon running on a MySQL persistence layer, and the same script we're using also has access to this database. Is there an easy way to take a submitted form's XML and fetch the attachment for a given form field?
We see in the submitted form's XML that the attachment tag looks like this:
<File1 filename="Original Filename.doc" mediatype="application/msword" size="14236">
file:/tmp/tomcat7-tomcat7-tmp/xforms_upload_7266596219758922423.tmp?filename=Original+Filename+doc&mediatype=application%2Fmsword&size=14236&mac=fc2febb1227e93643a048fbb02abc16bba346531
</File1>
When we scan the orbeon_form_data_attach database table, we see a row with the file content we expect, but the file_name column doesn't match the file information in the form's XML above...in this example, the file_name on the database is 1af8cd16367470362e13f77e679c0ae590e1f4a5.bin. Some of our forms have multiple attachments, and there doesn't seem to be a direct way to go from the form XML to the file_name in the database table.
Either of these solutions would be fine for us - we just need a way to get the attachments for a form from a simple script.
For reference, the relevant documentation is Authorization of Pages and Services.
You can, although this is not to be done for production but only testing and development, open all services without authentication. See this section. Otherwise, you need to setup an authorization service.

SSH Online Code Editor Terminal Security Issue

I am currently going through a tutorial with Ruby On Rails through a third party code editor.
It's currently walking me through through the process of getting my stuff onto a git repository and I have set up an SSH key from within the terminal of the online code editor itself. (not my computers code editor)
Using the command cat ~/.ssh/id_rsa.pub I accidentally printed it onto the console and am worried about security. It was the only way I could carry on with the tutorial. I did manage to push my application to the repo successfully. Is it wise to generate SSH Keys through other online code editors? Does it matter?
Any help and advice is greatly appreciated.
Thanks
Dan

Ruby on Rails: Executing JAR

Folks, i'm trying to execute a jar file inside RoR. Thanks to SO, I figured using IO::popen calls to execute a jar file.
Requirements:
- To login to site: To let our company employees login. Its a Java library which does some magic and figures if the username/password is valid. Which I did using,
result = IO::popen("java -cp auth.jar com.name.auth.LDAPLookup " + params[:username] + " " + params[:password]).read
p result
output: ["Authorized", "email", "id"]
No input sanitizing done. This is risky. Anyone could type something up in username/password and that will be executed in the server.
I'm not sure how to do this. One option I want to try is to use fork() or Process APIs to launch "java" and pass arguments. Couldn't figure out however. Any other thoughts?
Aside from the issue you mention, this sounds pretty painful in terms of performance (you're waiting around for the JVM to start up on every request, after all).
Two solutions jump out at me:
Look what the library does, and see if you really need to call out to Java for this; in particular, if it's just a question of making a lookup in an LDAP directory with a set of canned parameters, there are plenty of gems for that
If you must make use of Java classes from Ruby, strongly consider using JRuby, which will let you call the Java class in question directly, with neither the overhead of restarting the JVM on each call, nor the risk which comes with trying to correctly escape your arguments from Ruby to the shell to the JVM, and back.

Running grails test-app command from grails web console plugin

I have installed the grails web plugin. I can now browse to :
localhost:8080/myappname/console
And I can see the console displayed over there. I have bunch of test-cases written for application. I wish I can test my app from this web console.
Is it possible to do so? I'm very new to grails.
Thanks in advance.
Short answer no. The grails console is meant to write groovy code that interacts with your running application. Your running application does not include your test cases or the grails command line by default.
Long answer sort of. Provided you have all of your projects source code available somewhere in the file system where your application is running, you could call an external process to run test-app and return the result to the user. Here are some docs on running external processes in groovy: http://groovy.codehaus.org/Executing+External+Processes+From+Groovy. I suppose you could also package you application somehow to make this work, but I think doing that would be fairly complex.
I am not sure this is a good use case for the console plugin over all. Hope this helps

I want to use EtherPad (or a clone). My site is running Ruby on Rails. API or local install?

I'd like to utilize an etherpad interface on my website. Two questions:
1) is there any site with an etherpad api that I could just call remotely?
2) if not, how much trouble is it to install scala and have the two run concurrently?
Thanks
Check out http://piratepad.net and http://ietherpad.com
And you can embed those etherpad instances using a simple iframe as suggested here: http://etherpad.com/ep/blog/posts/embedding-etherpad
There doesn't seem to be a proper API yet for more robust interactions.
The original etherpad.com has now gone away but at that link there is a list of clones.
The instructions for embedding etherpads seems to have gone away with the rest of etherpad.com but I believe it's as simple as this:
<div id="ep">
<iframe src="http://etherpad.com/foo?fullScreen=1"></iframe>
</div>
Replace "etherpad.com" with whatever clone you're using, "foo" with the name of your pad, and you may or may not want to change that fullScreen=1 to fullScreen=0 (or leave it off altogether).
Installing scala might mean a few things:
Installing the SDK (i.e. scalac)
Installing the runtime
Assuming you mean the runtime, scala runs entirely on the Java Virtual Machine (JVM) so assuming you have 1.5+ JVM installed, you can run scala programs on it easily (Scala just compiles down to bytecode, after all). All a scala program requires is a few JARs on the classpath (scala-library and scala-compiler)
Now there is a better solution Etherpad Lite it is easily installable and embedable. See http://etherpad.org

Resources