Home » Developer & Programmer » JDeveloper, Java & XML » Project Similar to PLPDF - Permissions to external Jar for reading-writing on a file in Oracle jvm
Project Similar to PLPDF - Permissions to external Jar for reading-writing on a file in Oracle jvm [message #356285] Thu, 30 October 2008 03:29
NeO_GeO
Messages: 2
Registered: September 2006
Junior Member
hi all,

I explain my situation.

I ' ve made an open source project similar to plpdf using jasper report libraries and others.
My project, which works perfectly in a java jre, have some problems in Oracle Aurora jvm.

I use the Reflection technique to load the classes from their libraries.

For this i use this class :


import java.io.File;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;



/**
 *
 * @author g.veltro
 */
public class Utility {
  
  public final static ClassLoader sysloader = ClassLoader.getSystemClassLoader();  
    
  public static Object createIstance (Class classe,Object [] parameters,Class [] parametersClasses) throws InstantiationException, IllegalAccessException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException{
        
      Constructor cons = classe.getConstructor(parametersClasses);    
     
      return cons.newInstance(parameters);
  }
    
  public static Object executeMethod(Object obj,Class objClass,String methodName,Object [] parameters,Class [] parametersClasses) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
      
      Method method = objClass.getDeclaredMethod(methodName,parametersClasses);
      method.setAccessible(true);
      
      return method.invoke(obj, parameters);  

      
  }
  
  public static void addJarLibrary(String s) throws MalformedURLException, IOException{        
      addJarLibrary(new File(s));      
  }
  
  public static void addJarLibrary(File f) throws MalformedURLException, IOException{        
      addJarLibrary(f.toURI().toURL());      
  }
  
  public static void addJarLibrary(URL url) throws IOException{
      
      URLClassLoader urlsysloader = null;
      urlsysloader = (URLClassLoader) sysloader;
      
   
      try {          
          executeMethod(urlsysloader,URLClassLoader.class,"addURL",new Object[]{url},new Class[]{URL.class});            
      } catch (Throwable t) {            
          t.printStackTrace();            
          throw new IOException("Error, could not add "+url.getPath()+" to system classloader");
      }
      
      
  }
  
  public static void addJarLibraries(String libDir) throws IOException {
      
      File directory = null;
      directory = new File(libDir);
      
      if(directory.isDirectory()){
      
          JarFilter filter = new JarFilter();      
          File[] jarLibraries = directory.listFiles(filter);      
            
          for(int i=0;i<jarLibraries.length;i++){    
              addJarLibrary(jarLibraries[i]);      
          }     
      } else {                    
          throw new IOException(libDir+" is not a Directory !");       
      }
      
  } 
    
}




I gave all the permissions as dba to allow java to access files, etc. etc
Begin
........
........
dbms_java.grant_permission( 'NEOGEO', 'SYS:java.lang.RuntimePermission', 'accessDeclaredMembers', '' );
dbms_java.grant_permission( 'NEOGEO', 'SYS:java.lang.reflect.ReflectPermission', 'suppressAccessChecks', '' );
........
end;



Then when I try to call a class library that attempts to access a file residing in the file-system i recive an exception.

This is an example of code that call a class and execute one methods.



    public static Object compileJrxml(String path_file_jrxml) throws ClassNotFoundException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
        
       Object jReport = null;  
       Object jCompileManager = null;
       Class jcmClass = null;
       
       Object [] params = {path_file_jrxml};
       Class [] paramsClasses = {String.class};
       
       jcmClass = Class.forName("net.sf.jasperreports.engine.JasperCompileManager",true,org.Reflection.Utility.sysloader);
       jCompileManager = jcmClass.newInstance();
       
       // compilazione del report 
       jReport = Utility.executeMethod(jCompileManager,jcmClass,"compileReport",params,paramsClasses);
              
       return jReport;        
   
    }


this is the exception :

java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java)
at java.lang.reflect.Method.invoke(Method.java)
at org.Reflection.Utility.executeMethod(Utility.java)
at org.EngineReport.ReportControl.compileJrxml(ReportControl.java:44)
at org.EngineReport.ReportOracle.getReportByte(ReportOracle.java:130)
at org.EngineReport.ReportOracle.ReportAsBlob(ReportOracle.java:69)
at org.EngineReport.ReportOracle.ReportAsBlob(ReportOracle.java:49)
Caused by: java.security.AccessControlException: the Permission (java.io.FilePermission /home/neogeo/Java_Resources.jrxml read) has not been granted to ProtectionDomain (file:/home/neogeo/lib/jasperreports-3.0.0.jar <no signer certificates>)
AppClassLoader: file:/home/neogeo/lib/xml-apis.jar file:/home/neogeo/lib/jpa.jar file:/home/neogeo/lib/jdt-compiler-3.1.1.jar file:/home/neogeo/lib/png-encoder-1.5.jar file:/home/neogeo/lib/ant-1.5.1.jar file:/home/neogeo/lib/jaxen-1.1.1.jar file:/home/neogeo/lib/mondrian-2.3.2.8944.jar file:/home/neogeo/lib/commons-javaflow-20060411.jar file:/home/neogeo/lib/batik-bridge.jar file:/home/neogeo/lib/antlr-2.7.5.jar file:/home/neogeo/lib/batik-parser.jar file:/home/neogeo/lib/hibernate3.jar file:/home/neogeo/lib/batik-ext.jar file:/home/neogeo/lib/commons-logging-1.0.2.jar file:/home/neogeo/lib/jasperreports-3.0.0.jar file:/home/neogeo/lib/batik-svggen.jar file:/home/neogeo/lib/batik-xml.jar file:/home/neogeo/lib/xml-apis-ext.jar file:/home/neogeo/lib/batik-dom.jar file:/home/neogeo/lib/jakarta-bcel-20050813.jar file:/home/neogeo/lib/servlet.jar file:/home/neogeo/lib/hsqldb-1.7.1.jar file:/home/neogeo/lib/batik-gvt.jar file:/home/neogeo/lib/batik-svg-dom.jar file:/home/neogeo/lib/jxl-2.6.jar file:/home/neogeo/lib/groovy-all-1.5.5.jar file:/home/neogeo/lib/xercesImpl.jar file:/home/neogeo/lib/batik-awt-util.jar file:/home/neogeo/lib/bsh-2.0b4.jar file:/home/neogeo/lib/commons-digester-1.7.jar file:/home/neogeo/lib/batik-css.jar file:/home/neogeo/lib/commons-logging-api-1.0.2.jar file:/home/neogeo/lib/jfreechart-1.0.0.jar file:/home/neogeo/lib/itext-1.3.1.jar file:/home/neogeo/lib/poi-3.0.1-FINAL-20070705.jar file:/home/neogeo/lib/batik-util.jar file:/home/neogeo/lib/commons-beanutils-1.7.jar file:/home/neogeo/lib/jcommon-1.0.0.jar file:/home/neogeo/lib/saaj-api-1.3.jar file:/home/neogeo/lib/batik-script.jar file:/home/neogeo/lib/xalan.jar file:/home/neogeo/lib/batik-anim.jar file:/home/neogeo/lib/commons-collections-2.1.jar
<no principals>
java.security.Permissions@1aebb385 (
(java.io.FilePermission /home/neogeo/lib/jasperreports-3.0.0.jar read)
(java.util.PropertyPermission user.language write)
(java.util.PropertyPermission * read)
(java.lang.RuntimePermission modifyThreadGroup)
(java.lang.RuntimePermission createSecurityManager)
(java.lang.RuntimePermission modifyThread)
(java.lang.RuntimePermission preferences)
(java.lang.RuntimePermission exitVM)
(oracle.aurora.security.JServerPermission LoadClassInPackage.*)
)

. 
at java.security.AccessControlContext.checkPermission(AccessControlContext.java)
at java.security.AccessController.checkPermission(AccessController.java)
at java.lang.SecurityManager.checkPermission(SecurityManager.java)
at oracle.aurora.rdbms.SecurityManagerImpl.checkPermission(SecurityManagerImpl.java)
at java.lang.SecurityManager.checkRead(SecurityManager.java)
at java.io.FileInputStream.<init>(FileInputStream.java)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:167)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:152)
at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:150)
... 9 more


The problem i think is that i have to give the permission for input and output on files to an external jar-library .
I don't know how i can resolve this problem ....
Do you have any suggestions?
Previous Topic: problem with session
Next Topic: XML from database
Goto Forum:
  


Current Time: Mon Dec 05 15:20:23 CST 2016

Total time taken to generate the page: 0.09229 seconds