Class PolicyEditor

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
net.adoptopenjdk.icedteaweb.client.policyeditor.PolicyEditor
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class PolicyEditor extends JPanel
This class provides a policy editing tool as a simpler alternate to the JDK PolicyTool.
See Also:
  • Field Details

    • LOG

      private static final Logger LOG
    • closed

      private boolean closed
    • checkboxMap

      private final Map<PolicyEditorPermissions, JCheckBox> checkboxMap
    • groupBoxList

      private final List<PolicyEditor.JCheckBoxWithGroup> groupBoxList
    • scrollPane

      private final JScrollPane scrollPane
    • listModel

      private final DefaultListModel<PolicyIdentifier> listModel
    • list

      private final JList<PolicyIdentifier> list
    • okButton

      private final JButton okButton
    • closeButton

      private final JButton closeButton
    • addEntryButton

      private final JButton addEntryButton
    • removeEntryButton

      private final JButton removeEntryButton
    • fileChooser

      private final JFileChooser fileChooser
    • cpViewer

      private CustomPolicyViewer cpViewer
    • parentPolicyEditor

      private final 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.
    • policyEditorController

      public final PolicyEditorController policyEditorController
    • okButtonAction

      private final ActionListener okButtonAction
    • addEntryButtonAction

      private final ActionListener addEntryButtonAction
    • removeEntryButtonAction

      private final ActionListener removeEntryButtonAction
    • newButtonAction

      private final ActionListener newButtonAction
    • openButtonAction

      private final ActionListener openButtonAction
    • openDefaultButtonAction

      private final ActionListener openDefaultButtonAction
    • saveAsButtonAction

      private final ActionListener saveAsButtonAction
    • viewCustomButtonAction

      private final ActionListener viewCustomButtonAction
    • modifyCodebaseButtonAction

      private final ActionListener modifyCodebaseButtonAction
    • modifyPrincipalsButtonAction

      private final ActionListener modifyPrincipalsButtonAction
    • modifySignedByButtonAction

      private final ActionListener modifySignedByButtonAction
    • copyEntryButtonAction

      private final ActionListener copyEntryButtonAction
    • pasteEntryButtonAction

      private final ActionListener pasteEntryButtonAction
    • policyEditorHelpButtonAction

      private final ActionListener policyEditorHelpButtonAction
    • aboutPolicyEditorButtonAction

      private final ActionListener aboutPolicyEditorButtonAction
    • aboutItwButtonAction

      private final ActionListener aboutItwButtonAction
    • closeButtonAction

      private final ActionListener closeButtonAction
  • Constructor Details

    • PolicyEditor

      public PolicyEditor(String filepath)
  • Method Details

    • getDefaultPolicyFilePath

      private static 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(String filepath)
    • setParentWindowTitle

      private void setParentWindowTitle(String title)
    • getWindowTitleForStatus

      private String getWindowTitleForStatus()
    • getSelectedPolicyIdentifier

      private PolicyIdentifier getSelectedPolicyIdentifier()
    • preparePolicyEditorWindow

      private static void preparePolicyEditorWindow(PolicyEditor.PolicyEditorWindow w, PolicyEditor e)
    • setupPolicyEditorWindow

      private static void setupPolicyEditorWindow(Window window, PolicyEditor editor)
    • policyEditorWindowQuit

      private static void policyEditorWindowQuit(Window window)
    • getPolicyEditorFrame

      public static PolicyEditor.PolicyEditorWindow getPolicyEditorFrame(String filepath)
    • getPolicyEditorDialog

      public static PolicyEditor.PolicyEditorWindow getPolicyEditorDialog(String filepath)
    • 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(String codebase)
    • validateCodebase

      private static boolean validateCodebase(String codebase)
    • getFile

      public 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.
    • promptForPolicyIdentifier

      private PolicyIdentifier promptForPolicyIdentifier(PolicyIdentifier initialValues)
    • 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, String newCodebase)
    • modifyPrincipals

      public void modifyPrincipals(PolicyIdentifier identifier, List<PolicyParser.PrincipalEntry> principalEntries)
    • modifySignedBy

      public void modifySignedBy(PolicyIdentifier identifier, String newSignedBy)
    • replaceIdentifier

      private void replaceIdentifier(PolicyIdentifier oldIdentifier, PolicyIdentifier newIdentifier)
    • copyEntry

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

      Paste a grant entry from the system clipboard with a new identifier
      Throws:
      UnsupportedFlavorException
      PolicyParser.ParsingException
      IOException
    • getCodebases

      Set<String> getCodebases()
    • isCodeBaseIdentifier

      static boolean isCodeBaseIdentifier(PolicyIdentifier identifier)
    • setPermission

      public void setPermission(PolicyIdentifier identifier, PolicyEditorPermissions permission, boolean state)
    • getPermissions

      public Map<PolicyEditorPermissions, Boolean> getPermissions(PolicyIdentifier identifier)
    • addCustomPermission

      public void addCustomPermission(PolicyIdentifier identifier, PolicyParser.PermissionEntry permission)
    • getCustomPermissions

      public Collection<PolicyParser.PermissionEntry> getCustomPermissions(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(AbstractButton button, 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(JMenuItem menuItem, String accelerator)
    • createMenuBar

      private static 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(JPanel groupPanel)
    • main

      public static void main(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)
    • getCodebaseArgument

      static String getCodebaseArgument(CommandLineOptionsParser optionParser)
    • getSignedByArgument

      static String getSignedByArgument(CommandLineOptionsParser optionParser)
    • getPrincipalsArgument

      static Set<PolicyParser.PrincipalEntry> getPrincipalsArgument(CommandLineOptionsParser optionParser)
    • getFilePathArgument

      static String getFilePathArgument(CommandLineOptionsParser optionParser)
    • cleanFilePathArgument

      private static String cleanFilePathArgument(String filepath)
    • createInstance

      public static PolicyEditor createInstance(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