Class PolicyEditor

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class PolicyEditor
    extends javax.swing.JPanel
    This class provides a policy editing tool as a simpler alternate to the JDK PolicyTool.
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  PolicyEditor.JCheckBoxWithGroup  
      private static class  PolicyEditor.PolicyEditorDialog  
      private static class  PolicyEditor.PolicyEditorFrame  
      static interface  PolicyEditor.PolicyEditorWindow  
      private static class  PolicyEditor.PrincipalsPanel  
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      PolicyEditor​(java.lang.String filepath)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addCustomPermission​(PolicyIdentifier identifier, PolicyParser.PermissionEntry permission)  
      private void addDefaultAllAppletsIdentifier()  
      void addNewEntry​(PolicyIdentifier identifier)
      Add a new identifier to the editor's model.
      void addNewIdentifierInteractive()
      Display an input dialog, which will disappear when the user enters a valid entry or when the user presses cancel.
      private int checkPolicyChangesWithDialog()
      Detect if the policy settings have changed, either on-disk or in-app.
      private static java.lang.String cleanFilePathArgument​(java.lang.String filepath)  
      void clearCustomPermissions​(PolicyIdentifier identifier)  
      void copyEntry​(PolicyIdentifier identifier)
      Copy an entry to the system clipboard
      static PolicyEditor createInstance​(java.lang.String filepath)
      Create a new PolicyEditor instance without passing argv.
      private static javax.swing.JMenuBar createMenuBar​(PolicyEditor editor)  
      (package private) void customPolicyViewerClosing()
      Called by the Custom Policy Viewer on its parent Policy Editor when the Custom Policy Viewer is closing
      (package private) static java.lang.String getCodebaseArgument​(CommandLineOptionsParser optionParser)  
      (package private) java.util.Set<java.lang.String> getCodebases()  
      java.util.Collection<PolicyParser.PermissionEntry> getCustomPermissions​(PolicyIdentifier identifier)  
      private static java.lang.String getDefaultPolicyFilePath()  
      java.io.File getFile()  
      (package private) static java.lang.String getFilePathArgument​(CommandLineOptionsParser optionParser)  
      private boolean getModality()  
      java.util.Map<PolicyEditorPermissions,​java.lang.Boolean> getPermissions​(PolicyIdentifier identifier)  
      static PolicyEditor.PolicyEditorWindow getPolicyEditorDialog​(java.lang.String filepath)  
      static PolicyEditor.PolicyEditorWindow getPolicyEditorFrame​(java.lang.String filepath)  
      (package private) static java.util.Set<PolicyParser.PrincipalEntry> getPrincipalsArgument​(CommandLineOptionsParser optionParser)  
      private PolicyIdentifier getSelectedPolicyIdentifier()  
      (package private) static java.lang.String getSignedByArgument​(CommandLineOptionsParser optionParser)  
      private java.lang.String getWindowTitleForStatus()  
      (package private) static PolicyIdentifier identifierFromCodebase​(java.lang.String codebase)  
      boolean isClosed()
      Check if the PolicyEditor instance has been visually closed
      (package private) static boolean isCodeBaseIdentifier​(PolicyIdentifier identifier)  
      boolean isPerformingIO()  
      static void main​(java.lang.String[] args)
      Start a Policy Editor instance.
      void modifyCodebase​(PolicyIdentifier identifier, java.lang.String newCodebase)  
      void modifyPrincipals​(PolicyIdentifier identifier, java.util.List<PolicyParser.PrincipalEntry> principalEntries)  
      void modifySignedBy​(PolicyIdentifier identifier, java.lang.String newSignedBy)  
      void openAndParsePolicyFile()  
      void openPolicyFileSynchronously()  
      void pasteEntry​(PolicyIdentifier identifier)
      Paste a grant entry from the system clipboard with a new identifier
      private static void policyEditorWindowQuit​(java.awt.Window window)  
      private static void preparePolicyEditorWindow​(PolicyEditor.PolicyEditorWindow w, PolicyEditor e)  
      private PolicyIdentifier promptForPolicyIdentifier​(PolicyIdentifier initialValues)  
      private boolean promptOnSaveChangesMade​(boolean async)  
      void removeIdentifier​(PolicyIdentifier identifier)
      Remove an identifier from the editor's model
      private void replaceIdentifier​(PolicyIdentifier oldIdentifier, PolicyIdentifier newIdentifier)  
      private void resetEntries()  
      private void savePolicyFile()
      Save the policy model into the file pointed to by the filePath field.
      private static void setButtonMnemonic​(javax.swing.AbstractButton button, java.lang.String mnemonic)
      Set a mnemonic key for a menu item or button
      (package private) void setChangesMade​(boolean b)  
      private void setClosed()  
      void setFile​(java.lang.String filepath)  
      private static void setMenuItemAccelerator​(javax.swing.JMenuItem menuItem, java.lang.String accelerator)  
      private void setParentWindowTitle​(java.lang.String title)  
      void setPermission​(PolicyIdentifier identifier, PolicyEditorPermissions permission, boolean state)  
      private void setupLayout()
      Lay out all controls, tooltips, etc.
      private static void setupPolicyEditorWindow​(java.awt.Window window, PolicyEditor editor)  
      private void showChangesSavedDialog()
      Show a dialog informing the user that their changes have been saved.
      private void showClipboardErrorDialog()  
      private void showCouldNotAccessClipboardDialog()  
      private void showCouldNotSaveDialog()
      Show a dialog informing the user that their changes could not be saved.
      private void showInvalidPolicyExceptionDialog​(PolicyIdentifier identifier)  
      private void toggleExpandedCheckboxGroupPanel​(javax.swing.JPanel groupPanel)  
      private void updateCheckboxes​(PolicyIdentifier identifier)
      Update the checkboxes to show the permissions granted to the specified identifier
      private void updateCheckboxesImpl​(PolicyIdentifier identifier)  
      private static boolean validateCodebase​(java.lang.String codebase)  
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
      • Methods inherited from class java.awt.Component

        action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • LOG

        private static final Logger LOG
      • closed

        private boolean closed
      • scrollPane

        private final javax.swing.JScrollPane scrollPane
      • listModel

        private final javax.swing.DefaultListModel<PolicyIdentifier> listModel
      • okButton

        private final javax.swing.JButton okButton
      • closeButton

        private final javax.swing.JButton closeButton
      • addEntryButton

        private final javax.swing.JButton addEntryButton
      • removeEntryButton

        private final javax.swing.JButton removeEntryButton
      • fileChooser

        private final javax.swing.JFileChooser fileChooser
      • parentPolicyEditor

        private final java.lang.ref.WeakReference<PolicyEditor> parentPolicyEditor
        See showChangesSavedDialog/showCouldNotSaveDialog. This weak reference is needed because there is a modal child dialog which can sometimes appear after the editor has been closed and disposed. In this case, its parent should be set to 'null', but otherwise the parent should be the editor so that the dialog is modal.
      • okButtonAction

        private final java.awt.event.ActionListener okButtonAction
      • addEntryButtonAction

        private final java.awt.event.ActionListener addEntryButtonAction
      • removeEntryButtonAction

        private final java.awt.event.ActionListener removeEntryButtonAction
      • newButtonAction

        private final java.awt.event.ActionListener newButtonAction
      • openButtonAction

        private final java.awt.event.ActionListener openButtonAction
      • openDefaultButtonAction

        private final java.awt.event.ActionListener openDefaultButtonAction
      • saveAsButtonAction

        private final java.awt.event.ActionListener saveAsButtonAction
      • viewCustomButtonAction

        private final java.awt.event.ActionListener viewCustomButtonAction
      • modifyCodebaseButtonAction

        private final java.awt.event.ActionListener modifyCodebaseButtonAction
      • modifyPrincipalsButtonAction

        private final java.awt.event.ActionListener modifyPrincipalsButtonAction
      • modifySignedByButtonAction

        private final java.awt.event.ActionListener modifySignedByButtonAction
      • copyEntryButtonAction

        private final java.awt.event.ActionListener copyEntryButtonAction
      • pasteEntryButtonAction

        private final java.awt.event.ActionListener pasteEntryButtonAction
      • policyEditorHelpButtonAction

        private final java.awt.event.ActionListener policyEditorHelpButtonAction
      • aboutPolicyEditorButtonAction

        private final java.awt.event.ActionListener aboutPolicyEditorButtonAction
      • aboutItwButtonAction

        private final java.awt.event.ActionListener aboutItwButtonAction
      • closeButtonAction

        private final java.awt.event.ActionListener closeButtonAction
    • Constructor Detail

      • PolicyEditor

        public PolicyEditor​(java.lang.String filepath)
    • Method Detail

      • getDefaultPolicyFilePath

        private static java.lang.String getDefaultPolicyFilePath()
      • addDefaultAllAppletsIdentifier

        private void addDefaultAllAppletsIdentifier()
      • getModality

        private boolean getModality()
      • promptOnSaveChangesMade

        private boolean promptOnSaveChangesMade​(boolean async)
        Parameters:
        async - use asynchronous saving, which displays a progress dialog, or use synchronous, which blocks the EDT but allows for eg the on-disk file to be changed without resorting to a busy-wait loop
        Returns:
        false iff the user wishes to cancel the operation and keep the current editor state
      • setFile

        public void setFile​(java.lang.String filepath)
      • setParentWindowTitle

        private void setParentWindowTitle​(java.lang.String title)
      • getWindowTitleForStatus

        private java.lang.String getWindowTitleForStatus()
      • getSelectedPolicyIdentifier

        private PolicyIdentifier getSelectedPolicyIdentifier()
      • setupPolicyEditorWindow

        private static void setupPolicyEditorWindow​(java.awt.Window window,
                                                    PolicyEditor editor)
      • policyEditorWindowQuit

        private static void policyEditorWindowQuit​(java.awt.Window window)
      • setClosed

        private void setClosed()
      • isClosed

        public boolean isClosed()
        Check if the PolicyEditor instance has been visually closed
        Returns:
        if the PolicyEditor instance has been closed
      • customPolicyViewerClosing

        void customPolicyViewerClosing()
        Called by the Custom Policy Viewer on its parent Policy Editor when the Custom Policy Viewer is closing
      • addNewEntry

        public void addNewEntry​(PolicyIdentifier identifier)
        Add a new identifier to the editor's model.
        Parameters:
        identifier - to be added
      • identifierFromCodebase

        static PolicyIdentifier identifierFromCodebase​(java.lang.String codebase)
      • validateCodebase

        private static boolean validateCodebase​(java.lang.String codebase)
      • getFile

        public java.io.File getFile()
      • addNewIdentifierInteractive

        public void addNewIdentifierInteractive()
        Display an input dialog, which will disappear when the user enters a valid entry or when the user presses cancel.
      • removeIdentifier

        public void removeIdentifier​(PolicyIdentifier identifier)
        Remove an identifier from the editor's model
        Parameters:
        identifier - to be removed
      • modifyCodebase

        public void modifyCodebase​(PolicyIdentifier identifier,
                                   java.lang.String newCodebase)
      • modifySignedBy

        public void modifySignedBy​(PolicyIdentifier identifier,
                                   java.lang.String newSignedBy)
      • copyEntry

        public void copyEntry​(PolicyIdentifier identifier)
        Copy an entry to the system clipboard
        Parameters:
        identifier - the identifier to copy
      • getCodebases

        java.util.Set<java.lang.String> getCodebases()
      • isCodeBaseIdentifier

        static boolean isCodeBaseIdentifier​(PolicyIdentifier identifier)
      • clearCustomPermissions

        public void clearCustomPermissions​(PolicyIdentifier identifier)
      • updateCheckboxes

        private void updateCheckboxes​(PolicyIdentifier identifier)
        Update the checkboxes to show the permissions granted to the specified identifier
        Parameters:
        identifier - whose permissions to display
      • updateCheckboxesImpl

        private void updateCheckboxesImpl​(PolicyIdentifier identifier)
      • setButtonMnemonic

        private static void setButtonMnemonic​(javax.swing.AbstractButton button,
                                              java.lang.String mnemonic)
        Set a mnemonic key for a menu item or button
        Parameters:
        button - the component for which to set a mnemonic
        mnemonic - the mnemonic to set
      • setMenuItemAccelerator

        private static void setMenuItemAccelerator​(javax.swing.JMenuItem menuItem,
                                                   java.lang.String accelerator)
      • createMenuBar

        private static javax.swing.JMenuBar createMenuBar​(PolicyEditor editor)
      • setupLayout

        private void setupLayout()
        Lay out all controls, tooltips, etc.
      • setChangesMade

        void setChangesMade​(boolean b)
      • resetEntries

        private void resetEntries()
      • isPerformingIO

        public boolean isPerformingIO()
        Returns:
        whether this PolicyEditor is currently opening or saving a policy file to disk
      • openPolicyFileSynchronously

        public void openPolicyFileSynchronously()
      • openAndParsePolicyFile

        public void openAndParsePolicyFile()
      • savePolicyFile

        private void savePolicyFile()
        Save the policy model into the file pointed to by the filePath field.
      • showChangesSavedDialog

        private void showChangesSavedDialog()
        Show a dialog informing the user that their changes have been saved.
      • showCouldNotSaveDialog

        private void showCouldNotSaveDialog()
        Show a dialog informing the user that their changes could not be saved.
      • showClipboardErrorDialog

        private void showClipboardErrorDialog()
      • showInvalidPolicyExceptionDialog

        private void showInvalidPolicyExceptionDialog​(PolicyIdentifier identifier)
      • showCouldNotAccessClipboardDialog

        private void showCouldNotAccessClipboardDialog()
      • checkPolicyChangesWithDialog

        private int checkPolicyChangesWithDialog()
        Detect if the policy settings have changed, either on-disk or in-app. If an on-disk change has occurred, update the Md5.
        Returns:
        The user's choice (Yes/No/Cancel - see JOptionPane constants). "Cancel" if the file hasn't changed but the user has made modifications to the settings. "No" otherwise
      • toggleExpandedCheckboxGroupPanel

        private void toggleExpandedCheckboxGroupPanel​(javax.swing.JPanel groupPanel)
      • main

        public static void main​(java.lang.String[] args)
        Start a Policy Editor instance.
        Parameters:
        args - "-file $FILENAME" and/or "-codebase $CODEBASE" are accepted flag/value pairs. -file specifies a file path to be opened by the editor. If none is provided, the default policy file location for the user is opened. -help will print a help message and immediately return (no editor instance opens)
      • cleanFilePathArgument

        private static java.lang.String cleanFilePathArgument​(java.lang.String filepath)
      • createInstance

        public static PolicyEditor createInstance​(java.lang.String filepath)
        Create a new PolicyEditor instance without passing argv. The returned instance is not yet set visible.
        Parameters:
        filepath - a policy file to open at start, or null if no file to load
        Returns:
        a reference to a new PolicyEditor instance