Monday, April 16, 2012

How user can (safely) programme their own filter in Java

I want my users to be able to write there own filter when requesting a List in Java.



Option 1) I'm thinking about JavaScript with Rhino.

I get my user's filter as a javascript string. And then call isAccepted(myItem) in this script.

Depending on the reply I accept the element or not.



Option 2) I'm thinking about Groovy.

My user can write Groovy script in a textfield. When my user searches with this filter the Groovy script is compiled in Java (if first call) and call the Java methode isAccepted()
Depending on the reply I accept the element or not.



My application rely a lot on this fonctionallity and it will be called intensively on my server.

So I beleave speed is the key.



Option 1 thinking:
Correct me if I'm wrong, but I think in my case the main advantage of Groovy is the speed but my user can compile and run unwanted code on my server... (any workaround?)



Option 2 thinking:
I think in most people mind JavaScript is more like a toy. Even if it's not my idea at all it is probably for my customers who will not trust it that much. Do you think so?

An other bad point I expect is speed, from my reading on the web.

And again my user can access Java and run unwanted code on my server... (any workaround?)



More info:
I'm running my application on Google App Engine for the main web service of my app.

The filter will be apply 20 times by call.

The filter will be (most of the times) simple.




Any idea to make this filter safe for my server?

Any other approche to make it work?





No comments:

Post a Comment