Applet数字签名

Applet数字签名

我用applet做了一个文件的上传和下载在本机和内网服务器上和xp上好使,把代码打到windows2003上win7系统文件的上传和下载就不好使报一下错误:

java.security.AccessControlException: access denied (java.util.PropertyPermission user.dir read)
at java.security.AccessControlContext.checkPermission(Unknown Source)
at java.security.AccessController.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPermission(Unknown Source)
at java.lang.SecurityManager.checkPropertyAccess(Unknown Source)
at java.lang.System.getProperty(Unknown Source)
at java.io.Win32FileSystem.getUserPath(Unknown Source)
at java.io.Win32FileSystem.resolve(Unknown Source)
at java.io.File.getAbsolutePath(Unknown Source)
at javax.swing.filechooser.WindowsFileSystemView.isFloppyDrive(Unknown Source)
at javax.swing.plaf.basic.BasicFileChooserUI$BasicFileView.getIcon(Unknown Source)
at javax.swing.JFileChooser.getIcon(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxRenderer.getListCellRendererComponent(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.updateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(Unknown Source)
at javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.fireValueChanged(Unknown Source)
at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
at javax.swing.DefaultListSelectionModel.changeSelection(Unknown Source)
at javax.swing.DefaultListSelectionModel.setSelectionInterval(Unknown Source)
at javax.swing.JList.setSelectedIndex(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup.setListSelection(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup.access$300(Unknown Source)
at javax.swing.plaf.basic.BasicComboPopup$Handler.itemStateChanged(Unknown Source)
at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)
at javax.swing.JComboBox.selectedItemChanged(Unknown Source)
at javax.swing.JComboBox.contentsChanged(Unknown Source)
at javax.swing.AbstractListModel.fireContentsChanged(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.setSelectedItem(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.addItem(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.access$900(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI.doDirectoryChanged(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI.access$1200(Unknown Source)
at javax.swing.plaf.metal.MetalFileChooserUI$5.propertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.beans.PropertyChangeSupport.firePropertyChange(Unknown Source)
at java.awt.Component.firePropertyChange(Unknown Source)
at javax.swing.JFileChooser.setCurrentDirectory(Unknown Source)
at javax.swing.JFileChooser.<init>(Unknown Source)
at javax.swing.JFileChooser.<init>(Unknown Source)
at com.pxl.client.ppm.pm.ProjectManageUI.actionPerformed(ProjectManageUI.java:1112)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


这个问题让我很头疼,我在网上找了很多关于java安全策略的资料,大致都是拿来主义,在java jre \lib\security\ java.policy修改了此文件如下:
//grant codeBase "file:${{java.ext.dirs}}/*" {
//permission java.security.AllPermission;
//};

grant codeBase "http://*/-" {
permission java.security.AllPermission;
permission java.io.FilePermission "<<ALL FILES>>", "read";
permission java.io.FilePermission "<<ALL FILES>>", "write";
permission java.util.PropertyPermission "*", "write,read";
permission java.util.PropertyPermission "user.dir", "read";
};
修改之后还是不好使,哎!头疼,最后还是不得不用applet的数字签名
不好就是打一次补丁就的生成一次数字签名,还有就是你的大错一次就的清除ie的缓存一次,要不然就会一直报同样的错误

以下是数字签名的步骤
步骤一:jar文件
1. 可以用eclipse导入jar文件
2. 可以用命令如:jar -cvf MyApplet.jar class (cmd?文件目录)

步骤二:(在网页中嵌入Applet)(如何在Html嵌入Apple方法见附录)
下面是嵌入Applet部分的写法:
<APPLET
CODEBASE = "."
CODE = "jcomponent.FileReaderApplet.class"
ARCHIVE ="MyClass.jar"
NAME = "TestApplet"
WIDTH = 400
HEIGHT = 300
HSPACE = 0
VSPACE = 0
ALIGN = middle

</APPLET>


步骤三:(生成证书及签名)

  1、keytool -genkey -keystore pepper.store -alias pepper
  这个命令用来产生一个密匙库,执行完毕后应该在c:/admin中产生一个pepper.store的文件,这里的pepper是我自己的名字,你可以对它进行修改。另外在执行命令的时候还有提示你输入密匙库的密码,这里你一定要记住,否则后面要用的时候无法输入。

  2、keytool -export -keystore pepper.store -alias pepper -file pepper.cert
  这个命令用来产生签名时所要用的证书,同样这里的pepper也可以换成你自己需要的名字。这个命令执行完后在c:/admin中产生一个pepper.cert的文件。

  3、 jarsigner -keystore pepper.store MyApplet.jar pepper
  这个命令用上面产生的证书将我们的jar文件进行了签名。

步骤四:新建一个策略文件,并把这些策略文件加入(修改文件)

  1、 在c:/admin中产生一个名为applet.policy的文件,其内容如下:
  keystore "file:c: /admin/pepper.store", "JKS";
  grant signedBy "pepper"
  { permission java.io.FilePermission "<<ALL FILES>>", "read";=;
  这个文件让由pepper签名的Applet拥有本地所有文件的读权限。

  2、 修改${java.home}/jre/lib/security目录下的java.security,找到下面这两行:
  policy.url.1=file:${java.home}/lib/security/java.policy
  policy.url.2=file:${user.home}/.java.policy

  在下面添写第三行
  policy.url.3=file:c: /admin/applet.policy
  完成这个修改后我们在前面创建的applet.policy文件才有效。
步骤五:(转换html文件)
  运行前面提到的HTMLConvert工具,将原有的FileReaderApplet.html转化成下面的形式:
<!--"CONVERTED_APPLET"-->
<!-- CONVERTER VERSION 1.3 -->
<OBJECT classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
WIDTH = 400 HEIGHT = 300 NAME = "TestApplet" ALIGN = middle VSPACE = 0 HSPACE = 0 codebase="http://java.sun.com/products/plugin/1.3/jinstall-13- win32.cab#Version=1,3,0,0">
<PARAM NAME = CODE VALUE = "jcomponent.FileReaderApplet.class" >
<PARAM NAME = CODEBASE VALUE = "." >
<PARAM NAME = ARCHIVE VALUE = "MyApplet.jar" >
<PARAM NAME = NAME VALUE = "TestApplet" >

<PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
<PARAM NAME="scriptable" VALUE="false">
<COMMENT>
<EMBED type="application/x-java-applet;version=1.3" CODE = "jcomponent.FileReaderApplet.class" CODEBASE = "." ARCHIVE = "MyApplet.jar" NAME = "TestApplet" WIDTH = 400 HEIGHT = 300 ALIGN = middle VSPACE = 0 HSPACE = 0 scriptable=false pluginspage="http://java.sun.com/products/plugin/1.3/plugin- install.html"><NOEMBED></COMMENT>

</NOEMBED></EMBED>
</OBJECT>
<!--
<APPLET CODE = "jcomponent.FileReaderApplet.class" CODEBASE = "." ARCHIVE = "MyApplet.jar" WIDTH = 400 HEIGHT = 300 NAME = "TestApplet" ALIGN = middle VSPACE = 0 HSPACE = 0>

</APPLET>
-->
<!--"END_CONVERTED_APPLET"-->

  大家不要看到这里的写法很复杂,但是这些都是由HTMLConvert工具自动实现的。这个工具有命令行和图形界面两种运行方式。

   好了,现在这个Applet可以运行读写文件的功能了。如果你要考虑在Internet上实现这个Applet,那么你也不需要在所有的客户端均做上面 的步骤,你只需要在你的服务器上创建一个目录,例如c:/admin,将这个目录映射为www.testApplet.com/admin。这里的 www.testApplet.com是一个假定的网址,将pepper.cert、pepper.store、 FileReaderApplet.html、MyApplet.jar以及applet.policy放在这个目录中,然后修改 applet.policy文件如下:
  keystore "http:// www.testApplet.com/admin/pepper.store",
  "JKS";grant signedBy "pepper"{ permission java.io.FilePermission "<<ALL FILES>>", "read";};

  3、 而每个客户端仅仅需要修改一下它们的${java.home}/jre/lib/security目录下的java.security文件如下:
  policy.url.1=file:${java.home}/lib/security/java.policypolicy.url.2=
file:${user.home}/.java.policypolicy.url.3= http:// www.testApplet.com/admin/applet.policy

  当然每个客户端还是需要安装JRE的。
如果是tomcat做域名绑定就需要在tomcat\conf\server.xml文件中做映射
<context path=”” docBase=”映射的目录” debug=”1” reloadable=”true”></context>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值