Home Database Mysql Tutorial Applet虽签名,但是异常:java.security.AccessControlException

Applet虽签名,但是异常:java.security.AccessControlException

Jun 07, 2016 pm 03:42 PM
but abnormal sign

原文来源: http://blog.csdn.net/faye0412/article/details/7037078 一个Applet的项目,在客户端无论使用什么浏览器都无法正常运行,我检查了一下,异常信息如下: java.security.AccessControlException: access denied (java.io.FilePermission ALL FILES,

原文来源: http://blog.csdn.net/faye0412/article/details/7037078

一个Applet的项目,在客户端无论使用什么浏览器都无法正常运行,我检查了一下,异常信息如下:
java.security.AccessControlException: access denied (java.io.FilePermission ">", "execute")...
.....


这个问题在开发的时候也曾经遇到过,后来签名后解决了,但是最近为啥又冒出来了呢?奇怪....

我又找了N台机器,不同版本的浏览器(ie7,8,9...Cheome, Firefox....)都测了一遍发现一个问题:

1. 与浏览器无关,而是与jre的版本有关;

2. jre版本高于1.6.0_20的都不能正常运行,低于该版本的都可以正常运行(我的是JRE 版本 1.6.0_29-b11,不能运行);


如何解决呢?于是我找了Oracle里N多相关的文档,比如:

http://java.sun.com/developer/onlineTraining/Programming/JDCBook/signed.html(签名Applet)

http://docs.oracle.com/javase/1.4.2/docs/guide/security/permissions.html(Permissions in the JavaTM 2 SDK)


等等,都没啥进展。我尝试了如下方法:

1. 定义私有policy文件的方法;

2. 修改Java默认安全策略文件(不太安全), ${java.home}/lib/security/java.security文件,增加授权方式;


都没起作用(可能是我没弄对?),但是我们不能让每一个客户都去修改他们自己的安全策略文件,毕竟不是每一个人都那么专业,客户也不会愿意接受这种方式的。


问题解决:

后来在翻阅文档后发现了一个重要的方法,可以很快速的解决我的问题,那就是:使用AccessController.doPrivileged提升代码权限!如果不期望客户端修改JRE中的安全配置,可以选择在代码中提升,而这个就是我所期待的!

在客户端弹出的jdk的对话框中只要用户点击信任,运行按钮,也就是说如果信任此签名,将可以执行此代码:AccessController.doPrivileged(...),Applet权限也将得到提升。


具体示例代码如下:

[java] view plaincopy

  1. private String runCmd(){  
  2.     String result = AccessController.doPrivileged(new PrivilegedAction() {    
  3.         @Override    
  4.         public String run() {  
  5.                 String res = null;  
  6.         //TODO like 'Runtime.getRuntime().exec(cmd)' etc.....  
  7.                 return res;    
  8.             }  
  9.         });  
  10.     return result;  
  11. }  

就这样,简单的几句话就搞定了。。。。

别忘了,最后需要做的是重新打jar包,签名,然后将证书和keystore文件,jar文件重新发布到服务器测试:)


补充:

之前也曾写过一篇文章《关于JS调用Applet的执行权限的问题》(http://blog.csdn.net/faye0412/article/details/4566400),里面提到了使用SwingUtilities.invokeLater(new Runnable()...的方式,但是这种方法只能解决之前的签名和Applet假死的情况,不能解决现在遇到的这种情况,所以,最好的方式是结合这两种方法使用。问题完美解决!!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to verify signature in PDF How to verify signature in PDF Feb 18, 2024 pm 05:33 PM

We usually receive PDF files from the government or other agencies, some with digital signatures. After verifying the signature, we see the SignatureValid message and a green check mark. If the signature is not verified, the validity is unknown. Verifying signatures is important, let’s see how to do it in PDF. How to Verify Signatures in PDF Verifying signatures in PDF format makes it more trustworthy and the document more likely to be accepted. You can verify signatures in PDF documents in the following ways. Open the PDF in Adobe Reader Right-click the signature and select Show Signature Properties Click the Show Signer Certificate button Add the signature to the Trusted Certificates list from the Trust tab Click Verify Signature to complete the verification Let

What are the common causes of OutOfMemoryError exceptions in Java? What are the common causes of OutOfMemoryError exceptions in Java? Jun 25, 2023 pm 08:43 PM

Java is one of the most widely used programming languages, but when developing applications using Java, it is easy to encounter "OutOfMemoryError" exception errors, which often bring some challenges to developers. What exactly causes the OutOfMemoryError exception in Java? Next, let’s take a closer look. Memory Leak (MemoryLeak) Memory leak refers to when an object cannot be recycled by the garbage collector, it will cause a memory leak.

Outlook signature disappears every day after restart Outlook signature disappears every day after restart Feb 19, 2024 pm 05:24 PM

An email signature is important to demonstrate legitimacy and professionalism and includes contact information and company logo. Outlook users often complain that signatures disappear after restarting, which can be frustrating for those looking to increase their company's visibility. In this article, we will explore different fixes to resolve this issue. Why do my Microsoft Outlook signatures keep disappearing? If this is your first time using Microsoft Outlook, make sure your version is not a trial version. Trial versions may cause signatures to disappear. Additionally, the version architecture should also match the version architecture of the operating system. If you find that your email signature disappears from time to time in Outlook Web App, it may be due to

How to solve Java thread interrupt timeout exception (ThreadInterruptedTimeoutExceotion) How to solve Java thread interrupt timeout exception (ThreadInterruptedTimeoutExceotion) Aug 18, 2023 pm 01:57 PM

How to solve the Java thread interrupt timeout exception (ThreadInterruptedTimeoutException). In Java multi-thread programming, we often encounter situations where the thread execution time is too long. In order to prevent threads from occupying too many system resources, we usually set a timeout. When the thread execution time exceeds the timeout, we hope to be able to interrupt the execution of the thread. Java provides a thread interruption mechanism. By calling the thread's interrupt() method, you can

Methods to solve Java reflection exception (ReflectiveOperationException) Methods to solve Java reflection exception (ReflectiveOperationException) Aug 26, 2023 am 09:55 AM

Methods to solve Java reflection exceptions (ReflectiveOperationException) In Java development, reflection (Reflection) is a powerful mechanism that allows programs to dynamically obtain and operate classes, objects, methods, properties, etc. at runtime. Through reflection, we can implement some flexible functions, such as dynamically creating objects, calling private methods, obtaining class annotations, etc. However, using reflection also brings some potential risks and problems, one of which is reflection anomalies (

A guide to the unusual missions in the Rise of Ronin Pool A guide to the unusual missions in the Rise of Ronin Pool Mar 26, 2024 pm 08:06 PM

The abnormality in the pool is a side task in the game. Many players want to know how to complete the abnormality in the pool task. It is actually very simple. First, we must master the technique of shooting in the water before we can accept the task and investigate the source of the stench. Later, we discovered It turns out that there are a lot of corpses under the pool. Let’s take a look at this graphic guide for the unusual tasks in the pool in Rise of Ronin. Guide to unusual missions in the Ronin Rise Pool: 1. Talk to Iizuka and learn the technique of shooting in the water. 2. Go to the location in the picture below to receive the abnormal task in the pool. 3. Go to the mission location and talk to the NPC, and learn that there is a foul smell in the nearby pool. 4. Go to the pool to investigate. 5. Swim to the location in the picture below, dive underwater, and you will find a lot of corpses. 6. Use a camera to take pictures of the corpse. 7

Practical tips for efficiently solving Java large file reading exceptions Practical tips for efficiently solving Java large file reading exceptions Feb 21, 2024 am 10:54 AM

Practical tips for efficiently resolving large file read exceptions in Java require specific code examples. Overview: When processing large files, Java may face problems such as memory overflow and performance degradation. This article will introduce several practical techniques to effectively solve Java large file reading exceptions, and provide specific code examples. Background: When processing large files, we may need to read the file contents into memory for processing, such as searching, analyzing, extracting and other operations. However, when the file is large, the following problems are often encountered: Memory overflow: trying to copy the entire file at once

MIT's latest masterpiece: using GPT-3.5 to solve the problem of time series anomaly detection MIT's latest masterpiece: using GPT-3.5 to solve the problem of time series anomaly detection Jun 08, 2024 pm 06:09 PM

Today I would like to introduce to you an article published by MIT last week, using GPT-3.5-turbo to solve the problem of time series anomaly detection, and initially verifying the effectiveness of LLM in time series anomaly detection. There is no finetune in the whole process, and GPT-3.5-turbo is used directly for anomaly detection. The core of this article is how to convert time series into input that can be recognized by GPT-3.5-turbo, and how to design prompts or pipelines to let LLM solve the anomaly detection task. Let me introduce this work to you in detail. Image paper title: Largelanguagemodelscanbezero-shotanomalydete

See all articles