dbTalk Databases Forums  

JAVA file permissions

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss JAVA file permissions in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CenturionX
 
Posts: n/a

Default JAVA file permissions - 07-07-2009 , 10:07 AM






Hello,

I'm working with ORACLE 10.2.0.4.0 on windows server 2003 R2.

I need to execute a DOS batch file. I used some code i found in the
web (see the code below).

When i try to give permission to execut ethe file:
EXEC DBMS_JAVA.grant_permission('CMS',
'SYS.java.io.FilePermission', 'K:\Mesr\DBP_EXEC_FROM_ORA\',
'read ,write, execute');

I get this error:

ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ClassNotFoundException: sys/java/io/filepermission
ORA-06512: at "SYS.DBMS_JAVA", line 313
ORA-06512: at line 1

Somebody has a good idea on this.

THANKS.



CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
public static void executeCommand(String command) {
try {
String[] finalCommand;
if (isWindows()) {
finalCommand = new String[4];
// Use the appropriate path for your windows version.
finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; //
Windows XP/2003
//finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; //
Windows NT/2000
finalCommand[1] = "/y";
finalCommand[2] = "/c";
finalCommand[3] = command;
}
else {
finalCommand = new String[3];
finalCommand[0] = "/bin/sh";
finalCommand[1] = "-c";
finalCommand[2] = command;
}

final Process pr = Runtime.getRuntime().exec(finalCommand);
pr.waitFor();

new Thread(new Runnable(){
public void run() {
BufferedReader br_in = null;
try {
br_in = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
String buff = null;
while ((buff = br_in.readLine()) != null) {
System.out.println("Process out :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_in.close();
}
catch (IOException ioe) {
System.out.println("Exception caught printing process
output.");
ioe.printStackTrace();
}
finally {
try {
br_in.close();
} catch (Exception ex) {}
}
}
}).start();

new Thread(new Runnable(){
public void run() {
BufferedReader br_err = null;
try {
br_err = new BufferedReader(new InputStreamReader
(pr.getErrorStream()));
String buff = null;
while ((buff = br_err.readLine()) != null) {
System.out.println("Process err :" + buff);
try {Thread.sleep(100); } catch(Exception e) {}
}
br_err.close();
}
catch (IOException ioe) {
System.out.println("Exception caught printing process
error.");
ioe.printStackTrace();
}
finally {
try {
br_err.close();
} catch (Exception ex) {}
}
}
}).start();
}
catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
}

public static boolean isWindows() {
if (System.getProperty("os.name").toLowerCase().index Of
("windows") != -1)
return true;
else
return false;
}

};
/
show errors java source "Host"


CREATE OR REPLACE PROCEDURE host_command (p_command IN VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
/
show errors


EXEC DBMS_JAVA.grant_permission('CMS', 'SYS.java.io.FilePermission',
'K:\Mesr\DBP_EXEC_FROM_ORA\', 'read ,write, execute');
EXEC Dbms_Java.Grant_Permission('CMS',
'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission('CMS',
'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');

Reply With Quote
  #2  
Old   
ddf
 
Posts: n/a

Default Re: JAVA file permissions - 07-07-2009 , 10:24 AM






On Jul 7, 10:07*am, CenturionX <darwinbaldr... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

I'm working with ORACLE 10.2.0.4.0 on windows server 2003 R2.

I need to execute a DOS batch file. *I used some code i found in the
web (see the code below).

When i try to give permission to execut ethe file:
* *EXEC DBMS_JAVA.grant_permission('CMS',
'SYS.java.io.FilePermission', 'K:\Mesr\DBP_EXEC_FROM_ORA\',
'read ,write, execute');

I get this error:

ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ClassNotFoundException: sys/java/io/filepermission
ORA-06512: at "SYS.DBMS_JAVA", line 313
ORA-06512: at line 1

Somebody has a good idea on this.

THANKS.

CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "Host" AS
import java.io.*;
public class Host {
* public static void executeCommand(String command) {
* * try {
* * * String[] finalCommand;
* * * if (isWindows()) {
* * * * finalCommand = new String[4];
* * * * // Use the appropriate path for your windows version.
* * * * finalCommand[0] = "C:\\windows\\system32\\cmd.exe"; *//
Windows XP/2003
* * * * //finalCommand[0] = "C:\\winnt\\system32\\cmd.exe"; *//
Windows NT/2000
* * * * finalCommand[1] = "/y";
* * * * finalCommand[2] = "/c";
* * * * finalCommand[3] = command;
* * * }
* * * else {
* * * * finalCommand = new String[3];
* * * * finalCommand[0] = "/bin/sh";
* * * * finalCommand[1] = "-c";
* * * * finalCommand[2] = command;
* * * }

* * * final Process pr = Runtime.getRuntime().exec(finalCommand);
* * * pr.waitFor();

* * * new Thread(new Runnable(){
* * * * public void run() {
* * * * * BufferedReader br_in = null;
* * * * * try {
* * * * * * br_in = new BufferedReader(new InputStreamReader
(pr.getInputStream()));
* * * * * * String buff = null;
* * * * * * while ((buff = br_in.readLine()) != null) {
* * * * * * * System.out.println("Process out :" + buff);
* * * * * * * try {Thread.sleep(100); } catch(Exception e) {}
* * * * * * }
* * * * * * br_in.close();
* * * * * }
* * * * * catch (IOException ioe) {
* * * * * * System.out.println("Exception caught printing process
output.");
* * * * * * ioe.printStackTrace();
* * * * * }
* * * * * finally {
* * * * * * try {
* * * * * * * br_in.close();
* * * * * * } catch (Exception ex) {}
* * * * * }
* * * * }
* * * }).start();

* * * new Thread(new Runnable(){
* * * * public void run() {
* * * * * BufferedReader br_err = null;
* * * * * try {
* * * * * * br_err = new BufferedReader(new InputStreamReader
(pr.getErrorStream()));
* * * * * * String buff = null;
* * * * * * while ((buff = br_err.readLine()) != null) {
* * * * * * * System.out.println("Process err :" + buff);
* * * * * * * try {Thread.sleep(100); } catch(Exception e) {}
* * * * * * }
* * * * * * br_err.close();
* * * * * }
* * * * * catch (IOException ioe) {
* * * * * * System.out.println("Exception caught printing process
error.");
* * * * * * ioe.printStackTrace();
* * * * * }
* * * * * finally {
* * * * * * try {
* * * * * * * br_err.close();
* * * * * * } catch (Exception ex) {}
* * * * * }
* * * * }
* * * }).start();
* * }
* * catch (Exception ex) {
* * * System.out.println(ex.getLocalizedMessage());
* * }
* }

* public static boolean isWindows() {
* * if (System.getProperty("os.name").toLowerCase().index Of
("windows") != -1)
* * * return true;
* * else
* * * return false;
* }

};

/
show errors java source "Host"

CREATE OR REPLACE PROCEDURE host_command (p_command *IN *VARCHAR2)
AS LANGUAGE JAVA
NAME 'Host.executeCommand (java.lang.String)';
/
show errors

EXEC DBMS_JAVA.grant_permission('CMS', 'SYS.java.io.FilePermission',
'K:\Mesr\DBP_EXEC_FROM_ORA\', 'read ,write, execute');
EXEC Dbms_Java.Grant_Permission('CMS',
'SYS:java.lang.RuntimePermission', 'writeFileDescriptor', '');
EXEC Dbms_Java.Grant_Permission('CMS',
'SYS:java.lang.RuntimePermission', 'readFileDescriptor', '');
Normally the \ is an escape character; have you given thought to
possibly changing the string to this:

EXEC DBMS_JAVA.grant_permission('CMS', 'SYS.java.io.FilePermission',
'K:\\Mesr\\DBP_EXEC_FROM_ORA\\', 'read ,write, execute');


David Fitzjarrell

Reply With Quote
  #3  
Old   
CenturionX
 
Posts: n/a

Default Re: JAVA file permissions - 07-07-2009 , 10:42 AM



I tryed that and specifying the file name too:
EXEC DBMS_JAVA.grant_permission('CMS', 'SYS.java.io.FilePermission',
'K:\\Mesr\\DBP_EXEC_FROM_ORA\\', 'read ,write, execute');
EXEC DBMS_JAVA.grant_permission('CMS', 'SYS.java.io.FilePermission',
'K:\\Mesr\\DBP_EXEC_FROM_ORA\\DBP.BAT', 'read ,write, execute');

But the error persists.

Thanks.

Reply With Quote
  #4  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: JAVA file permissions - 07-07-2009 , 10:51 AM



CenturionX (darwinbaldrich (AT) gmail (DOT) com) wrote:
: Hello,

: I'm working with ORACLE 10.2.0.4.0 on windows server 2003 R2.

: I need to execute a DOS batch file. I used some code i found in the
: web (see the code below).

: When i try to give permission to execut ethe file:
: EXEC DBMS_JAVA.grant_permission('CMS',
: 'SYS.java.io.FilePermission', 'K:\Mesr\DBP_EXEC_FROM_ORA\',
: 'read ,write, execute');

: I get this error:

: ORA-29532: Java call terminated by uncaught Java exception:
: java.lang.ClassNotFoundException: sys/java/io/filepermission
: ORA-06512: at "SYS.DBMS_JAVA", line 313
: ORA-06512: at line 1

The error says that the class sys/java/io/filepermission does not exist.

I think the class name is probably what is wrong, perhaps that should be
java.io.filepermission

Reply With Quote
  #5  
Old   
Vladimir M. Zakharychev
 
Posts: n/a

Default Re: JAVA file permissions - 07-13-2009 , 02:41 AM



On Jul 7, 7:07*pm, CenturionX <darwinbaldr... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

I'm working with ORACLE 10.2.0.4.0 on windows server 2003 R2.

I need to execute a DOS batch file. *I used some code i found in the
web (see the code below).

When i try to give permission to execut ethe file:
* *EXEC DBMS_JAVA.grant_permission('CMS',
'SYS.java.io.FilePermission', 'K:\Mesr\DBP_EXEC_FROM_ORA\',
'read ,write, execute');

I get this error:

ORA-29532: Java call terminated by uncaught Java exception:
java.lang.ClassNotFoundException: sys/java/io/filepermission
ORA-06512: at "SYS.DBMS_JAVA", line 313
ORA-06512: at line 1

Somebody has a good idea on this.

This call should look like this:

EXEC DBMS_JAVA.grant_permission('CMS', 'SYS:java.io.FilePermission',
'K:\Mesr\DBP_EXEC_FROM_ORA\', 'read ,write, execute');

that is, replace the dot after SYS with colon in the permission class
name.

Hth,
Vladimir M. Zakharychev
N-Networks, makers of Dynamic PSP(tm)
http://www.dynamicpsp.com

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.