繁体   English   中英

已签名的Jar&doPrivileged无法解决访问控制异常

[英]Signed Jar & doPrivileged doesn't solve access control exception

我试图调用文件选择器选项并获取文件名作为输入。 但是我正在获取java AccessControlException 当我使用Web浏览器启动applet时,这很好用,但是当尝试使用applet viewer时抛出异常。

我尝试了以下

  1. 使用keytool和jarsigner JDK1.6.24签署了JAR
  2. 使用AccessController.doPrivileged

但是我仍然遇到如下相同的异常。

    Exception in thread "AWT-EventQueue-1" java.security.AccessControlException: acc
ess denied (java.util.PropertyPermission user.dir read)
        at java.security.AccessControlContext.checkPermission(AccessControlConte
xt.java:374)
        at java.security.AccessController.checkPermission(AccessController.java:
546)
        at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
        at java.lang.SecurityManager.checkPropertyAccess(SecurityManager.java:12
85)
        at java.lang.System.getProperty(System.java:650)
        at java.io.Win32FileSystem.getUserPath(Win32FileSystem.java:296)
        at java.io.Win32FileSystem.resolve(Win32FileSystem.java:312)
        at java.io.File.getAbsolutePath(File.java:501)
        at javax.swing.filechooser.WindowsFileSystemView.isFloppyDrive(FileSyste
mView.java:734)
        at javax.swing.plaf.basic.BasicFileChooserUI$BasicFileView.getIcon(Basic
FileChooserUI.java:1200)
        at javax.swing.JFileChooser.getIcon(JFileChooser.java:1538)
        at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxRenderer.g
etListCellRendererComponent(MetalFileChooserUI.java:854)
        at javax.swing.plaf.basic.BasicListUI.updateLayoutState(BasicListUI.java
:1344)
        at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState(BasicListUI
.java:1294)
        at javax.swing.plaf.basic.BasicListUI$Handler.valueChanged(BasicListUI.j
ava:2611)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSel
ectionModel.java:167)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSel
ectionModel.java:147)
        at javax.swing.DefaultListSelectionModel.fireValueChanged(DefaultListSel
ectionModel.java:194)
        at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSele
ctionModel.java:388)
        at javax.swing.DefaultListSelectionModel.changeSelection(DefaultListSele
ctionModel.java:398)
        at javax.swing.DefaultListSelectionModel.setSelectionInterval(DefaultLis
tSelectionModel.java:442)
        at javax.swing.JList.setSelectedIndex(JList.java:2179)
        at javax.swing.plaf.basic.BasicComboPopup.setListSelection(BasicComboPop
up.java:1126)
        at javax.swing.plaf.basic.BasicComboPopup.access$300(BasicComboPopup.jav
a:46)
        at javax.swing.plaf.basic.BasicComboPopup$Handler.itemStateChanged(Basic
ComboPopup.java:964)
        at javax.swing.JComboBox.fireItemStateChanged(JComboBox.java:1205)
        at javax.swing.JComboBox.selectedItemChanged(JComboBox.java:1262)
        at javax.swing.JComboBox.contentsChanged(JComboBox.java:1309)
        at javax.swing.AbstractListModel.fireContentsChanged(AbstractListModel.j
ava:100)
        at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.setS
electedItem(MetalFileChooserUI.java:1001)
        at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.addI
tem(MetalFileChooserUI.java:972)
        at javax.swing.plaf.metal.MetalFileChooserUI$DirectoryComboBoxModel.acce
ss$900(MetalFileChooserUI.java:897)
        at javax.swing.plaf.metal.MetalFileChooserUI.doDirectoryChanged(MetalFil
eChooserUI.java:648)
        at javax.swing.plaf.metal.MetalFileChooserUI.access$1200(MetalFileChoose
rUI.java:38)
        at javax.swing.plaf.metal.MetalFileChooserUI$5.propertyChange(MetalFileC
hooserUI.java:734)
        at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
port.java:339)
        at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSup
port.java:276)
        at java.awt.Component.firePropertyChange(Component.java:8154)
        at javax.swing.JFileChooser.setCurrentDirectory(JFileChooser.java:568)
        at javax.swing.JFileChooser.<init>(JFileChooser.java:334)
        at javax.swing.JFileChooser.<init>(JFileChooser.java:286)
        at StegnoMainFrame.selectFileAction(StegnoMainFrame.java:596)
        at StegnoMainFrame.access$800(StegnoMainFrame.java:48)
        at StegnoMainFrame$4.actionPerformed(StegnoMainFrame.java:201)
        at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:19
95)
        at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.jav
a:2318)
        at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel
.java:387)
        at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242
)
        at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonL
istener.java:236)
        at java.awt.Component.processMouseEvent(Component.java:6289)
        at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
        at java.awt.Component.processEvent(Component.java:6054)
        at java.awt.Container.processEvent(Container.java:2041)
        at java.awt.Component.dispatchEventImpl(Component.java:4652)
        at java.awt.Container.dispatchEventImpl(Container.java:2099)
        at java.awt.Component.dispatchEvent(Component.java:4482)
        at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4577
)
        at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4238)

        at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4168)
        at java.awt.Container.dispatchEventImpl(Container.java:2085)
        at java.awt.Component.dispatchEvent(Component.java:4482)
        at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:644)
        at java.awt.EventQueue.access$000(EventQueue.java:85)
        at java.awt.EventQueue$1.run(EventQueue.java:603)
        at java.awt.EventQueue$1.run(EventQueue.java:601)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessCo
ntrolContext.java:87)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessCo
ntrolContext.java:98)
        at java.awt.EventQueue$2.run(EventQueue.java:617)
        at java.awt.EventQueue$2.run(EventQueue.java:615)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessCo
ntrolContext.java:87)
        at java.awt.EventQueue.dispatchEvent(EventQueue.java:614)
        at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThre
ad.java:269)
        at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.
java:184)
        at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
ad.java:174)
        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169)

        at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161)

        at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

请在使用doPrivileged地方找到我的代码部分。

private boolean selectFileAction(final String titleTextIn, final JTextField fileLocIn, final boolean allowFileFilter, 
        final boolean setOutFile)
{
    String isOkSelected = "false";
    final JFileChooser chooser = new JFileChooser();
    isOkSelected = (String) AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
            if (allowFileFilter)
            {
                FileNameExtensionFilter filter = new FileNameExtensionFilter("GIF Images", "gif");
                chooser.setFileFilter(filter);
            }
            if (setOutFile)
            {
                if (hideRadiButton.isSelected())
                {
                    if (titleTextIn.contains("Key"))
                        chooser.setSelectedFile(new File("enckey"));
                    else
                        chooser.setSelectedFile(new File("output.gif"));
                }
                else
                    chooser.setSelectedFile(new File("output.txt"));
            }
            chooser.setDialogTitle(titleTextIn);
            int returnVal = chooser.showOpenDialog(getContentPane());
            boolean tempSelected = false;
            if(returnVal == JFileChooser.APPROVE_OPTION) {
                tempSelected = true;
                fileLocIn.setText(chooser.getSelectedFile().getAbsolutePath());
            }
            System.loadLibrary("awt");
            return tempSelected;
        }
    });


    return Boolean.parseBoolean(isOkSelected);
}

当我使用网络浏览器启动小程序时,此方法工作正常

这样就没有(真正的)问题了。

..但是尝试与appletviewer一起抛出异常。

即使代码已签名并且您选择菜单选项来信任它,SDK所配置的小程序查看器的最新版本也会被沙盒化 从IDE启动的Applet Viewer通常具有具有所有权限的安全策略(即使未签名)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM