AccessControlException的因和果



applet项目中,总会遇到java.security.AccessControlException:这类异常.

在这里总结一下applet会遇到这些异常的情况和解决办法.

     产生这个异常都是由java的安全性所致.

    Applet属于网页加载的代码,所以被限定了安全级别,也就是说,很多事,没通过一些特定权限的授予,都是不能干的.以下是被禁止的操作:

     不能访问本地文件,不能读取或者写入,深圳不能获得文件相关信息(是否存在,修改日期)

不能访问任何内存地址

不能打印文档

不能启动客户端的其他程序,也就是不能执行System.exec()或者Runtime.exec()

不能获取系统参数,System.getProperty(),那更加不能设置系统属性了

不能定义或使用ClassLoader,SecurityManager,Content-HandlerFactory,SocketImplFactory或者URLStreamHandlerFactory的新实例,必须是已经存在的实例.

不能建立除加载此applet主机外的链接,也就是只能连加载此applet的主机

      虽说这些限制对于经过数字签名的代码会有所放松,但有时候不一定灵

   解决办法就是你把所有这些操作,加到一个特权类里面,表示这些操作享有特权.

     AccessController.doPrivileged(new PrivilegedAction() {
            public Object run() {
                  // privileged code goes here, for example:
                   System.getProperty(….)

                   returnnull;// nothing to return
           }
      });

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Trace File Manager (TFM) - Using PHP and Oracle to manage your distributed trace files--------------------------------------------------------------------------------------Deployment InstructionsOracle Layer The Oracle JServer must be installed and exist in a valid state. Ensure that the directories specified in the parameters for USER_DUMP_DEST and BACKGROUND_DUMP_DEST are set up as utl_file_dir directives in the init.ora, eg utl_file_dir=myDB/oratrace/back utl_file_dir=myDB/oratrace/user Run all of the below mentioned scripts in any database whose trace files you want to view As SYS create a user account (TFMADMIN) See - tfmadmin_create.sql This account will be the repository for all of the Oracle objects used by the utility and will be responsible for retrieving information from the file system for presentation to the PHP layer. nb ! The supplied create script is for demo purposes only. You will need to specify a password and you may also want to assign alternative default and temporary tablespaces. create the external library call Windows - see extWindows.sql Linux - see extLinux.sql nb ! for unix it would be ; create or replace library systemcalls is ‘/lib/libc.so‘; / grant necessary database privileges to tfmadmin tfmAdmin_privs_and_syns.sql grant necessary java privileges to tfmadmin tfmAdmin_java_privs.sql if this fails with any spurious dbms_java errors then issue the statements manually, eg exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘your background_dump_dest‘, ‘read‘) exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘your user_dump_dest‘, ‘read‘) create a wrapper package for utl_file pk_utl_file.sql As TFMADMIN set up the tables, views and sequence tfmadmin_objects.sql create the controlling package pack_trace_file_manager.sqlJava Layer TraceFileDisplay.java you need to compile this and use loadjava to deploy it into the TFMADMIN account sample compilation & load - see javacomp.txt test the Java layer - RECOMMENDED I have seen occasions where the java security layer behaves unpredictably and this can result in the Trace File Display utility falsely reporting that there are no trace files in the trace directories. consequently it is a sensible idea to verify that your java layer is behaving as expected before you try starting up the utility as TFMADMIN, try this exec pack_trace_file_manager.pc_generate_file_list (‘BACKGROUND‘) if you get a "PL/SQL procedure completed successfully" then everything is OK if you get something like this ... * ERROR at line 1: ORA-29532: Java call terminated by uncaught Java exception: java.security.AccessControlException: th (java.io.FilePermission D:OCCdboratraceack read) has not been granted to TFMADMIN. The PL/SQL to dbms_java.grant_permission( ‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘, ‘D:OCCdboratraceack‘, ‘rea ORA-06512: at "TFMADMIN.PACK_TRACE_FILE_DISPLAY", line 45 ORA-06512: at "TFMADMIN.PACK_TRACE_FILE_DISPLAY", line 135 ORA-06512: at line 1 then you will need to sort it out before you go any further. Firstly, check out Note:137280.1 on Metalink. If the error persists beyond the solution suggested here then try; as SYS grant JAVASYSPRIV, JAVAUSERPRIV to tfmadmin; If this does not help then you can always adopt the "Mit Kanonen auf Spatzen schie遝n" approach (Shooting sparrows with canons ...) ; exec dbms_java.grant_permission (‘TFMADMIN‘, ‘SYS:java.io.FilePermission‘,‘<<ALL FILES>>‘, ‘read‘); If that doesn‘t work then raise it with Oracle Support - there may well be a fundamental problem with your java layer.Apahe / PHP layer If you haven‘t already done so, deploy Apache and PHP in a centralised location. see http://otn.oracle.com/tech/opensource/php/apache/inst_php_apache_windows.html for a handy guide to deployment source code ; listTargets.php listFiles.php * retrieveTraceFile.php * tkprofDialog.php deleteFilesConfirmation.php * you may need to either remove or edit the YourDomain tag in here I found the easist way to make the oci connection work from a php source file was to specify the full connection string as it would appear in the tnsnames.ora - In our environment this included a domain name - what you do will depend on your personal environment ... configuration files user.conf - contains the username & password for db connections made to the TFMADMIN account from the php layer - edit as required targets.conf - contains a list of the connection details for the databases where TFMADMIN is deployed - edit as required cascading stylesheet - not supplied
### 回答1: accesscontrolexception是Java中的一个异常类,表示访问控制异常。当试图访问受保护的资源时,如果没有足够的权限,则会抛出这个异常。通常情况下,这个异常是由Java安全管理器抛出的。 ### 回答2: AccessControlException(访问控制异常)是Java编程语言的一个异常类型,用于指示当尝试访问受限资源时发生了安全限制。 当程序运行时,Java的安全管理器可以限制对特定资源(如文件、网络、系统属性等)的访问。如果违反了这些访问限制,就会抛出AccessControlException异常。 AccessControlException通常由以下原因引起: 1. 未授予程序访问资源所需的安全权限。 2. 程序尝试打开受限的网络连接。 3. 程序尝试读取或写入文件系统中受限的文件。 4. 程序尝试访问受限的系统属性或环境变量。 要解决AccessControlException异常,可以采取以下措施: 1. 检查程序是否具有所需的安全权限。可以使用Java SecurityManager和访问策略文件来分配和管理安全权限。 2. 如果程序需要访问网络连接或文件系统中的受限资源,可以使用Java Policy文件来允许对特定资源的访问。 3. 确保程序在安全环境下运行,并遵循安全最佳实践。 4. 检查操作系统和网络配置,确保没有其他限制导致程序无法访问所需资源。 需要注意的是,处理AccessControlException异常需要谨慎,不应该简单地忽略或捕获异常并继续执行。应该仔细检查异常的原因,并采取适当的措施来修复或处理引发异常的问题。 ### 回答3: AccessControlException是一个Java异常,表示在执行安全操作时发生了安全限制的访问违规。 AccessControlException通常在Java安全管理器检查访问权限时抛出。安全管理器用于实施系统安全策略,限制代码对资源的访问。当代码试图访问受限资源时,SecurityManager会抛出AccessControlExceptionAccessControlException通常发生在以下情况下: 1. 代码试图在没有适当权限的情况下访问受保护的资源,比如文件或网络。 2. 安全管理器机制没有正确配置,无法为代码提供所需的访问权限。 要解决AccessControlException,可以采取以下步骤: 1. 确保代码具有所需的访问权限。可以通过检查权限设置或在代码中添加权限认证逻辑来实现。 2. 检查安全策略文件,确保正确配置了所需的权限。 3. 使用SecurityManager类提供的方法来设置和管理权限。 在应用程序中处理AccessControlException通常需要在代码中捕获并处理异常。可以使用try-catch块来捕获AccessControlException,并采取适当的措施来处理异常情况,比如提示用户或记录错误。 总而言之,AccessControlException是一种Java异常,表示在执行安全操作时发生了访问违规。通过正确配置访问权限和安全策略,以及处理异常情况,可以解决AccessControlException问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值