2

I have created 2 procedure and a java source

One procedure is calling java class TestHostCommand

 PROCEDURE TEST2
  (p_command IN Varchar2)
   AS LANGUAGE JAVA
    NAME 'TestHostCommand.executeCommand(java.lang.String)';

Java Source is:

import java.io.*;

public class TestHostCommand
{

public void executeCommand(String command)
 {
Runtime rt = Runtime.getRuntime();
Process p = null;
try
{
  p = rt.exec("ls > /Orion/list/list.txt");
  return;
} catch ( IOException ioe)
  {
    System.out.println("Error executing file");
  }
}

}

And the other Procedure is to grant permissions but it is generated incorrectly:

     PROCEDURE GRANT_PERMISSION
      (grantee            IN  VARCHAR2,
       permission_type    IN  VARCHAR2,
       permission_name    IN  VARCHAR2,
       permission_action  IN  VARCHAR2)


        IS
        BEGIN
         DBMS_JAVA.grant_permission ('ORION', 'java.io.FilePermission',
                                   '<>', 'read ,write, execute, delete');

         DBMS_JAVA.grant_permission ('ORION', 'SYS:java.lang.RuntimePermission',
                                               'writeFileDescriptor', '');

          DBMS_JAVA.grant_permission ('Orion', 'SYS:java.lang.RuntimePermission',
                                                 'readFileDescriptor', '');

           END; 

Error is invalid object.

Thanks

1 Answer 1

1

The third parameter in the first statement should be a file or directory path, e.g.

     DBMS_JAVA.grant_permission ('ORION', 'java.io.FilePermission',
                               '/home/orion/*', 'read ,write, execute, delete');

Alternatively you could just grant ORION the JAVASYSPRIV role instead, as it's pretty much what you're doing anyway.

Either way, granting maximal privileges to ORION makes the account very poweful, and one which you will need to control tightly, especially in production environments.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer.So i need to have privileges set through a DBA for it to be able to work for me. Thanks
I am currently getting this error: 8:22:50 Execution failed: ORA-29532: Java call terminated by uncaught Java exception: java.lang.SecurityException: policy table update java.io.FilePermission, TestHostCommand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.