How to call java API from javascript server-side functions?

Hi,

seeing this post (https://stackoverflow.com/questions/29764754/creating-a-sha-256-hash-in-orientdb-function), I thought it would be easy to create a javascript server-side function calling java API.

My function is as follow:
return com.orientechnologies.orient.core.security.OSecurityManager.instance().digest2String(“password”);

and the error is as follow:
java.lang.ClassNotFoundException: com.orientechnologies.orient.core.security.OSecurityManager.instance

=> is it truly possible to call java API using javascript server-side functions on odb 3.0.29?

Thanks in advance.
Christian

Hi @cmichon

this worked until 3.0.28, which didn’t contain the JS sandbox. Now we implemented the sandbox and by default you cannot access to any java code, only to the injected context which is the database for query.

If you want to use OSecurity manager you should activate it in the configuration file. something like this

        <handler
                class="com.orientechnologies.orient.server.handler.OServerSideScriptInterpreter">
            <parameters>
                <parameter name="enabled" value="true"/>
                <parameter name="allowedLanguages" value="SQL"/>
                <!--  Comma separated packages  allowed in JS scripts eg. java.math.*, java.util.ArrayList -->
                <parameter name="allowedPackages" value="com.orientechnologies.orient.core.security.OSecurityManager"/>
            </parameters>
        </handler>

Let me know if this helps

Thanks

Thanks! It worked the sandboxing was the issue to reach the java class.

Please note that digest2String() is not available in that particular version. So I used another function.