jdk/src/jdk.dev/share/classes/sun/security/tools/policytool/PolicyTool.java
changeset 29455 e451c01a5747
parent 29454 e5e9478e2ddb
parent 29433 c97e2d1bad97
child 29478 6637277d28cc
equal deleted inserted replaced
29454:e5e9478e2ddb 29455:e451c01a5747
     1 /*
       
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.  Oracle designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Oracle in the LICENSE file that accompanied this code.
       
    10  *
       
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14  * version 2 for more details (a copy is included in the LICENSE file that
       
    15  * accompanied this code).
       
    16  *
       
    17  * You should have received a copy of the GNU General Public License version
       
    18  * 2 along with this work; if not, write to the Free Software Foundation,
       
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20  *
       
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22  * or visit www.oracle.com if you need additional information or have any
       
    23  * questions.
       
    24  */
       
    25 
       
    26 package sun.security.tools.policytool;
       
    27 
       
    28 import java.io.*;
       
    29 import java.util.LinkedList;
       
    30 import java.util.ListIterator;
       
    31 import java.util.Vector;
       
    32 import java.util.Enumeration;
       
    33 import java.net.URL;
       
    34 import java.net.MalformedURLException;
       
    35 import java.lang.reflect.*;
       
    36 import java.text.Collator;
       
    37 import java.text.MessageFormat;
       
    38 import sun.security.util.PropertyExpander;
       
    39 import sun.security.util.PropertyExpander.ExpandException;
       
    40 import java.awt.Component;
       
    41 import java.awt.Container;
       
    42 import java.awt.Dimension;
       
    43 import java.awt.FileDialog;
       
    44 import java.awt.GridBagConstraints;
       
    45 import java.awt.GridBagLayout;
       
    46 import java.awt.Insets;
       
    47 import java.awt.Point;
       
    48 import java.awt.Toolkit;
       
    49 import java.awt.Window;
       
    50 import java.awt.event.*;
       
    51 import java.security.cert.Certificate;
       
    52 import java.security.cert.CertificateException;
       
    53 import java.security.*;
       
    54 import sun.security.provider.*;
       
    55 import sun.security.util.PolicyUtil;
       
    56 import javax.security.auth.x500.X500Principal;
       
    57 import javax.swing.*;
       
    58 import javax.swing.border.EmptyBorder;
       
    59 
       
    60 /**
       
    61  * PolicyTool may be used by users and administrators to configure the
       
    62  * overall java security policy (currently stored in the policy file).
       
    63  * Using PolicyTool administrators may add and remove policies from
       
    64  * the policy file. <p>
       
    65  *
       
    66  * @see java.security.Policy
       
    67  * @since   1.2
       
    68  */
       
    69 
       
    70 public class PolicyTool {
       
    71 
       
    72     // for i18n
       
    73     static final java.util.ResourceBundle rb =
       
    74         java.util.ResourceBundle.getBundle(
       
    75             "sun.security.tools.policytool.Resources");
       
    76     static final Collator collator = Collator.getInstance();
       
    77     static {
       
    78         // this is for case insensitive string comparisons
       
    79         collator.setStrength(Collator.PRIMARY);
       
    80 
       
    81         // Support for Apple menu bar
       
    82         if (System.getProperty("apple.laf.useScreenMenuBar") == null) {
       
    83             System.setProperty("apple.laf.useScreenMenuBar", "true");
       
    84         }
       
    85         System.setProperty("apple.awt.application.name", getMessage("Policy.Tool"));
       
    86 
       
    87         // Apply the system L&F if not specified with a system property.
       
    88         if (System.getProperty("swing.defaultlaf") == null) {
       
    89             try {
       
    90                 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
       
    91             } catch (Exception e) {
       
    92                 // ignore
       
    93             }
       
    94         }
       
    95     }
       
    96 
       
    97     // anyone can add warnings
       
    98     Vector<String> warnings;
       
    99     boolean newWarning = false;
       
   100 
       
   101     // set to true if policy modified.
       
   102     // this way upon exit we know if to ask the user to save changes
       
   103     boolean modified = false;
       
   104 
       
   105     private static final boolean testing = false;
       
   106     private static final Class<?>[] TWOPARAMS = { String.class, String.class };
       
   107     private static final Class<?>[] ONEPARAMS = { String.class };
       
   108     private static final Class<?>[] NOPARAMS  = {};
       
   109     /*
       
   110      * All of the policy entries are read in from the
       
   111      * policy file and stored here.  Updates to the policy entries
       
   112      * using addEntry() and removeEntry() are made here.  To ultimately save
       
   113      * the policy entries back to the policy file, the SavePolicy button
       
   114      * must be clicked.
       
   115      **/
       
   116     private static String policyFileName = null;
       
   117     private Vector<PolicyEntry> policyEntries = null;
       
   118     private PolicyParser parser = null;
       
   119 
       
   120     /* The public key alias information is stored here.  */
       
   121     private KeyStore keyStore = null;
       
   122     private String keyStoreName = " ";
       
   123     private String keyStoreType = " ";
       
   124     private String keyStoreProvider = " ";
       
   125     private String keyStorePwdURL = " ";
       
   126 
       
   127     /* standard PKCS11 KeyStore type */
       
   128     private static final String P11KEYSTORE = "PKCS11";
       
   129 
       
   130     /* reserved word for PKCS11 KeyStores */
       
   131     private static final String NONE = "NONE";
       
   132 
       
   133     /**
       
   134      * default constructor
       
   135      */
       
   136     private PolicyTool() {
       
   137         policyEntries = new Vector<PolicyEntry>();
       
   138         parser = new PolicyParser();
       
   139         warnings = new Vector<String>();
       
   140     }
       
   141 
       
   142     /**
       
   143      * get the PolicyFileName
       
   144      */
       
   145     String getPolicyFileName() {
       
   146         return policyFileName;
       
   147     }
       
   148 
       
   149     /**
       
   150      * set the PolicyFileName
       
   151      */
       
   152     void setPolicyFileName(String policyFileName) {
       
   153         PolicyTool.policyFileName = policyFileName;
       
   154     }
       
   155 
       
   156    /**
       
   157     * clear keyStore info
       
   158     */
       
   159     void clearKeyStoreInfo() {
       
   160         this.keyStoreName = null;
       
   161         this.keyStoreType = null;
       
   162         this.keyStoreProvider = null;
       
   163         this.keyStorePwdURL = null;
       
   164 
       
   165         this.keyStore = null;
       
   166     }
       
   167 
       
   168     /**
       
   169      * get the keyStore URL name
       
   170      */
       
   171     String getKeyStoreName() {
       
   172         return keyStoreName;
       
   173     }
       
   174 
       
   175     /**
       
   176      * get the keyStore Type
       
   177      */
       
   178     String getKeyStoreType() {
       
   179         return keyStoreType;
       
   180     }
       
   181 
       
   182     /**
       
   183      * get the keyStore Provider
       
   184      */
       
   185     String getKeyStoreProvider() {
       
   186         return keyStoreProvider;
       
   187     }
       
   188 
       
   189     /**
       
   190      * get the keyStore password URL
       
   191      */
       
   192     String getKeyStorePwdURL() {
       
   193         return keyStorePwdURL;
       
   194     }
       
   195 
       
   196     /**
       
   197      * Open and read a policy file
       
   198      */
       
   199     void openPolicy(String filename) throws FileNotFoundException,
       
   200                                         PolicyParser.ParsingException,
       
   201                                         KeyStoreException,
       
   202                                         CertificateException,
       
   203                                         InstantiationException,
       
   204                                         MalformedURLException,
       
   205                                         IOException,
       
   206                                         NoSuchAlgorithmException,
       
   207                                         IllegalAccessException,
       
   208                                         NoSuchMethodException,
       
   209                                         UnrecoverableKeyException,
       
   210                                         NoSuchProviderException,
       
   211                                         ClassNotFoundException,
       
   212                                         PropertyExpander.ExpandException,
       
   213                                         InvocationTargetException {
       
   214 
       
   215         newWarning = false;
       
   216 
       
   217         // start fresh - blow away the current state
       
   218         policyEntries = new Vector<PolicyEntry>();
       
   219         parser = new PolicyParser();
       
   220         warnings = new Vector<String>();
       
   221         setPolicyFileName(null);
       
   222         clearKeyStoreInfo();
       
   223 
       
   224         // see if user is opening a NEW policy file
       
   225         if (filename == null) {
       
   226             modified = false;
       
   227             return;
       
   228         }
       
   229 
       
   230         // Read in the policy entries from the file and
       
   231         // populate the parser vector table.  The parser vector
       
   232         // table only holds the entries as strings, so it only
       
   233         // guarantees that the policies are syntactically
       
   234         // correct.
       
   235         setPolicyFileName(filename);
       
   236         parser.read(new FileReader(filename));
       
   237 
       
   238         // open the keystore
       
   239         openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(),
       
   240                 parser.getKeyStoreProvider(), parser.getStorePassURL());
       
   241 
       
   242         // Update the local vector with the same policy entries.
       
   243         // This guarantees that the policy entries are not only
       
   244         // syntactically correct, but semantically valid as well.
       
   245         Enumeration<PolicyParser.GrantEntry> enum_ = parser.grantElements();
       
   246         while (enum_.hasMoreElements()) {
       
   247             PolicyParser.GrantEntry ge = enum_.nextElement();
       
   248 
       
   249             // see if all the signers have public keys
       
   250             if (ge.signedBy != null) {
       
   251 
       
   252                 String signers[] = parseSigners(ge.signedBy);
       
   253                 for (int i = 0; i < signers.length; i++) {
       
   254                     PublicKey pubKey = getPublicKeyAlias(signers[i]);
       
   255                     if (pubKey == null) {
       
   256                         newWarning = true;
       
   257                         MessageFormat form = new MessageFormat(getMessage
       
   258                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
       
   259                         Object[] source = {signers[i]};
       
   260                         warnings.addElement(form.format(source));
       
   261                     }
       
   262                 }
       
   263             }
       
   264 
       
   265             // check to see if the Principals are valid
       
   266             ListIterator<PolicyParser.PrincipalEntry> prinList =
       
   267                                                 ge.principals.listIterator(0);
       
   268             while (prinList.hasNext()) {
       
   269                 PolicyParser.PrincipalEntry pe = prinList.next();
       
   270                 try {
       
   271                     verifyPrincipal(pe.getPrincipalClass(),
       
   272                                 pe.getPrincipalName());
       
   273                 } catch (ClassNotFoundException fnfe) {
       
   274                     newWarning = true;
       
   275                     MessageFormat form = new MessageFormat(getMessage
       
   276                                 ("Warning.Class.not.found.class"));
       
   277                     Object[] source = {pe.getPrincipalClass()};
       
   278                     warnings.addElement(form.format(source));
       
   279                 }
       
   280             }
       
   281 
       
   282             // check to see if the Permissions are valid
       
   283             Enumeration<PolicyParser.PermissionEntry> perms =
       
   284                                                 ge.permissionElements();
       
   285             while (perms.hasMoreElements()) {
       
   286                 PolicyParser.PermissionEntry pe = perms.nextElement();
       
   287                 try {
       
   288                     verifyPermission(pe.permission, pe.name, pe.action);
       
   289                 } catch (ClassNotFoundException fnfe) {
       
   290                     newWarning = true;
       
   291                     MessageFormat form = new MessageFormat(getMessage
       
   292                                 ("Warning.Class.not.found.class"));
       
   293                     Object[] source = {pe.permission};
       
   294                     warnings.addElement(form.format(source));
       
   295                 } catch (InvocationTargetException ite) {
       
   296                     newWarning = true;
       
   297                     MessageFormat form = new MessageFormat(getMessage
       
   298                         ("Warning.Invalid.argument.s.for.constructor.arg"));
       
   299                     Object[] source = {pe.permission};
       
   300                     warnings.addElement(form.format(source));
       
   301                 }
       
   302 
       
   303                 // see if all the permission signers have public keys
       
   304                 if (pe.signedBy != null) {
       
   305 
       
   306                     String signers[] = parseSigners(pe.signedBy);
       
   307 
       
   308                     for (int i = 0; i < signers.length; i++) {
       
   309                         PublicKey pubKey = getPublicKeyAlias(signers[i]);
       
   310                         if (pubKey == null) {
       
   311                             newWarning = true;
       
   312                             MessageFormat form = new MessageFormat(getMessage
       
   313                                 ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
       
   314                             Object[] source = {signers[i]};
       
   315                             warnings.addElement(form.format(source));
       
   316                         }
       
   317                     }
       
   318                 }
       
   319             }
       
   320             PolicyEntry pEntry = new PolicyEntry(this, ge);
       
   321             policyEntries.addElement(pEntry);
       
   322         }
       
   323 
       
   324         // just read in the policy -- nothing has been modified yet
       
   325         modified = false;
       
   326     }
       
   327 
       
   328 
       
   329     /**
       
   330      * Save a policy to a file
       
   331      */
       
   332     void savePolicy(String filename)
       
   333     throws FileNotFoundException, IOException {
       
   334         // save the policy entries to a file
       
   335         parser.setKeyStoreUrl(keyStoreName);
       
   336         parser.setKeyStoreType(keyStoreType);
       
   337         parser.setKeyStoreProvider(keyStoreProvider);
       
   338         parser.setStorePassURL(keyStorePwdURL);
       
   339         parser.write(new FileWriter(filename));
       
   340         modified = false;
       
   341     }
       
   342 
       
   343     /**
       
   344      * Open the KeyStore
       
   345      */
       
   346     void openKeyStore(String name,
       
   347                 String type,
       
   348                 String provider,
       
   349                 String pwdURL) throws   KeyStoreException,
       
   350                                         NoSuchAlgorithmException,
       
   351                                         UnrecoverableKeyException,
       
   352                                         IOException,
       
   353                                         CertificateException,
       
   354                                         NoSuchProviderException,
       
   355                                         ExpandException {
       
   356 
       
   357         if (name == null && type == null &&
       
   358             provider == null && pwdURL == null) {
       
   359 
       
   360             // policy did not specify a keystore during open
       
   361             // or use wants to reset keystore values
       
   362 
       
   363             this.keyStoreName = null;
       
   364             this.keyStoreType = null;
       
   365             this.keyStoreProvider = null;
       
   366             this.keyStorePwdURL = null;
       
   367 
       
   368             // caller will set (tool.modified = true) if appropriate
       
   369 
       
   370             return;
       
   371         }
       
   372 
       
   373         URL policyURL = null;
       
   374         if (policyFileName != null) {
       
   375             File pfile = new File(policyFileName);
       
   376             policyURL = new URL("file:" + pfile.getCanonicalPath());
       
   377         }
       
   378 
       
   379         // although PolicyUtil.getKeyStore may properly handle
       
   380         // defaults and property expansion, we do it here so that
       
   381         // if the call is successful, we can set the proper values
       
   382         // (PolicyUtil.getKeyStore does not return expanded values)
       
   383 
       
   384         if (name != null && name.length() > 0) {
       
   385             name = PropertyExpander.expand(name).replace
       
   386                                         (File.separatorChar, '/');
       
   387         }
       
   388         if (type == null || type.length() == 0) {
       
   389             type = KeyStore.getDefaultType();
       
   390         }
       
   391         if (pwdURL != null && pwdURL.length() > 0) {
       
   392             pwdURL = PropertyExpander.expand(pwdURL).replace
       
   393                                         (File.separatorChar, '/');
       
   394         }
       
   395 
       
   396         try {
       
   397             this.keyStore = PolicyUtil.getKeyStore(policyURL,
       
   398                                                 name,
       
   399                                                 type,
       
   400                                                 provider,
       
   401                                                 pwdURL,
       
   402                                                 null);
       
   403         } catch (IOException ioe) {
       
   404 
       
   405             // copied from sun.security.pkcs11.SunPKCS11
       
   406             String MSG = "no password provided, and no callback handler " +
       
   407                         "available for retrieving password";
       
   408 
       
   409             Throwable cause = ioe.getCause();
       
   410             if (cause != null &&
       
   411                 cause instanceof javax.security.auth.login.LoginException &&
       
   412                 MSG.equals(cause.getMessage())) {
       
   413 
       
   414                 // throw a more friendly exception message
       
   415                 throw new IOException(MSG);
       
   416             } else {
       
   417                 throw ioe;
       
   418             }
       
   419         }
       
   420 
       
   421         this.keyStoreName = name;
       
   422         this.keyStoreType = type;
       
   423         this.keyStoreProvider = provider;
       
   424         this.keyStorePwdURL = pwdURL;
       
   425 
       
   426         // caller will set (tool.modified = true)
       
   427     }
       
   428 
       
   429     /**
       
   430      * Add a Grant entry to the overall policy at the specified index.
       
   431      * A policy entry consists of a CodeSource.
       
   432      */
       
   433     boolean addEntry(PolicyEntry pe, int index) {
       
   434 
       
   435         if (index < 0) {
       
   436             // new entry -- just add it to the end
       
   437             policyEntries.addElement(pe);
       
   438             parser.add(pe.getGrantEntry());
       
   439         } else {
       
   440             // existing entry -- replace old one
       
   441             PolicyEntry origPe = policyEntries.elementAt(index);
       
   442             parser.replace(origPe.getGrantEntry(), pe.getGrantEntry());
       
   443             policyEntries.setElementAt(pe, index);
       
   444         }
       
   445         return true;
       
   446     }
       
   447 
       
   448     /**
       
   449      * Add a Principal entry to an existing PolicyEntry at the specified index.
       
   450      * A Principal entry consists of a class, and name.
       
   451      *
       
   452      * If the principal already exists, it is not added again.
       
   453      */
       
   454     boolean addPrinEntry(PolicyEntry pe,
       
   455                         PolicyParser.PrincipalEntry newPrin,
       
   456                         int index) {
       
   457 
       
   458         // first add the principal to the Policy Parser entry
       
   459         PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();
       
   460         if (grantEntry.contains(newPrin) == true)
       
   461             return false;
       
   462 
       
   463         LinkedList<PolicyParser.PrincipalEntry> prinList =
       
   464                                                 grantEntry.principals;
       
   465         if (index != -1)
       
   466             prinList.set(index, newPrin);
       
   467         else
       
   468             prinList.add(newPrin);
       
   469 
       
   470         modified = true;
       
   471         return true;
       
   472     }
       
   473 
       
   474     /**
       
   475      * Add a Permission entry to an existing PolicyEntry at the specified index.
       
   476      * A Permission entry consists of a permission, name, and actions.
       
   477      *
       
   478      * If the permission already exists, it is not added again.
       
   479      */
       
   480     boolean addPermEntry(PolicyEntry pe,
       
   481                         PolicyParser.PermissionEntry newPerm,
       
   482                         int index) {
       
   483 
       
   484         // first add the permission to the Policy Parser Vector
       
   485         PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();
       
   486         if (grantEntry.contains(newPerm) == true)
       
   487             return false;
       
   488 
       
   489         Vector<PolicyParser.PermissionEntry> permList =
       
   490                                                 grantEntry.permissionEntries;
       
   491         if (index != -1)
       
   492             permList.setElementAt(newPerm, index);
       
   493         else
       
   494             permList.addElement(newPerm);
       
   495 
       
   496         modified = true;
       
   497         return true;
       
   498     }
       
   499 
       
   500     /**
       
   501      * Remove a Permission entry from an existing PolicyEntry.
       
   502      */
       
   503     boolean removePermEntry(PolicyEntry pe,
       
   504                         PolicyParser.PermissionEntry perm) {
       
   505 
       
   506         // remove the Permission from the GrantEntry
       
   507         PolicyParser.GrantEntry ppge = pe.getGrantEntry();
       
   508         modified = ppge.remove(perm);
       
   509         return modified;
       
   510     }
       
   511 
       
   512     /**
       
   513      * remove an entry from the overall policy
       
   514      */
       
   515     boolean removeEntry(PolicyEntry pe) {
       
   516 
       
   517         parser.remove(pe.getGrantEntry());
       
   518         modified = true;
       
   519         return (policyEntries.removeElement(pe));
       
   520     }
       
   521 
       
   522     /**
       
   523      * retrieve all Policy Entries
       
   524      */
       
   525     PolicyEntry[] getEntry() {
       
   526 
       
   527         if (policyEntries.size() > 0) {
       
   528             PolicyEntry entries[] = new PolicyEntry[policyEntries.size()];
       
   529             for (int i = 0; i < policyEntries.size(); i++)
       
   530                 entries[i] = policyEntries.elementAt(i);
       
   531             return entries;
       
   532         }
       
   533         return null;
       
   534     }
       
   535 
       
   536     /**
       
   537      * Retrieve the public key mapped to a particular name.
       
   538      * If the key has expired, a KeyException is thrown.
       
   539      */
       
   540     PublicKey getPublicKeyAlias(String name) throws KeyStoreException {
       
   541         if (keyStore == null) {
       
   542             return null;
       
   543         }
       
   544 
       
   545         Certificate cert = keyStore.getCertificate(name);
       
   546         if (cert == null) {
       
   547             return null;
       
   548         }
       
   549         PublicKey pubKey = cert.getPublicKey();
       
   550         return pubKey;
       
   551     }
       
   552 
       
   553     /**
       
   554      * Retrieve all the alias names stored in the certificate database
       
   555      */
       
   556     String[] getPublicKeyAlias() throws KeyStoreException {
       
   557 
       
   558         int numAliases = 0;
       
   559         String aliases[] = null;
       
   560 
       
   561         if (keyStore == null) {
       
   562             return null;
       
   563         }
       
   564         Enumeration<String> enum_ = keyStore.aliases();
       
   565 
       
   566         // first count the number of elements
       
   567         while (enum_.hasMoreElements()) {
       
   568             enum_.nextElement();
       
   569             numAliases++;
       
   570         }
       
   571 
       
   572         if (numAliases > 0) {
       
   573             // now copy them into an array
       
   574             aliases = new String[numAliases];
       
   575             numAliases = 0;
       
   576             enum_ = keyStore.aliases();
       
   577             while (enum_.hasMoreElements()) {
       
   578                 aliases[numAliases] = new String(enum_.nextElement());
       
   579                 numAliases++;
       
   580             }
       
   581         }
       
   582         return aliases;
       
   583     }
       
   584 
       
   585     /**
       
   586      * This method parses a single string of signers separated by commas
       
   587      * ("jordan, duke, pippen") into an array of individual strings.
       
   588      */
       
   589     String[] parseSigners(String signedBy) {
       
   590 
       
   591         String signers[] = null;
       
   592         int numSigners = 1;
       
   593         int signedByIndex = 0;
       
   594         int commaIndex = 0;
       
   595         int signerNum = 0;
       
   596 
       
   597         // first pass thru "signedBy" counts the number of signers
       
   598         while (commaIndex >= 0) {
       
   599             commaIndex = signedBy.indexOf(',', signedByIndex);
       
   600             if (commaIndex >= 0) {
       
   601                 numSigners++;
       
   602                 signedByIndex = commaIndex + 1;
       
   603             }
       
   604         }
       
   605         signers = new String[numSigners];
       
   606 
       
   607         // second pass thru "signedBy" transfers signers to array
       
   608         commaIndex = 0;
       
   609         signedByIndex = 0;
       
   610         while (commaIndex >= 0) {
       
   611             if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) {
       
   612                 // transfer signer and ignore trailing part of the string
       
   613                 signers[signerNum] =
       
   614                         signedBy.substring(signedByIndex, commaIndex).trim();
       
   615                 signerNum++;
       
   616                 signedByIndex = commaIndex + 1;
       
   617             } else {
       
   618                 // we are at the end of the string -- transfer signer
       
   619                 signers[signerNum] = signedBy.substring(signedByIndex).trim();
       
   620             }
       
   621         }
       
   622         return signers;
       
   623     }
       
   624 
       
   625     /**
       
   626      * Check to see if the Principal contents are OK
       
   627      */
       
   628     void verifyPrincipal(String type, String name)
       
   629         throws ClassNotFoundException,
       
   630                InstantiationException
       
   631     {
       
   632         if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) ||
       
   633             type.equals(PolicyParser.PrincipalEntry.REPLACE_NAME)) {
       
   634             return;
       
   635         }
       
   636         Class<?> PRIN = Class.forName("java.security.Principal");
       
   637         Class<?> pc = Class.forName(type, true,
       
   638                 Thread.currentThread().getContextClassLoader());
       
   639         if (!PRIN.isAssignableFrom(pc)) {
       
   640             MessageFormat form = new MessageFormat(getMessage
       
   641                         ("Illegal.Principal.Type.type"));
       
   642             Object[] source = {type};
       
   643             throw new InstantiationException(form.format(source));
       
   644         }
       
   645 
       
   646         if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) {
       
   647             // PolicyParser checks validity of X500Principal name
       
   648             // - PolicyTool needs to as well so that it doesn't store
       
   649             //   an invalid name that can't be read in later
       
   650             //
       
   651             // this can throw an IllegalArgumentException
       
   652             X500Principal newP = new X500Principal(name);
       
   653         }
       
   654     }
       
   655 
       
   656     /**
       
   657      * Check to see if the Permission contents are OK
       
   658      */
       
   659     @SuppressWarnings("fallthrough")
       
   660     void verifyPermission(String type,
       
   661                                     String name,
       
   662                                     String actions)
       
   663         throws ClassNotFoundException,
       
   664                InstantiationException,
       
   665                IllegalAccessException,
       
   666                NoSuchMethodException,
       
   667                InvocationTargetException
       
   668     {
       
   669 
       
   670         //XXX we might want to keep a hash of created factories...
       
   671         Class<?> pc = Class.forName(type, true,
       
   672                 Thread.currentThread().getContextClassLoader());
       
   673         Constructor<?> c = null;
       
   674         Vector<String> objects = new Vector<>(2);
       
   675         if (name != null) objects.add(name);
       
   676         if (actions != null) objects.add(actions);
       
   677         switch (objects.size()) {
       
   678         case 0:
       
   679             try {
       
   680                 c = pc.getConstructor(NOPARAMS);
       
   681                 break;
       
   682             } catch (NoSuchMethodException ex) {
       
   683                 // proceed to the one-param constructor
       
   684                 objects.add(null);
       
   685             }
       
   686             /* fall through */
       
   687         case 1:
       
   688             try {
       
   689                 c = pc.getConstructor(ONEPARAMS);
       
   690                 break;
       
   691             } catch (NoSuchMethodException ex) {
       
   692                 // proceed to the two-param constructor
       
   693                 objects.add(null);
       
   694             }
       
   695             /* fall through */
       
   696         case 2:
       
   697             c = pc.getConstructor(TWOPARAMS);
       
   698             break;
       
   699         }
       
   700         Object parameters[] = objects.toArray();
       
   701         Permission p = (Permission)c.newInstance(parameters);
       
   702     }
       
   703 
       
   704     /*
       
   705      * Parse command line arguments.
       
   706      */
       
   707     static void parseArgs(String args[]) {
       
   708         /* parse flags */
       
   709         int n = 0;
       
   710 
       
   711         for (n=0; (n < args.length) && args[n].startsWith("-"); n++) {
       
   712 
       
   713             String flags = args[n];
       
   714 
       
   715             if (collator.compare(flags, "-file") == 0) {
       
   716                 if (++n == args.length) usage();
       
   717                 policyFileName = args[n];
       
   718             } else {
       
   719                 MessageFormat form = new MessageFormat(getMessage
       
   720                                 ("Illegal.option.option"));
       
   721                 Object[] source = { flags };
       
   722                 System.err.println(form.format(source));
       
   723                 usage();
       
   724             }
       
   725         }
       
   726     }
       
   727 
       
   728     static void usage() {
       
   729         System.out.println(getMessage("Usage.policytool.options."));
       
   730         System.out.println();
       
   731         System.out.println(getMessage
       
   732                 (".file.file.policy.file.location"));
       
   733         System.out.println();
       
   734 
       
   735         System.exit(1);
       
   736     }
       
   737 
       
   738     /**
       
   739      * run the PolicyTool
       
   740      */
       
   741     public static void main(String args[]) {
       
   742         parseArgs(args);
       
   743         SwingUtilities.invokeLater(new Runnable() {
       
   744             public void run() {
       
   745                 ToolWindow tw = new ToolWindow(new PolicyTool());
       
   746                 tw.displayToolWindow(args);
       
   747             }
       
   748         });
       
   749     }
       
   750 
       
   751     // split instr to words according to capitalization,
       
   752     // like, AWTControl -> A W T Control
       
   753     // this method is for easy pronounciation
       
   754     static String splitToWords(String instr) {
       
   755         return instr.replaceAll("([A-Z])", " $1");
       
   756     }
       
   757 
       
   758     /**
       
   759      * Returns the message corresponding to the key in the bundle.
       
   760      * This is preferred over {@link #getString} because it removes
       
   761      * any mnemonic '&' character in the string.
       
   762      *
       
   763      * @param key the key
       
   764      *
       
   765      * @return the message
       
   766      */
       
   767     static String getMessage(String key) {
       
   768         return removeMnemonicAmpersand(rb.getString(key));
       
   769     }
       
   770 
       
   771 
       
   772     /**
       
   773      * Returns the mnemonic for a message.
       
   774      *
       
   775      * @param key the key
       
   776      *
       
   777      * @return the mnemonic <code>int</code>
       
   778      */
       
   779     static int getMnemonicInt(String key) {
       
   780         String message = rb.getString(key);
       
   781         return (findMnemonicInt(message));
       
   782     }
       
   783 
       
   784     /**
       
   785      * Returns the mnemonic display index for a message.
       
   786      *
       
   787      * @param key the key
       
   788      *
       
   789      * @return the mnemonic display index
       
   790      */
       
   791     static int getDisplayedMnemonicIndex(String key) {
       
   792         String message = rb.getString(key);
       
   793         return (findMnemonicIndex(message));
       
   794     }
       
   795 
       
   796     /**
       
   797      * Finds the mnemonic character in a message.
       
   798      *
       
   799      * The mnemonic character is the first character followed by the first
       
   800      * <code>&</code> that is not followed by another <code>&</code>.
       
   801      *
       
   802      * @return the mnemonic as an <code>int</code>, or <code>0</code> if it
       
   803      *         can't be found.
       
   804      */
       
   805     private static int findMnemonicInt(String s) {
       
   806         for (int i = 0; i < s.length() - 1; i++) {
       
   807             if (s.charAt(i) == '&') {
       
   808                 if (s.charAt(i + 1) != '&') {
       
   809                     return KeyEvent.getExtendedKeyCodeForChar(s.charAt(i + 1));
       
   810                 } else {
       
   811                     i++;
       
   812                 }
       
   813             }
       
   814         }
       
   815         return 0;
       
   816     }
       
   817 
       
   818     /**
       
   819      * Finds the index of the mnemonic character in a message.
       
   820      *
       
   821      * The mnemonic character is the first character followed by the first
       
   822      * <code>&</code> that is not followed by another <code>&</code>.
       
   823      *
       
   824      * @return the mnemonic character index as an <code>int</code>, or <code>-1</code> if it
       
   825      *         can't be found.
       
   826      */
       
   827     private static int findMnemonicIndex(String s) {
       
   828         for (int i = 0; i < s.length() - 1; i++) {
       
   829             if (s.charAt(i) == '&') {
       
   830                 if (s.charAt(i + 1) != '&') {
       
   831                     // Return the index of the '&' since it will be removed
       
   832                     return i;
       
   833                 } else {
       
   834                     i++;
       
   835                 }
       
   836             }
       
   837         }
       
   838         return -1;
       
   839     }
       
   840 
       
   841     /**
       
   842      * Removes the mnemonic identifier (<code>&</code>) from a string unless
       
   843      * it's escaped by <code>&&</code> or placed at the end.
       
   844      *
       
   845      * @param message the message
       
   846      *
       
   847      * @return a message with the mnemonic identifier removed
       
   848      */
       
   849     private static String removeMnemonicAmpersand(String message) {
       
   850         StringBuilder s = new StringBuilder();
       
   851         for (int i = 0; i < message.length(); i++) {
       
   852             char current = message.charAt(i);
       
   853             if (current != '&' || i == message.length() - 1
       
   854                     || message.charAt(i + 1) == '&') {
       
   855                 s.append(current);
       
   856             }
       
   857         }
       
   858         return s.toString();
       
   859     }
       
   860 }
       
   861 
       
   862 /**
       
   863  * Each entry in the policy configuration file is represented by a
       
   864  * PolicyEntry object.
       
   865  *
       
   866  * A PolicyEntry is a (CodeSource,Permission) pair.  The
       
   867  * CodeSource contains the (URL, PublicKey) that together identify
       
   868  * where the Java bytecodes come from and who (if anyone) signed
       
   869  * them.  The URL could refer to localhost.  The URL could also be
       
   870  * null, meaning that this policy entry is given to all comers, as
       
   871  * long as they match the signer field.  The signer could be null,
       
   872  * meaning the code is not signed.
       
   873  *
       
   874  * The Permission contains the (Type, Name, Action) triplet.
       
   875  *
       
   876  */
       
   877 class PolicyEntry {
       
   878 
       
   879     private CodeSource codesource;
       
   880     private PolicyTool tool;
       
   881     private PolicyParser.GrantEntry grantEntry;
       
   882     private boolean testing = false;
       
   883 
       
   884     /**
       
   885      * Create a PolicyEntry object from the information read in
       
   886      * from a policy file.
       
   887      */
       
   888     PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge)
       
   889     throws MalformedURLException, NoSuchMethodException,
       
   890     ClassNotFoundException, InstantiationException, IllegalAccessException,
       
   891     InvocationTargetException, CertificateException,
       
   892     IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
       
   893 
       
   894         this.tool = tool;
       
   895 
       
   896         URL location = null;
       
   897 
       
   898         // construct the CodeSource
       
   899         if (ge.codeBase != null)
       
   900             location = new URL(ge.codeBase);
       
   901         this.codesource = new CodeSource(location,
       
   902             (java.security.cert.Certificate[]) null);
       
   903 
       
   904         if (testing) {
       
   905             System.out.println("Adding Policy Entry:");
       
   906             System.out.println("    CodeBase = " + location);
       
   907             System.out.println("    Signers = " + ge.signedBy);
       
   908             System.out.println("    with " + ge.principals.size() +
       
   909                     " Principals");
       
   910         }
       
   911 
       
   912         this.grantEntry = ge;
       
   913     }
       
   914 
       
   915     /**
       
   916      * get the codesource associated with this PolicyEntry
       
   917      */
       
   918     CodeSource getCodeSource() {
       
   919         return codesource;
       
   920     }
       
   921 
       
   922     /**
       
   923      * get the GrantEntry associated with this PolicyEntry
       
   924      */
       
   925     PolicyParser.GrantEntry getGrantEntry() {
       
   926         return grantEntry;
       
   927     }
       
   928 
       
   929     /**
       
   930      * convert the header portion, i.e. codebase, signer, principals, of
       
   931      * this policy entry into a string
       
   932      */
       
   933     String headerToString() {
       
   934         String pString = principalsToString();
       
   935         if (pString.length() == 0) {
       
   936             return codebaseToString();
       
   937         } else {
       
   938             return codebaseToString() + ", " + pString;
       
   939         }
       
   940     }
       
   941 
       
   942     /**
       
   943      * convert the Codebase/signer portion of this policy entry into a string
       
   944      */
       
   945     String codebaseToString() {
       
   946 
       
   947         String stringEntry = new String();
       
   948 
       
   949         if (grantEntry.codeBase != null &&
       
   950             grantEntry.codeBase.equals("") == false)
       
   951             stringEntry = stringEntry.concat
       
   952                                 ("CodeBase \"" +
       
   953                                 grantEntry.codeBase +
       
   954                                 "\"");
       
   955 
       
   956         if (grantEntry.signedBy != null &&
       
   957             grantEntry.signedBy.equals("") == false)
       
   958             stringEntry = ((stringEntry.length() > 0) ?
       
   959                 stringEntry.concat(", SignedBy \"" +
       
   960                                 grantEntry.signedBy +
       
   961                                 "\"") :
       
   962                 stringEntry.concat("SignedBy \"" +
       
   963                                 grantEntry.signedBy +
       
   964                                 "\""));
       
   965 
       
   966         if (stringEntry.length() == 0)
       
   967             return new String("CodeBase <ALL>");
       
   968         return stringEntry;
       
   969     }
       
   970 
       
   971     /**
       
   972      * convert the Principals portion of this policy entry into a string
       
   973      */
       
   974     String principalsToString() {
       
   975         String result = "";
       
   976         if ((grantEntry.principals != null) &&
       
   977             (!grantEntry.principals.isEmpty())) {
       
   978             StringBuilder sb = new StringBuilder(200);
       
   979             ListIterator<PolicyParser.PrincipalEntry> list =
       
   980                                 grantEntry.principals.listIterator();
       
   981             while (list.hasNext()) {
       
   982                 PolicyParser.PrincipalEntry pppe = list.next();
       
   983                 sb.append(" Principal ").append(pppe.getDisplayClass())
       
   984                         .append(' ')
       
   985                         .append(pppe.getDisplayName(true));
       
   986                 if (list.hasNext()) sb.append(", ");
       
   987             }
       
   988             result = sb.toString();
       
   989         }
       
   990         return result;
       
   991     }
       
   992 
       
   993     /**
       
   994      * convert this policy entry into a PolicyParser.PermissionEntry
       
   995      */
       
   996     PolicyParser.PermissionEntry toPermissionEntry(Permission perm) {
       
   997 
       
   998         String actions = null;
       
   999 
       
  1000         // get the actions
       
  1001         if (perm.getActions() != null &&
       
  1002             perm.getActions().trim() != "")
       
  1003                 actions = perm.getActions();
       
  1004 
       
  1005         PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry
       
  1006                         (perm.getClass().getName(),
       
  1007                         perm.getName(),
       
  1008                         actions);
       
  1009         return pe;
       
  1010     }
       
  1011 }
       
  1012 
       
  1013 /**
       
  1014  * The main window for the PolicyTool
       
  1015  */
       
  1016 class ToolWindow extends JFrame {
       
  1017     // use serialVersionUID from JDK 1.2.2 for interoperability
       
  1018     private static final long serialVersionUID = 5682568601210376777L;
       
  1019 
       
  1020     /* ESCAPE key */
       
  1021     static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
       
  1022 
       
  1023     /* external paddings */
       
  1024     public static final Insets TOP_PADDING = new Insets(25,0,0,0);
       
  1025     public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);
       
  1026     public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0);
       
  1027     public static final Insets LR_PADDING = new Insets(0,10,0,10);
       
  1028     public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);
       
  1029     public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);
       
  1030     public static final Insets LR_TOP_BOTTOM_PADDING = new Insets(15, 4, 15, 4);
       
  1031     public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);
       
  1032     public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);
       
  1033     public static final Insets R_BOTTOM_PADDING = new Insets(0, 0, 25, 5);
       
  1034     public static final Insets R_PADDING = new Insets(0, 0, 0, 5);
       
  1035 
       
  1036     /* buttons and menus */
       
  1037     public static final String NEW_POLICY_FILE          = "New";
       
  1038     public static final String OPEN_POLICY_FILE         = "Open";
       
  1039     public static final String SAVE_POLICY_FILE         = "Save";
       
  1040     public static final String SAVE_AS_POLICY_FILE      = "Save.As";
       
  1041     public static final String VIEW_WARNINGS            = "View.Warning.Log";
       
  1042     public static final String QUIT                     = "Exit";
       
  1043     public static final String ADD_POLICY_ENTRY         = "Add.Policy.Entry";
       
  1044     public static final String EDIT_POLICY_ENTRY        = "Edit.Policy.Entry";
       
  1045     public static final String REMOVE_POLICY_ENTRY      = "Remove.Policy.Entry";
       
  1046     public static final String EDIT_KEYSTORE            = "Edit";
       
  1047     public static final String ADD_PUBKEY_ALIAS         = "Add.Public.Key.Alias";
       
  1048     public static final String REMOVE_PUBKEY_ALIAS      = "Remove.Public.Key.Alias";
       
  1049 
       
  1050     /* gridbag index for components in the main window (MW) */
       
  1051     public static final int MW_FILENAME_LABEL           = 0;
       
  1052     public static final int MW_FILENAME_TEXTFIELD       = 1;
       
  1053     public static final int MW_PANEL                    = 2;
       
  1054     public static final int MW_ADD_BUTTON               = 0;
       
  1055     public static final int MW_EDIT_BUTTON              = 1;
       
  1056     public static final int MW_REMOVE_BUTTON            = 2;
       
  1057     public static final int MW_POLICY_LIST              = 3; // follows MW_PANEL
       
  1058 
       
  1059     /* The preferred height of JTextField should match JComboBox. */
       
  1060     static final int TEXTFIELD_HEIGHT = new JComboBox<>().getPreferredSize().height;
       
  1061 
       
  1062     private PolicyTool tool;
       
  1063 
       
  1064     /**
       
  1065      * Constructor
       
  1066      */
       
  1067     ToolWindow(PolicyTool tool) {
       
  1068         this.tool = tool;
       
  1069     }
       
  1070 
       
  1071     /**
       
  1072      * Don't call getComponent directly on the window
       
  1073      */
       
  1074     public Component getComponent(int n) {
       
  1075         Component c = getContentPane().getComponent(n);
       
  1076         if (c instanceof JScrollPane) {
       
  1077             c = ((JScrollPane)c).getViewport().getView();
       
  1078         }
       
  1079         return c;
       
  1080     }
       
  1081 
       
  1082     /**
       
  1083      * Initialize the PolicyTool window with the necessary components
       
  1084      */
       
  1085     private void initWindow() {
       
  1086         // The ToolWindowListener will handle closing the window.
       
  1087         setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
       
  1088 
       
  1089         // create the top menu bar
       
  1090         JMenuBar menuBar = new JMenuBar();
       
  1091 
       
  1092         // create a File menu
       
  1093         JMenu menu = new JMenu();
       
  1094         configureButton(menu, "File");
       
  1095         ActionListener actionListener = new FileMenuListener(tool, this);
       
  1096         addMenuItem(menu, NEW_POLICY_FILE, actionListener, "N");
       
  1097         addMenuItem(menu, OPEN_POLICY_FILE, actionListener, "O");
       
  1098         addMenuItem(menu, SAVE_POLICY_FILE, actionListener, "S");
       
  1099         addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener, null);
       
  1100         addMenuItem(menu, VIEW_WARNINGS, actionListener, null);
       
  1101         addMenuItem(menu, QUIT, actionListener, null);
       
  1102         menuBar.add(menu);
       
  1103 
       
  1104         // create a KeyStore menu
       
  1105         menu = new JMenu();
       
  1106         configureButton(menu, "KeyStore");
       
  1107         actionListener = new MainWindowListener(tool, this);
       
  1108         addMenuItem(menu, EDIT_KEYSTORE, actionListener, null);
       
  1109         menuBar.add(menu);
       
  1110         setJMenuBar(menuBar);
       
  1111 
       
  1112         // Create some space around components
       
  1113         ((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
       
  1114 
       
  1115         // policy entry listing
       
  1116         JLabel label = new JLabel(PolicyTool.getMessage("Policy.File."));
       
  1117         addNewComponent(this, label, MW_FILENAME_LABEL,
       
  1118                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1119                         LR_TOP_BOTTOM_PADDING);
       
  1120         JTextField tf = new JTextField(50);
       
  1121         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  1122         tf.getAccessibleContext().setAccessibleName(
       
  1123                 PolicyTool.getMessage("Policy.File."));
       
  1124         tf.setEditable(false);
       
  1125         addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,
       
  1126                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1127                         LR_TOP_BOTTOM_PADDING);
       
  1128 
       
  1129 
       
  1130         // add ADD/REMOVE/EDIT buttons in a new panel
       
  1131         JPanel panel = new JPanel();
       
  1132         panel.setLayout(new GridBagLayout());
       
  1133 
       
  1134         JButton button = new JButton();
       
  1135         configureButton(button, ADD_POLICY_ENTRY);
       
  1136         button.addActionListener(new MainWindowListener(tool, this));
       
  1137         addNewComponent(panel, button, MW_ADD_BUTTON,
       
  1138                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1139                         LR_PADDING);
       
  1140 
       
  1141         button = new JButton();
       
  1142         configureButton(button, EDIT_POLICY_ENTRY);
       
  1143         button.addActionListener(new MainWindowListener(tool, this));
       
  1144         addNewComponent(panel, button, MW_EDIT_BUTTON,
       
  1145                         1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1146                         LR_PADDING);
       
  1147 
       
  1148         button = new JButton();
       
  1149         configureButton(button, REMOVE_POLICY_ENTRY);
       
  1150         button.addActionListener(new MainWindowListener(tool, this));
       
  1151         addNewComponent(panel, button, MW_REMOVE_BUTTON,
       
  1152                         2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1153                         LR_PADDING);
       
  1154 
       
  1155         addNewComponent(this, panel, MW_PANEL,
       
  1156                         0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1157                         BOTTOM_PADDING);
       
  1158 
       
  1159 
       
  1160         String policyFile = tool.getPolicyFileName();
       
  1161         if (policyFile == null) {
       
  1162             String userHome;
       
  1163             userHome = java.security.AccessController.doPrivileged(
       
  1164                 (PrivilegedAction<String>) () -> System.getProperty("user.home"));
       
  1165             policyFile = userHome + File.separatorChar + ".java.policy";
       
  1166         }
       
  1167 
       
  1168         try {
       
  1169             // open the policy file
       
  1170             tool.openPolicy(policyFile);
       
  1171 
       
  1172             // display the policy entries via the policy list textarea
       
  1173             DefaultListModel<String> listModel = new DefaultListModel<>();
       
  1174             JList<String> list = new JList<>(listModel);
       
  1175             list.setVisibleRowCount(15);
       
  1176             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1177             list.addMouseListener(new PolicyListListener(tool, this));
       
  1178             PolicyEntry entries[] = tool.getEntry();
       
  1179             if (entries != null) {
       
  1180                 for (int i = 0; i < entries.length; i++) {
       
  1181                     listModel.addElement(entries[i].headerToString());
       
  1182                 }
       
  1183             }
       
  1184             JTextField newFilename = (JTextField)
       
  1185                                 getComponent(MW_FILENAME_TEXTFIELD);
       
  1186             newFilename.setText(policyFile);
       
  1187             initPolicyList(list);
       
  1188 
       
  1189         } catch (FileNotFoundException fnfe) {
       
  1190             // add blank policy listing
       
  1191             JList<String> list = new JList<>(new DefaultListModel<>());
       
  1192             list.setVisibleRowCount(15);
       
  1193             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1194             list.addMouseListener(new PolicyListListener(tool, this));
       
  1195             initPolicyList(list);
       
  1196             tool.setPolicyFileName(null);
       
  1197             tool.modified = false;
       
  1198 
       
  1199             // just add warning
       
  1200             tool.warnings.addElement(fnfe.toString());
       
  1201 
       
  1202         } catch (Exception e) {
       
  1203             // add blank policy listing
       
  1204             JList<String> list = new JList<>(new DefaultListModel<>());
       
  1205             list.setVisibleRowCount(15);
       
  1206             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  1207             list.addMouseListener(new PolicyListListener(tool, this));
       
  1208             initPolicyList(list);
       
  1209             tool.setPolicyFileName(null);
       
  1210             tool.modified = false;
       
  1211 
       
  1212             // display the error
       
  1213             MessageFormat form = new MessageFormat(PolicyTool.getMessage
       
  1214                 ("Could.not.open.policy.file.policyFile.e.toString."));
       
  1215             Object[] source = {policyFile, e.toString()};
       
  1216             displayErrorDialog(null, form.format(source));
       
  1217         }
       
  1218     }
       
  1219 
       
  1220 
       
  1221     // Platform specific modifier (control / command).
       
  1222     private int shortCutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
       
  1223 
       
  1224     private void addMenuItem(JMenu menu, String key, ActionListener actionListener, String accelerator) {
       
  1225         JMenuItem menuItem = new JMenuItem();
       
  1226         configureButton(menuItem, key);
       
  1227 
       
  1228         if (PolicyTool.rb.containsKey(key + ".accelerator")) {
       
  1229             // Accelerator from resources takes precedence
       
  1230             accelerator = PolicyTool.getMessage(key + ".accelerator");
       
  1231         }
       
  1232 
       
  1233         if (accelerator != null && !accelerator.isEmpty()) {
       
  1234             KeyStroke keyStroke;
       
  1235             if (accelerator.length() == 1) {
       
  1236                 keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(0)),
       
  1237                                                    shortCutModifier);
       
  1238             } else {
       
  1239                 keyStroke = KeyStroke.getKeyStroke(accelerator);
       
  1240             }
       
  1241             menuItem.setAccelerator(keyStroke);
       
  1242         }
       
  1243 
       
  1244         menuItem.addActionListener(actionListener);
       
  1245         menu.add(menuItem);
       
  1246     }
       
  1247 
       
  1248     static void configureButton(AbstractButton button, String key) {
       
  1249         button.setText(PolicyTool.getMessage(key));
       
  1250         button.setActionCommand(key);
       
  1251 
       
  1252         int mnemonicInt = PolicyTool.getMnemonicInt(key);
       
  1253         if (mnemonicInt > 0) {
       
  1254             button.setMnemonic(mnemonicInt);
       
  1255             button.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
       
  1256          }
       
  1257     }
       
  1258 
       
  1259     static void configureLabelFor(JLabel label, JComponent component, String key) {
       
  1260         label.setText(PolicyTool.getMessage(key));
       
  1261         label.setLabelFor(component);
       
  1262 
       
  1263         int mnemonicInt = PolicyTool.getMnemonicInt(key);
       
  1264         if (mnemonicInt > 0) {
       
  1265             label.setDisplayedMnemonic(mnemonicInt);
       
  1266             label.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));
       
  1267          }
       
  1268     }
       
  1269 
       
  1270 
       
  1271     /**
       
  1272      * Add a component to the PolicyTool window
       
  1273      */
       
  1274     void addNewComponent(Container container, JComponent component,
       
  1275         int index, int gridx, int gridy, int gridwidth, int gridheight,
       
  1276         double weightx, double weighty, int fill, Insets is) {
       
  1277 
       
  1278         if (container instanceof JFrame) {
       
  1279             container = ((JFrame)container).getContentPane();
       
  1280         } else if (container instanceof JDialog) {
       
  1281             container = ((JDialog)container).getContentPane();
       
  1282         }
       
  1283 
       
  1284         // add the component at the specified gridbag index
       
  1285         container.add(component, index);
       
  1286 
       
  1287         // set the constraints
       
  1288         GridBagLayout gbl = (GridBagLayout)container.getLayout();
       
  1289         GridBagConstraints gbc = new GridBagConstraints();
       
  1290         gbc.gridx = gridx;
       
  1291         gbc.gridy = gridy;
       
  1292         gbc.gridwidth = gridwidth;
       
  1293         gbc.gridheight = gridheight;
       
  1294         gbc.weightx = weightx;
       
  1295         gbc.weighty = weighty;
       
  1296         gbc.fill = fill;
       
  1297         if (is != null) gbc.insets = is;
       
  1298         gbl.setConstraints(component, gbc);
       
  1299     }
       
  1300 
       
  1301 
       
  1302     /**
       
  1303      * Add a component to the PolicyTool window without external padding
       
  1304      */
       
  1305     void addNewComponent(Container container, JComponent component,
       
  1306         int index, int gridx, int gridy, int gridwidth, int gridheight,
       
  1307         double weightx, double weighty, int fill) {
       
  1308 
       
  1309         // delegate with "null" external padding
       
  1310         addNewComponent(container, component, index, gridx, gridy,
       
  1311                         gridwidth, gridheight, weightx, weighty,
       
  1312                         fill, null);
       
  1313     }
       
  1314 
       
  1315 
       
  1316     /**
       
  1317      * Init the policy_entry_list TEXTAREA component in the
       
  1318      * PolicyTool window
       
  1319      */
       
  1320     void initPolicyList(JList<String> policyList) {
       
  1321 
       
  1322         // add the policy list to the window
       
  1323         //policyList.setPreferredSize(new Dimension(500, 350));
       
  1324         JScrollPane scrollPane = new JScrollPane(policyList);
       
  1325         addNewComponent(this, scrollPane, MW_POLICY_LIST,
       
  1326                         0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);
       
  1327     }
       
  1328 
       
  1329     /**
       
  1330      * Replace the policy_entry_list TEXTAREA component in the
       
  1331      * PolicyTool window with an updated one.
       
  1332      */
       
  1333     void replacePolicyList(JList<String> policyList) {
       
  1334 
       
  1335         // remove the original list of Policy Entries
       
  1336         // and add the new list of entries
       
  1337         @SuppressWarnings("unchecked")
       
  1338         JList<String> list = (JList<String>)getComponent(MW_POLICY_LIST);
       
  1339         list.setModel(policyList.getModel());
       
  1340     }
       
  1341 
       
  1342     /**
       
  1343      * display the main PolicyTool window
       
  1344      */
       
  1345     void displayToolWindow(String args[]) {
       
  1346 
       
  1347         setTitle(PolicyTool.getMessage("Policy.Tool"));
       
  1348         setResizable(true);
       
  1349         addWindowListener(new ToolWindowListener(tool, this));
       
  1350         //setBounds(135, 80, 500, 500);
       
  1351         getContentPane().setLayout(new GridBagLayout());
       
  1352 
       
  1353         initWindow();
       
  1354         pack();
       
  1355         setLocationRelativeTo(null);
       
  1356 
       
  1357         // display it
       
  1358         setVisible(true);
       
  1359 
       
  1360         if (tool.newWarning == true) {
       
  1361             displayStatusDialog(this, PolicyTool.getMessage
       
  1362                 ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
       
  1363         }
       
  1364     }
       
  1365 
       
  1366     /**
       
  1367      * displays a dialog box describing an error which occurred.
       
  1368      */
       
  1369     void displayErrorDialog(Window w, String error) {
       
  1370         ToolDialog ed = new ToolDialog
       
  1371                 (PolicyTool.getMessage("Error"), tool, this, true);
       
  1372 
       
  1373         // find where the PolicyTool gui is
       
  1374         Point location = ((w == null) ?
       
  1375                 getLocationOnScreen() : w.getLocationOnScreen());
       
  1376         //ed.setBounds(location.x + 50, location.y + 50, 600, 100);
       
  1377         ed.setLayout(new GridBagLayout());
       
  1378 
       
  1379         JLabel label = new JLabel(error);
       
  1380         addNewComponent(ed, label, 0,
       
  1381                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  1382 
       
  1383         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  1384         ActionListener okListener = new ErrorOKButtonListener(ed);
       
  1385         okButton.addActionListener(okListener);
       
  1386         addNewComponent(ed, okButton, 1,
       
  1387                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  1388 
       
  1389         ed.getRootPane().setDefaultButton(okButton);
       
  1390         ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1391 
       
  1392         ed.pack();
       
  1393         ed.setLocationRelativeTo(w);
       
  1394         ed.setVisible(true);
       
  1395     }
       
  1396 
       
  1397     /**
       
  1398      * displays a dialog box describing an error which occurred.
       
  1399      */
       
  1400     void displayErrorDialog(Window w, Throwable t) {
       
  1401         if (t instanceof NoDisplayException) {
       
  1402             return;
       
  1403         }
       
  1404         if (t.getClass() == Exception.class) {
       
  1405             // Exception is usually thrown inside policytool for user
       
  1406             // interaction error. There is no need to show the type.
       
  1407             displayErrorDialog(w, t.getLocalizedMessage());
       
  1408         } else {
       
  1409             displayErrorDialog(w, t.toString());
       
  1410         }
       
  1411     }
       
  1412 
       
  1413     /**
       
  1414      * displays a dialog box describing the status of an event
       
  1415      */
       
  1416     void displayStatusDialog(Window w, String status) {
       
  1417         ToolDialog sd = new ToolDialog
       
  1418                 (PolicyTool.getMessage("Status"), tool, this, true);
       
  1419 
       
  1420         // find the location of the PolicyTool gui
       
  1421         Point location = ((w == null) ?
       
  1422                 getLocationOnScreen() : w.getLocationOnScreen());
       
  1423         //sd.setBounds(location.x + 50, location.y + 50, 500, 100);
       
  1424         sd.setLayout(new GridBagLayout());
       
  1425 
       
  1426         JLabel label = new JLabel(status);
       
  1427         addNewComponent(sd, label, 0,
       
  1428                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  1429 
       
  1430         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  1431         ActionListener okListener = new StatusOKButtonListener(sd);
       
  1432         okButton.addActionListener(okListener);
       
  1433         addNewComponent(sd, okButton, 1,
       
  1434                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  1435 
       
  1436         sd.getRootPane().setDefaultButton(okButton);
       
  1437         sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1438 
       
  1439         sd.pack();
       
  1440         sd.setLocationRelativeTo(w);
       
  1441         sd.setVisible(true);
       
  1442     }
       
  1443 
       
  1444     /**
       
  1445      * display the warning log
       
  1446      */
       
  1447     void displayWarningLog(Window w) {
       
  1448 
       
  1449         ToolDialog wd = new ToolDialog
       
  1450                 (PolicyTool.getMessage("Warning"), tool, this, true);
       
  1451 
       
  1452         // find the location of the PolicyTool gui
       
  1453         Point location = ((w == null) ?
       
  1454                 getLocationOnScreen() : w.getLocationOnScreen());
       
  1455         //wd.setBounds(location.x + 50, location.y + 50, 500, 100);
       
  1456         wd.setLayout(new GridBagLayout());
       
  1457 
       
  1458         JTextArea ta = new JTextArea();
       
  1459         ta.setEditable(false);
       
  1460         for (int i = 0; i < tool.warnings.size(); i++) {
       
  1461             ta.append(tool.warnings.elementAt(i));
       
  1462             ta.append(PolicyTool.getMessage("NEWLINE"));
       
  1463         }
       
  1464         addNewComponent(wd, ta, 0,
       
  1465                         0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1466                         BOTTOM_PADDING);
       
  1467         ta.setFocusable(false);
       
  1468 
       
  1469         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  1470         ActionListener okListener = new CancelButtonListener(wd);
       
  1471         okButton.addActionListener(okListener);
       
  1472         addNewComponent(wd, okButton, 1,
       
  1473                         0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  1474                         LR_PADDING);
       
  1475 
       
  1476         wd.getRootPane().setDefaultButton(okButton);
       
  1477         wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1478 
       
  1479         wd.pack();
       
  1480         wd.setLocationRelativeTo(w);
       
  1481         wd.setVisible(true);
       
  1482     }
       
  1483 
       
  1484     char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) {
       
  1485 
       
  1486         final ToolDialog tw = new ToolDialog
       
  1487                 (title, tool, this, true);
       
  1488         Point location = ((w == null) ?
       
  1489                 getLocationOnScreen() : w.getLocationOnScreen());
       
  1490         //tw.setBounds(location.x + 75, location.y + 100, 400, 150);
       
  1491         tw.setLayout(new GridBagLayout());
       
  1492 
       
  1493         JTextArea ta = new JTextArea(prompt, 10, 50);
       
  1494         ta.setEditable(false);
       
  1495         ta.setLineWrap(true);
       
  1496         ta.setWrapStyleWord(true);
       
  1497         JScrollPane scrollPane = new JScrollPane(ta,
       
  1498                                                  JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
       
  1499                                                  JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
       
  1500         addNewComponent(tw, scrollPane, 0,
       
  1501                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  1502         ta.setFocusable(false);
       
  1503 
       
  1504         JPanel panel = new JPanel();
       
  1505         panel.setLayout(new GridBagLayout());
       
  1506 
       
  1507         // StringBuffer to store button press. Must be final.
       
  1508         final StringBuffer chooseResult = new StringBuffer();
       
  1509 
       
  1510         JButton button = new JButton(yes);
       
  1511         button.addActionListener(new ActionListener() {
       
  1512             public void actionPerformed(ActionEvent e) {
       
  1513                 chooseResult.append('Y');
       
  1514                 tw.setVisible(false);
       
  1515                 tw.dispose();
       
  1516             }
       
  1517         });
       
  1518         addNewComponent(panel, button, 0,
       
  1519                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  1520                            LR_PADDING);
       
  1521 
       
  1522         button = new JButton(no);
       
  1523         button.addActionListener(new ActionListener() {
       
  1524             public void actionPerformed(ActionEvent e) {
       
  1525                 chooseResult.append('N');
       
  1526                 tw.setVisible(false);
       
  1527                 tw.dispose();
       
  1528             }
       
  1529         });
       
  1530         addNewComponent(panel, button, 1,
       
  1531                            1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  1532                            LR_PADDING);
       
  1533 
       
  1534         addNewComponent(tw, panel, 1,
       
  1535                 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  1536 
       
  1537         tw.pack();
       
  1538         tw.setLocationRelativeTo(w);
       
  1539         tw.setVisible(true);
       
  1540         if (chooseResult.length() > 0) {
       
  1541             return chooseResult.charAt(0);
       
  1542         } else {
       
  1543             // I did encounter this once, don't why.
       
  1544             return 'N';
       
  1545         }
       
  1546     }
       
  1547 
       
  1548 }
       
  1549 
       
  1550 /**
       
  1551  * General dialog window
       
  1552  */
       
  1553 class ToolDialog extends JDialog {
       
  1554     // use serialVersionUID from JDK 1.2.2 for interoperability
       
  1555     private static final long serialVersionUID = -372244357011301190L;
       
  1556 
       
  1557     /* ESCAPE key */
       
  1558     static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
       
  1559 
       
  1560     /* necessary constants */
       
  1561     public static final int NOACTION            = 0;
       
  1562     public static final int QUIT                = 1;
       
  1563     public static final int NEW                 = 2;
       
  1564     public static final int OPEN                = 3;
       
  1565 
       
  1566     public static final String ALL_PERM_CLASS   =
       
  1567                 "java.security.AllPermission";
       
  1568     public static final String FILE_PERM_CLASS  =
       
  1569                 "java.io.FilePermission";
       
  1570 
       
  1571     public static final String X500_PRIN_CLASS         =
       
  1572                 "javax.security.auth.x500.X500Principal";
       
  1573 
       
  1574     /* popup menus */
       
  1575     public static final String PERM             =
       
  1576         PolicyTool.getMessage
       
  1577         ("Permission.");
       
  1578 
       
  1579     public static final String PRIN_TYPE        =
       
  1580         PolicyTool.getMessage("Principal.Type.");
       
  1581     public static final String PRIN_NAME        =
       
  1582         PolicyTool.getMessage("Principal.Name.");
       
  1583 
       
  1584     /* more popu menus */
       
  1585     public static final String PERM_NAME        =
       
  1586         PolicyTool.getMessage
       
  1587         ("Target.Name.");
       
  1588 
       
  1589     /* and more popup menus */
       
  1590     public static final String PERM_ACTIONS             =
       
  1591       PolicyTool.getMessage
       
  1592       ("Actions.");
       
  1593 
       
  1594     /* gridbag index for display PolicyEntry (PE) components */
       
  1595     public static final int PE_CODEBASE_LABEL           = 0;
       
  1596     public static final int PE_CODEBASE_TEXTFIELD       = 1;
       
  1597     public static final int PE_SIGNEDBY_LABEL           = 2;
       
  1598     public static final int PE_SIGNEDBY_TEXTFIELD       = 3;
       
  1599 
       
  1600     public static final int PE_PANEL0                   = 4;
       
  1601     public static final int PE_ADD_PRIN_BUTTON          = 0;
       
  1602     public static final int PE_EDIT_PRIN_BUTTON         = 1;
       
  1603     public static final int PE_REMOVE_PRIN_BUTTON       = 2;
       
  1604 
       
  1605     public static final int PE_PRIN_LABEL               = 5;
       
  1606     public static final int PE_PRIN_LIST                = 6;
       
  1607 
       
  1608     public static final int PE_PANEL1                   = 7;
       
  1609     public static final int PE_ADD_PERM_BUTTON          = 0;
       
  1610     public static final int PE_EDIT_PERM_BUTTON         = 1;
       
  1611     public static final int PE_REMOVE_PERM_BUTTON       = 2;
       
  1612 
       
  1613     public static final int PE_PERM_LIST                = 8;
       
  1614 
       
  1615     public static final int PE_PANEL2                   = 9;
       
  1616     public static final int PE_CANCEL_BUTTON            = 1;
       
  1617     public static final int PE_DONE_BUTTON              = 0;
       
  1618 
       
  1619     /* the gridbag index for components in the Principal Dialog (PRD) */
       
  1620     public static final int PRD_DESC_LABEL              = 0;
       
  1621     public static final int PRD_PRIN_CHOICE             = 1;
       
  1622     public static final int PRD_PRIN_TEXTFIELD          = 2;
       
  1623     public static final int PRD_NAME_LABEL              = 3;
       
  1624     public static final int PRD_NAME_TEXTFIELD          = 4;
       
  1625     public static final int PRD_CANCEL_BUTTON           = 6;
       
  1626     public static final int PRD_OK_BUTTON               = 5;
       
  1627 
       
  1628     /* the gridbag index for components in the Permission Dialog (PD) */
       
  1629     public static final int PD_DESC_LABEL               = 0;
       
  1630     public static final int PD_PERM_CHOICE              = 1;
       
  1631     public static final int PD_PERM_TEXTFIELD           = 2;
       
  1632     public static final int PD_NAME_CHOICE              = 3;
       
  1633     public static final int PD_NAME_TEXTFIELD           = 4;
       
  1634     public static final int PD_ACTIONS_CHOICE           = 5;
       
  1635     public static final int PD_ACTIONS_TEXTFIELD        = 6;
       
  1636     public static final int PD_SIGNEDBY_LABEL           = 7;
       
  1637     public static final int PD_SIGNEDBY_TEXTFIELD       = 8;
       
  1638     public static final int PD_CANCEL_BUTTON            = 10;
       
  1639     public static final int PD_OK_BUTTON                = 9;
       
  1640 
       
  1641     /* modes for KeyStore */
       
  1642     public static final int EDIT_KEYSTORE               = 0;
       
  1643 
       
  1644     /* the gridbag index for components in the Change KeyStore Dialog (KSD) */
       
  1645     public static final int KSD_NAME_LABEL              = 0;
       
  1646     public static final int KSD_NAME_TEXTFIELD          = 1;
       
  1647     public static final int KSD_TYPE_LABEL              = 2;
       
  1648     public static final int KSD_TYPE_TEXTFIELD          = 3;
       
  1649     public static final int KSD_PROVIDER_LABEL          = 4;
       
  1650     public static final int KSD_PROVIDER_TEXTFIELD      = 5;
       
  1651     public static final int KSD_PWD_URL_LABEL           = 6;
       
  1652     public static final int KSD_PWD_URL_TEXTFIELD       = 7;
       
  1653     public static final int KSD_CANCEL_BUTTON           = 9;
       
  1654     public static final int KSD_OK_BUTTON               = 8;
       
  1655 
       
  1656     /* the gridbag index for components in the User Save Changes Dialog (USC) */
       
  1657     public static final int USC_LABEL                   = 0;
       
  1658     public static final int USC_PANEL                   = 1;
       
  1659     public static final int USC_YES_BUTTON              = 0;
       
  1660     public static final int USC_NO_BUTTON               = 1;
       
  1661     public static final int USC_CANCEL_BUTTON           = 2;
       
  1662 
       
  1663     /* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */
       
  1664     public static final int CRPE_LABEL1                 = 0;
       
  1665     public static final int CRPE_LABEL2                 = 1;
       
  1666     public static final int CRPE_PANEL                  = 2;
       
  1667     public static final int CRPE_PANEL_OK               = 0;
       
  1668     public static final int CRPE_PANEL_CANCEL           = 1;
       
  1669 
       
  1670     /* some private static finals */
       
  1671     private static final int PERMISSION                 = 0;
       
  1672     private static final int PERMISSION_NAME            = 1;
       
  1673     private static final int PERMISSION_ACTIONS         = 2;
       
  1674     private static final int PERMISSION_SIGNEDBY        = 3;
       
  1675     private static final int PRINCIPAL_TYPE             = 4;
       
  1676     private static final int PRINCIPAL_NAME             = 5;
       
  1677 
       
  1678     /* The preferred height of JTextField should match JComboBox. */
       
  1679     static final int TEXTFIELD_HEIGHT = new JComboBox<>().getPreferredSize().height;
       
  1680 
       
  1681     public static java.util.ArrayList<Perm> PERM_ARRAY;
       
  1682     public static java.util.ArrayList<Prin> PRIN_ARRAY;
       
  1683     PolicyTool tool;
       
  1684     ToolWindow tw;
       
  1685 
       
  1686     static {
       
  1687 
       
  1688         // set up permission objects
       
  1689 
       
  1690         PERM_ARRAY = new java.util.ArrayList<Perm>();
       
  1691         PERM_ARRAY.add(new AllPerm());
       
  1692         PERM_ARRAY.add(new AudioPerm());
       
  1693         PERM_ARRAY.add(new AuthPerm());
       
  1694         PERM_ARRAY.add(new AWTPerm());
       
  1695         PERM_ARRAY.add(new DelegationPerm());
       
  1696         PERM_ARRAY.add(new FilePerm());
       
  1697         PERM_ARRAY.add(new URLPerm());
       
  1698         PERM_ARRAY.add(new InqSecContextPerm());
       
  1699         PERM_ARRAY.add(new LogPerm());
       
  1700         PERM_ARRAY.add(new MgmtPerm());
       
  1701         PERM_ARRAY.add(new MBeanPerm());
       
  1702         PERM_ARRAY.add(new MBeanSvrPerm());
       
  1703         PERM_ARRAY.add(new MBeanTrustPerm());
       
  1704         PERM_ARRAY.add(new NetPerm());
       
  1705         PERM_ARRAY.add(new NetworkPerm());
       
  1706         PERM_ARRAY.add(new PrivCredPerm());
       
  1707         PERM_ARRAY.add(new PropPerm());
       
  1708         PERM_ARRAY.add(new ReflectPerm());
       
  1709         PERM_ARRAY.add(new RuntimePerm());
       
  1710         PERM_ARRAY.add(new SecurityPerm());
       
  1711         PERM_ARRAY.add(new SerialPerm());
       
  1712         PERM_ARRAY.add(new ServicePerm());
       
  1713         PERM_ARRAY.add(new SocketPerm());
       
  1714         PERM_ARRAY.add(new SQLPerm());
       
  1715         PERM_ARRAY.add(new SSLPerm());
       
  1716         PERM_ARRAY.add(new SubjDelegPerm());
       
  1717 
       
  1718         // set up principal objects
       
  1719 
       
  1720         PRIN_ARRAY = new java.util.ArrayList<Prin>();
       
  1721         PRIN_ARRAY.add(new KrbPrin());
       
  1722         PRIN_ARRAY.add(new X500Prin());
       
  1723     }
       
  1724 
       
  1725     ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) {
       
  1726         super(tw, modal);
       
  1727         setTitle(title);
       
  1728         this.tool = tool;
       
  1729         this.tw = tw;
       
  1730         addWindowListener(new ChildWindowListener(this));
       
  1731 
       
  1732         // Create some space around components
       
  1733         ((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));
       
  1734     }
       
  1735 
       
  1736     /**
       
  1737      * Don't call getComponent directly on the window
       
  1738      */
       
  1739     public Component getComponent(int n) {
       
  1740         Component c = getContentPane().getComponent(n);
       
  1741         if (c instanceof JScrollPane) {
       
  1742             c = ((JScrollPane)c).getViewport().getView();
       
  1743         }
       
  1744         return c;
       
  1745     }
       
  1746 
       
  1747     /**
       
  1748      * get the Perm instance based on either the (shortened) class name
       
  1749      * or the fully qualified class name
       
  1750      */
       
  1751     static Perm getPerm(String clazz, boolean fullClassName) {
       
  1752         for (int i = 0; i < PERM_ARRAY.size(); i++) {
       
  1753             Perm next = PERM_ARRAY.get(i);
       
  1754             if (fullClassName) {
       
  1755                 if (next.FULL_CLASS.equals(clazz)) {
       
  1756                     return next;
       
  1757                 }
       
  1758             } else {
       
  1759                 if (next.CLASS.equals(clazz)) {
       
  1760                     return next;
       
  1761                 }
       
  1762             }
       
  1763         }
       
  1764         return null;
       
  1765     }
       
  1766 
       
  1767     /**
       
  1768      * get the Prin instance based on either the (shortened) class name
       
  1769      * or the fully qualified class name
       
  1770      */
       
  1771     static Prin getPrin(String clazz, boolean fullClassName) {
       
  1772         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
       
  1773             Prin next = PRIN_ARRAY.get(i);
       
  1774             if (fullClassName) {
       
  1775                 if (next.FULL_CLASS.equals(clazz)) {
       
  1776                     return next;
       
  1777                 }
       
  1778             } else {
       
  1779                 if (next.CLASS.equals(clazz)) {
       
  1780                     return next;
       
  1781                 }
       
  1782             }
       
  1783         }
       
  1784         return null;
       
  1785     }
       
  1786 
       
  1787     /**
       
  1788      * pop up a dialog so the user can enter info to add a new PolicyEntry
       
  1789      * - if edit is TRUE, then the user is editing an existing entry
       
  1790      *   and we should display the original info as well.
       
  1791      *
       
  1792      * - the other reason we need the 'edit' boolean is we need to know
       
  1793      *   when we are adding a NEW policy entry.  in this case, we can
       
  1794      *   not simply update the existing entry, because it doesn't exist.
       
  1795      *   we ONLY update the GUI listing/info, and then when the user
       
  1796      *   finally clicks 'OK' or 'DONE', then we can collect that info
       
  1797      *   and add it to the policy.
       
  1798      */
       
  1799     void displayPolicyEntryDialog(boolean edit) {
       
  1800 
       
  1801         int listIndex = 0;
       
  1802         PolicyEntry entries[] = null;
       
  1803         TaggedList prinList = new TaggedList(3, false);
       
  1804         prinList.getAccessibleContext().setAccessibleName(
       
  1805                 PolicyTool.getMessage("Principal.List"));
       
  1806         prinList.addMouseListener
       
  1807                 (new EditPrinButtonListener(tool, tw, this, edit));
       
  1808         TaggedList permList = new TaggedList(10, false);
       
  1809         permList.getAccessibleContext().setAccessibleName(
       
  1810                 PolicyTool.getMessage("Permission.List"));
       
  1811         permList.addMouseListener
       
  1812                 (new EditPermButtonListener(tool, tw, this, edit));
       
  1813 
       
  1814         // find where the PolicyTool gui is
       
  1815         Point location = tw.getLocationOnScreen();
       
  1816         //setBounds(location.x + 75, location.y + 200, 650, 500);
       
  1817         setLayout(new GridBagLayout());
       
  1818         setResizable(true);
       
  1819 
       
  1820         if (edit) {
       
  1821             // get the selected item
       
  1822             entries = tool.getEntry();
       
  1823             @SuppressWarnings("unchecked")
       
  1824             JList<String> policyList = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  1825             listIndex = policyList.getSelectedIndex();
       
  1826 
       
  1827             // get principal list
       
  1828             LinkedList<PolicyParser.PrincipalEntry> principals =
       
  1829                 entries[listIndex].getGrantEntry().principals;
       
  1830             for (int i = 0; i < principals.size(); i++) {
       
  1831                 String prinString = null;
       
  1832                 PolicyParser.PrincipalEntry nextPrin = principals.get(i);
       
  1833                 prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin);
       
  1834             }
       
  1835 
       
  1836             // get permission list
       
  1837             Vector<PolicyParser.PermissionEntry> permissions =
       
  1838                 entries[listIndex].getGrantEntry().permissionEntries;
       
  1839             for (int i = 0; i < permissions.size(); i++) {
       
  1840                 String permString = null;
       
  1841                 PolicyParser.PermissionEntry nextPerm =
       
  1842                                                 permissions.elementAt(i);
       
  1843                 permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm);
       
  1844             }
       
  1845         }
       
  1846 
       
  1847         // codebase label and textfield
       
  1848         JLabel label = new JLabel();
       
  1849         tw.addNewComponent(this, label, PE_CODEBASE_LABEL,
       
  1850                 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1851                 ToolWindow.R_PADDING);
       
  1852         JTextField tf;
       
  1853         tf = (edit ?
       
  1854                 new JTextField(entries[listIndex].getGrantEntry().codeBase) :
       
  1855                 new JTextField());
       
  1856         ToolWindow.configureLabelFor(label, tf, "CodeBase.");
       
  1857         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  1858         tf.getAccessibleContext().setAccessibleName(
       
  1859                 PolicyTool.getMessage("Code.Base"));
       
  1860         tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,
       
  1861                 1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
       
  1862 
       
  1863         // signedby label and textfield
       
  1864         label = new JLabel();
       
  1865         tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,
       
  1866                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1867                            ToolWindow.R_PADDING);
       
  1868         tf = (edit ?
       
  1869                 new JTextField(entries[listIndex].getGrantEntry().signedBy) :
       
  1870                 new JTextField());
       
  1871         ToolWindow.configureLabelFor(label, tf, "SignedBy.");
       
  1872         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  1873         tf.getAccessibleContext().setAccessibleName(
       
  1874                 PolicyTool.getMessage("Signed.By."));
       
  1875         tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,
       
  1876                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);
       
  1877 
       
  1878         // panel for principal buttons
       
  1879         JPanel panel = new JPanel();
       
  1880         panel.setLayout(new GridBagLayout());
       
  1881 
       
  1882         JButton button = new JButton();
       
  1883         ToolWindow.configureButton(button, "Add.Principal");
       
  1884         button.addActionListener
       
  1885                 (new AddPrinButtonListener(tool, tw, this, edit));
       
  1886         tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,
       
  1887                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1888 
       
  1889         button = new JButton();
       
  1890         ToolWindow.configureButton(button, "Edit.Principal");
       
  1891         button.addActionListener(new EditPrinButtonListener
       
  1892                                                 (tool, tw, this, edit));
       
  1893         tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,
       
  1894                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1895 
       
  1896         button = new JButton();
       
  1897         ToolWindow.configureButton(button, "Remove.Principal");
       
  1898         button.addActionListener(new RemovePrinButtonListener
       
  1899                                         (tool, tw, this, edit));
       
  1900         tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,
       
  1901                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1902 
       
  1903         tw.addNewComponent(this, panel, PE_PANEL0,
       
  1904                 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
       
  1905                            ToolWindow.LITE_BOTTOM_PADDING);
       
  1906 
       
  1907         // principal label and list
       
  1908         label = new JLabel();
       
  1909         tw.addNewComponent(this, label, PE_PRIN_LABEL,
       
  1910                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  1911                            ToolWindow.R_BOTTOM_PADDING);
       
  1912         JScrollPane scrollPane = new JScrollPane(prinList);
       
  1913         ToolWindow.configureLabelFor(label, scrollPane, "Principals.");
       
  1914         tw.addNewComponent(this, scrollPane, PE_PRIN_LIST,
       
  1915                            1, 3, 3, 1, 0.0, prinList.getVisibleRowCount(), GridBagConstraints.BOTH,
       
  1916                            ToolWindow.BOTTOM_PADDING);
       
  1917 
       
  1918         // panel for permission buttons
       
  1919         panel = new JPanel();
       
  1920         panel.setLayout(new GridBagLayout());
       
  1921 
       
  1922         button = new JButton();
       
  1923         ToolWindow.configureButton(button, ".Add.Permission");
       
  1924         button.addActionListener(new AddPermButtonListener
       
  1925                                                 (tool, tw, this, edit));
       
  1926         tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,
       
  1927                 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1928 
       
  1929         button = new JButton();
       
  1930         ToolWindow.configureButton(button, ".Edit.Permission");
       
  1931         button.addActionListener(new EditPermButtonListener
       
  1932                                                 (tool, tw, this, edit));
       
  1933         tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,
       
  1934                 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1935 
       
  1936 
       
  1937         button = new JButton();
       
  1938         ToolWindow.configureButton(button, "Remove.Permission");
       
  1939         button.addActionListener(new RemovePermButtonListener
       
  1940                                         (tool, tw, this, edit));
       
  1941         tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,
       
  1942                 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
       
  1943 
       
  1944         tw.addNewComponent(this, panel, PE_PANEL1,
       
  1945                 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
       
  1946                 ToolWindow.LITE_BOTTOM_PADDING);
       
  1947 
       
  1948         // permission list
       
  1949         scrollPane = new JScrollPane(permList);
       
  1950         tw.addNewComponent(this, scrollPane, PE_PERM_LIST,
       
  1951                            0, 5, 3, 1, 0.0, permList.getVisibleRowCount(), GridBagConstraints.BOTH,
       
  1952                            ToolWindow.BOTTOM_PADDING);
       
  1953 
       
  1954 
       
  1955         // panel for Done and Cancel buttons
       
  1956         panel = new JPanel();
       
  1957         panel.setLayout(new GridBagLayout());
       
  1958 
       
  1959         // Done Button
       
  1960         JButton okButton = new JButton(PolicyTool.getMessage("Done"));
       
  1961         okButton.addActionListener
       
  1962                 (new AddEntryDoneButtonListener(tool, tw, this, edit));
       
  1963         tw.addNewComponent(panel, okButton, PE_DONE_BUTTON,
       
  1964                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  1965                            ToolWindow.LR_PADDING);
       
  1966 
       
  1967         // Cancel Button
       
  1968         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
       
  1969         ActionListener cancelListener = new CancelButtonListener(this);
       
  1970         cancelButton.addActionListener(cancelListener);
       
  1971         tw.addNewComponent(panel, cancelButton, PE_CANCEL_BUTTON,
       
  1972                            1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  1973                            ToolWindow.LR_PADDING);
       
  1974 
       
  1975         // add the panel
       
  1976         tw.addNewComponent(this, panel, PE_PANEL2,
       
  1977                 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  1978 
       
  1979         getRootPane().setDefaultButton(okButton);
       
  1980         getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  1981 
       
  1982         pack();
       
  1983         setLocationRelativeTo(tw);
       
  1984         setVisible(true);
       
  1985     }
       
  1986 
       
  1987     /**
       
  1988      * Read all the Policy information data in the dialog box
       
  1989      * and construct a PolicyEntry object with it.
       
  1990      */
       
  1991     PolicyEntry getPolicyEntryFromDialog()
       
  1992         throws InvalidParameterException, MalformedURLException,
       
  1993         NoSuchMethodException, ClassNotFoundException, InstantiationException,
       
  1994         IllegalAccessException, InvocationTargetException,
       
  1995         CertificateException, IOException, Exception {
       
  1996 
       
  1997         // get the Codebase
       
  1998         JTextField tf = (JTextField)getComponent(PE_CODEBASE_TEXTFIELD);
       
  1999         String codebase = null;
       
  2000         if (tf.getText().trim().equals("") == false)
       
  2001                 codebase = new String(tf.getText().trim());
       
  2002 
       
  2003         // get the SignedBy
       
  2004         tf = (JTextField)getComponent(PE_SIGNEDBY_TEXTFIELD);
       
  2005         String signedby = null;
       
  2006         if (tf.getText().trim().equals("") == false)
       
  2007                 signedby = new String(tf.getText().trim());
       
  2008 
       
  2009         // construct a new GrantEntry
       
  2010         PolicyParser.GrantEntry ge =
       
  2011                         new PolicyParser.GrantEntry(signedby, codebase);
       
  2012 
       
  2013         // get the new Principals
       
  2014         LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();
       
  2015         TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
       
  2016         for (int i = 0; i < prinList.getModel().getSize(); i++) {
       
  2017             prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));
       
  2018         }
       
  2019         ge.principals = prins;
       
  2020 
       
  2021         // get the new Permissions
       
  2022         Vector<PolicyParser.PermissionEntry> perms = new Vector<>();
       
  2023         TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
       
  2024         for (int i = 0; i < permList.getModel().getSize(); i++) {
       
  2025             perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));
       
  2026         }
       
  2027         ge.permissionEntries = perms;
       
  2028 
       
  2029         // construct a new PolicyEntry object
       
  2030         PolicyEntry entry = new PolicyEntry(tool, ge);
       
  2031 
       
  2032         return entry;
       
  2033     }
       
  2034 
       
  2035     /**
       
  2036      * display a dialog box for the user to enter KeyStore information
       
  2037      */
       
  2038     void keyStoreDialog(int mode) {
       
  2039 
       
  2040         // find where the PolicyTool gui is
       
  2041         Point location = tw.getLocationOnScreen();
       
  2042         //setBounds(location.x + 25, location.y + 100, 500, 300);
       
  2043         setLayout(new GridBagLayout());
       
  2044 
       
  2045         if (mode == EDIT_KEYSTORE) {
       
  2046 
       
  2047             // KeyStore label and textfield
       
  2048             JLabel label = new JLabel();
       
  2049             tw.addNewComponent(this, label, KSD_NAME_LABEL,
       
  2050                                0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2051                                ToolWindow.R_BOTTOM_PADDING);
       
  2052             JTextField tf = new JTextField(tool.getKeyStoreName(), 30);
       
  2053             ToolWindow.configureLabelFor(label, tf, "KeyStore.URL.");
       
  2054             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2055 
       
  2056             // URL to U R L, so that accessibility reader will pronounce well
       
  2057             tf.getAccessibleContext().setAccessibleName(
       
  2058                 PolicyTool.getMessage("KeyStore.U.R.L."));
       
  2059             tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,
       
  2060                                1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2061                                ToolWindow.BOTTOM_PADDING);
       
  2062 
       
  2063             // KeyStore type and textfield
       
  2064             label = new JLabel();
       
  2065             tw.addNewComponent(this, label, KSD_TYPE_LABEL,
       
  2066                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2067                                ToolWindow.R_BOTTOM_PADDING);
       
  2068             tf = new JTextField(tool.getKeyStoreType(), 30);
       
  2069             ToolWindow.configureLabelFor(label, tf, "KeyStore.Type.");
       
  2070             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2071             tf.getAccessibleContext().setAccessibleName(
       
  2072                 PolicyTool.getMessage("KeyStore.Type."));
       
  2073             tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,
       
  2074                                1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2075                                ToolWindow.BOTTOM_PADDING);
       
  2076 
       
  2077             // KeyStore provider and textfield
       
  2078             label = new JLabel();
       
  2079             tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,
       
  2080                                0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2081                                ToolWindow.R_BOTTOM_PADDING);
       
  2082             tf = new JTextField(tool.getKeyStoreProvider(), 30);
       
  2083             ToolWindow.configureLabelFor(label, tf, "KeyStore.Provider.");
       
  2084             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2085             tf.getAccessibleContext().setAccessibleName(
       
  2086                 PolicyTool.getMessage("KeyStore.Provider."));
       
  2087             tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,
       
  2088                                1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2089                                ToolWindow.BOTTOM_PADDING);
       
  2090 
       
  2091             // KeyStore password URL and textfield
       
  2092             label = new JLabel();
       
  2093             tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,
       
  2094                                0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2095                                ToolWindow.R_BOTTOM_PADDING);
       
  2096             tf = new JTextField(tool.getKeyStorePwdURL(), 30);
       
  2097             ToolWindow.configureLabelFor(label, tf, "KeyStore.Password.URL.");
       
  2098             tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2099             tf.getAccessibleContext().setAccessibleName(
       
  2100                 PolicyTool.getMessage("KeyStore.Password.U.R.L."));
       
  2101             tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,
       
  2102                                1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2103                                ToolWindow.BOTTOM_PADDING);
       
  2104 
       
  2105             // OK button
       
  2106             JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  2107             okButton.addActionListener
       
  2108                         (new ChangeKeyStoreOKButtonListener(tool, tw, this));
       
  2109             tw.addNewComponent(this, okButton, KSD_OK_BUTTON,
       
  2110                         0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  2111 
       
  2112             // cancel button
       
  2113             JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
       
  2114             ActionListener cancelListener = new CancelButtonListener(this);
       
  2115             cancelButton.addActionListener(cancelListener);
       
  2116             tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,
       
  2117                         1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
       
  2118 
       
  2119             getRootPane().setDefaultButton(okButton);
       
  2120             getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2121         }
       
  2122 
       
  2123         pack();
       
  2124         setLocationRelativeTo(tw);
       
  2125         setVisible(true);
       
  2126     }
       
  2127 
       
  2128     /**
       
  2129      * display a dialog box for the user to input Principal info
       
  2130      *
       
  2131      * if editPolicyEntry is false, then we are adding Principals to
       
  2132      * a new PolicyEntry, and we only update the GUI listing
       
  2133      * with the new Principal.
       
  2134      *
       
  2135      * if edit is true, then we are editing an existing Policy entry.
       
  2136      */
       
  2137     void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) {
       
  2138 
       
  2139         PolicyParser.PrincipalEntry editMe = null;
       
  2140 
       
  2141         // get the Principal selected from the Principal List
       
  2142         TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
       
  2143         int prinIndex = prinList.getSelectedIndex();
       
  2144 
       
  2145         if (edit) {
       
  2146             editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex);
       
  2147         }
       
  2148 
       
  2149         ToolDialog newTD = new ToolDialog
       
  2150                 (PolicyTool.getMessage("Principals"), tool, tw, true);
       
  2151         newTD.addWindowListener(new ChildWindowListener(newTD));
       
  2152 
       
  2153         // find where the PolicyTool gui is
       
  2154         Point location = getLocationOnScreen();
       
  2155         //newTD.setBounds(location.x + 50, location.y + 100, 650, 190);
       
  2156         newTD.setLayout(new GridBagLayout());
       
  2157         newTD.setResizable(true);
       
  2158 
       
  2159         // description label
       
  2160         JLabel label = (edit ?
       
  2161                 new JLabel(PolicyTool.getMessage(".Edit.Principal.")) :
       
  2162                 new JLabel(PolicyTool.getMessage(".Add.New.Principal.")));
       
  2163         tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
       
  2164                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2165                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2166 
       
  2167         // principal choice
       
  2168         JComboBox<String> choice = new JComboBox<>();
       
  2169         choice.addItem(PRIN_TYPE);
       
  2170         choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
       
  2171         for (int i = 0; i < PRIN_ARRAY.size(); i++) {
       
  2172             Prin next = PRIN_ARRAY.get(i);
       
  2173             choice.addItem(next.CLASS);
       
  2174         }
       
  2175 
       
  2176         if (edit) {
       
  2177             if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals
       
  2178                                 (editMe.getPrincipalClass())) {
       
  2179                 choice.setSelectedItem(PRIN_TYPE);
       
  2180             } else {
       
  2181                 Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
       
  2182                 if (inputPrin != null) {
       
  2183                     choice.setSelectedItem(inputPrin.CLASS);
       
  2184                 }
       
  2185             }
       
  2186         }
       
  2187         // Add listener after selected item is set
       
  2188         choice.addItemListener(new PrincipalTypeMenuListener(newTD));
       
  2189 
       
  2190         tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,
       
  2191                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2192                            ToolWindow.LR_PADDING);
       
  2193 
       
  2194         // principal textfield
       
  2195         JTextField tf;
       
  2196         tf = (edit ?
       
  2197                 new JTextField(editMe.getDisplayClass(), 30) :
       
  2198                 new JTextField(30));
       
  2199         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2200         tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);
       
  2201         tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,
       
  2202                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2203                            ToolWindow.LR_PADDING);
       
  2204 
       
  2205         // name label and textfield
       
  2206         label = new JLabel(PRIN_NAME);
       
  2207         tf = (edit ?
       
  2208                 new JTextField(editMe.getDisplayName(), 40) :
       
  2209                 new JTextField(40));
       
  2210         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2211         tf.getAccessibleContext().setAccessibleName(PRIN_NAME);
       
  2212 
       
  2213         tw.addNewComponent(newTD, label, PRD_NAME_LABEL,
       
  2214                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2215                            ToolWindow.LR_PADDING);
       
  2216         tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,
       
  2217                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2218                            ToolWindow.LR_PADDING);
       
  2219 
       
  2220         // OK button
       
  2221         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  2222         okButton.addActionListener(
       
  2223             new NewPolicyPrinOKButtonListener
       
  2224                                         (tool, tw, this, newTD, edit));
       
  2225         tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON,
       
  2226                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  2227                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2228         // cancel button
       
  2229         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
       
  2230         ActionListener cancelListener = new CancelButtonListener(newTD);
       
  2231         cancelButton.addActionListener(cancelListener);
       
  2232         tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,
       
  2233                            1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  2234                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2235 
       
  2236         newTD.getRootPane().setDefaultButton(okButton);
       
  2237         newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2238 
       
  2239         newTD.pack();
       
  2240         newTD.setLocationRelativeTo(tw);
       
  2241         newTD.setVisible(true);
       
  2242     }
       
  2243 
       
  2244     /**
       
  2245      * display a dialog box for the user to input Permission info
       
  2246      *
       
  2247      * if editPolicyEntry is false, then we are adding Permissions to
       
  2248      * a new PolicyEntry, and we only update the GUI listing
       
  2249      * with the new Permission.
       
  2250      *
       
  2251      * if edit is true, then we are editing an existing Permission entry.
       
  2252      */
       
  2253     void displayPermissionDialog(boolean editPolicyEntry, boolean edit) {
       
  2254 
       
  2255         PolicyParser.PermissionEntry editMe = null;
       
  2256 
       
  2257         // get the Permission selected from the Permission List
       
  2258         TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
       
  2259         int permIndex = permList.getSelectedIndex();
       
  2260 
       
  2261         if (edit) {
       
  2262             editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex);
       
  2263         }
       
  2264 
       
  2265         ToolDialog newTD = new ToolDialog
       
  2266                 (PolicyTool.getMessage("Permissions"), tool, tw, true);
       
  2267         newTD.addWindowListener(new ChildWindowListener(newTD));
       
  2268 
       
  2269         // find where the PolicyTool gui is
       
  2270         Point location = getLocationOnScreen();
       
  2271         //newTD.setBounds(location.x + 50, location.y + 100, 700, 250);
       
  2272         newTD.setLayout(new GridBagLayout());
       
  2273         newTD.setResizable(true);
       
  2274 
       
  2275         // description label
       
  2276         JLabel label = (edit ?
       
  2277                 new JLabel(PolicyTool.getMessage(".Edit.Permission.")) :
       
  2278                 new JLabel(PolicyTool.getMessage(".Add.New.Permission.")));
       
  2279         tw.addNewComponent(newTD, label, PD_DESC_LABEL,
       
  2280                            0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2281                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2282 
       
  2283         // permission choice (added in alphabetical order)
       
  2284         JComboBox<String> choice = new JComboBox<>();
       
  2285         choice.addItem(PERM);
       
  2286         choice.getAccessibleContext().setAccessibleName(PERM);
       
  2287         for (int i = 0; i < PERM_ARRAY.size(); i++) {
       
  2288             Perm next = PERM_ARRAY.get(i);
       
  2289             choice.addItem(next.CLASS);
       
  2290         }
       
  2291         tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
       
  2292                            0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2293                            ToolWindow.LR_BOTTOM_PADDING);
       
  2294 
       
  2295         // permission textfield
       
  2296         JTextField tf;
       
  2297         tf = (edit ? new JTextField(editMe.permission, 30) : new JTextField(30));
       
  2298         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2299         tf.getAccessibleContext().setAccessibleName(PERM);
       
  2300         if (edit) {
       
  2301             Perm inputPerm = getPerm(editMe.permission, true);
       
  2302             if (inputPerm != null) {
       
  2303                 choice.setSelectedItem(inputPerm.CLASS);
       
  2304             }
       
  2305         }
       
  2306         tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
       
  2307                            1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2308                            ToolWindow.LR_BOTTOM_PADDING);
       
  2309         choice.addItemListener(new PermissionMenuListener(newTD));
       
  2310 
       
  2311         // name label and textfield
       
  2312         choice = new JComboBox<>();
       
  2313         choice.addItem(PERM_NAME);
       
  2314         choice.getAccessibleContext().setAccessibleName(PERM_NAME);
       
  2315         tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));
       
  2316         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2317         tf.getAccessibleContext().setAccessibleName(PERM_NAME);
       
  2318         if (edit) {
       
  2319             setPermissionNames(getPerm(editMe.permission, true), choice, tf);
       
  2320         }
       
  2321         tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,
       
  2322                            0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2323                            ToolWindow.LR_BOTTOM_PADDING);
       
  2324         tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,
       
  2325                            1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2326                            ToolWindow.LR_BOTTOM_PADDING);
       
  2327         choice.addItemListener(new PermissionNameMenuListener(newTD));
       
  2328 
       
  2329         // actions label and textfield
       
  2330         choice = new JComboBox<>();
       
  2331         choice.addItem(PERM_ACTIONS);
       
  2332         choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
       
  2333         tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));
       
  2334         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2335         tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
       
  2336         if (edit) {
       
  2337             setPermissionActions(getPerm(editMe.permission, true), choice, tf);
       
  2338         }
       
  2339         tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,
       
  2340                            0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2341                            ToolWindow.LR_BOTTOM_PADDING);
       
  2342         tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,
       
  2343                            1, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2344                            ToolWindow.LR_BOTTOM_PADDING);
       
  2345         choice.addItemListener(new PermissionActionsMenuListener(newTD));
       
  2346 
       
  2347         // signedby label and textfield
       
  2348         label = new JLabel(PolicyTool.getMessage("Signed.By."));
       
  2349         tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,
       
  2350                            0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2351                            ToolWindow.LR_BOTTOM_PADDING);
       
  2352         tf = (edit ? new JTextField(editMe.signedBy, 40) : new JTextField(40));
       
  2353         tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));
       
  2354         tf.getAccessibleContext().setAccessibleName(
       
  2355                 PolicyTool.getMessage("Signed.By."));
       
  2356         tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,
       
  2357                            1, 4, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,
       
  2358                            ToolWindow.LR_BOTTOM_PADDING);
       
  2359 
       
  2360         // OK button
       
  2361         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  2362         okButton.addActionListener(
       
  2363             new NewPolicyPermOKButtonListener
       
  2364                                     (tool, tw, this, newTD, edit));
       
  2365         tw.addNewComponent(newTD, okButton, PD_OK_BUTTON,
       
  2366                            0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  2367                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2368 
       
  2369         // cancel button
       
  2370         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
       
  2371         ActionListener cancelListener = new CancelButtonListener(newTD);
       
  2372         cancelButton.addActionListener(cancelListener);
       
  2373         tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,
       
  2374                            1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
       
  2375                            ToolWindow.TOP_BOTTOM_PADDING);
       
  2376 
       
  2377         newTD.getRootPane().setDefaultButton(okButton);
       
  2378         newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2379 
       
  2380         newTD.pack();
       
  2381         newTD.setLocationRelativeTo(tw);
       
  2382         newTD.setVisible(true);
       
  2383     }
       
  2384 
       
  2385     /**
       
  2386      * construct a Principal object from the Principal Info Dialog Box
       
  2387      */
       
  2388     PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {
       
  2389 
       
  2390         JTextField tf = (JTextField)getComponent(PRD_PRIN_TEXTFIELD);
       
  2391         String pclass = new String(tf.getText().trim());
       
  2392         tf = (JTextField)getComponent(PRD_NAME_TEXTFIELD);
       
  2393         String pname = new String(tf.getText().trim());
       
  2394         if (pclass.equals("*")) {
       
  2395             pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;
       
  2396         }
       
  2397         if (pname.equals("*")) {
       
  2398             pname = PolicyParser.PrincipalEntry.WILDCARD_NAME;
       
  2399         }
       
  2400 
       
  2401         PolicyParser.PrincipalEntry pppe = null;
       
  2402 
       
  2403         if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&
       
  2404             (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {
       
  2405             throw new Exception
       
  2406                         (PolicyTool.getMessage("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));
       
  2407         } else if (pname.equals("")) {
       
  2408             throw new Exception
       
  2409                         (PolicyTool.getMessage("Cannot.Specify.Principal.without.a.Name"));
       
  2410         } else if (pclass.equals("")) {
       
  2411             // make this consistent with what PolicyParser does
       
  2412             // when it sees an empty principal class
       
  2413             pclass = PolicyParser.PrincipalEntry.REPLACE_NAME;
       
  2414             tool.warnings.addElement(
       
  2415                         "Warning: Principal name '" + pname +
       
  2416                                 "' specified without a Principal class.\n" +
       
  2417                         "\t'" + pname + "' will be interpreted " +
       
  2418                                 "as a key store alias.\n" +
       
  2419                         "\tThe final principal class will be " +
       
  2420                                 ToolDialog.X500_PRIN_CLASS + ".\n" +
       
  2421                         "\tThe final principal name will be " +
       
  2422                                 "determined by the following:\n" +
       
  2423                         "\n" +
       
  2424                         "\tIf the key store entry identified by '"
       
  2425                                 + pname + "'\n" +
       
  2426                         "\tis a key entry, then the principal name will be\n" +
       
  2427                         "\tthe subject distinguished name from the first\n" +
       
  2428                         "\tcertificate in the entry's certificate chain.\n" +
       
  2429                         "\n" +
       
  2430                         "\tIf the key store entry identified by '" +
       
  2431                                 pname + "'\n" +
       
  2432                         "\tis a trusted certificate entry, then the\n" +
       
  2433                         "\tprincipal name will be the subject distinguished\n" +
       
  2434                         "\tname from the trusted public key certificate.");
       
  2435             tw.displayStatusDialog(this,
       
  2436                         "'" + pname + "' will be interpreted as a key " +
       
  2437                         "store alias.  View Warning Log for details.");
       
  2438         }
       
  2439         return new PolicyParser.PrincipalEntry(pclass, pname);
       
  2440     }
       
  2441 
       
  2442 
       
  2443     /**
       
  2444      * construct a Permission object from the Permission Info Dialog Box
       
  2445      */
       
  2446     PolicyParser.PermissionEntry getPermFromDialog() {
       
  2447 
       
  2448         JTextField tf = (JTextField)getComponent(PD_PERM_TEXTFIELD);
       
  2449         String permission = new String(tf.getText().trim());
       
  2450         tf = (JTextField)getComponent(PD_NAME_TEXTFIELD);
       
  2451         String name = null;
       
  2452         if (tf.getText().trim().equals("") == false)
       
  2453             name = new String(tf.getText().trim());
       
  2454         if (permission.equals("") ||
       
  2455             (!permission.equals(ALL_PERM_CLASS) && name == null)) {
       
  2456             throw new InvalidParameterException(PolicyTool.getMessage
       
  2457                 ("Permission.and.Target.Name.must.have.a.value"));
       
  2458         }
       
  2459 
       
  2460         // When the permission is FilePermission, we need to check the name
       
  2461         // to make sure it's not escaped. We believe --
       
  2462         //
       
  2463         // String             name.lastIndexOf("\\\\")
       
  2464         // ----------------   ------------------------
       
  2465         // c:\foo\bar         -1, legal
       
  2466         // c:\\foo\\bar       2, illegal
       
  2467         // \\server\share     0, legal
       
  2468         // \\\\server\share   2, illegal
       
  2469 
       
  2470         if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
       
  2471             char result = tw.displayYesNoDialog(this,
       
  2472                     PolicyTool.getMessage("Warning"),
       
  2473                     PolicyTool.getMessage(
       
  2474                         "Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),
       
  2475                     PolicyTool.getMessage("Retain"),
       
  2476                     PolicyTool.getMessage("Edit")
       
  2477                     );
       
  2478             if (result != 'Y') {
       
  2479                 // an invisible exception
       
  2480                 throw new NoDisplayException();
       
  2481             }
       
  2482         }
       
  2483         // get the Actions
       
  2484         tf = (JTextField)getComponent(PD_ACTIONS_TEXTFIELD);
       
  2485         String actions = null;
       
  2486         if (tf.getText().trim().equals("") == false)
       
  2487             actions = new String(tf.getText().trim());
       
  2488 
       
  2489         // get the Signed By
       
  2490         tf = (JTextField)getComponent(PD_SIGNEDBY_TEXTFIELD);
       
  2491         String signedBy = null;
       
  2492         if (tf.getText().trim().equals("") == false)
       
  2493             signedBy = new String(tf.getText().trim());
       
  2494 
       
  2495         PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry
       
  2496                                 (permission, name, actions);
       
  2497         pppe.signedBy = signedBy;
       
  2498 
       
  2499         // see if the signers have public keys
       
  2500         if (signedBy != null) {
       
  2501                 String signers[] = tool.parseSigners(pppe.signedBy);
       
  2502                 for (int i = 0; i < signers.length; i++) {
       
  2503                 try {
       
  2504                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
       
  2505                     if (pubKey == null) {
       
  2506                         MessageFormat form = new MessageFormat
       
  2507                             (PolicyTool.getMessage
       
  2508                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
       
  2509                         Object[] source = {signers[i]};
       
  2510                         tool.warnings.addElement(form.format(source));
       
  2511                         tw.displayStatusDialog(this, form.format(source));
       
  2512                     }
       
  2513                 } catch (Exception e) {
       
  2514                     tw.displayErrorDialog(this, e);
       
  2515                 }
       
  2516             }
       
  2517         }
       
  2518         return pppe;
       
  2519     }
       
  2520 
       
  2521     /**
       
  2522      * confirm that the user REALLY wants to remove the Policy Entry
       
  2523      */
       
  2524     void displayConfirmRemovePolicyEntry() {
       
  2525 
       
  2526         // find the entry to be removed
       
  2527         @SuppressWarnings("unchecked")
       
  2528         JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  2529         int index = list.getSelectedIndex();
       
  2530         PolicyEntry entries[] = tool.getEntry();
       
  2531 
       
  2532         // find where the PolicyTool gui is
       
  2533         Point location = tw.getLocationOnScreen();
       
  2534         //setBounds(location.x + 25, location.y + 100, 600, 400);
       
  2535         setLayout(new GridBagLayout());
       
  2536 
       
  2537         // ask the user do they really want to do this?
       
  2538         JLabel label = new JLabel
       
  2539                 (PolicyTool.getMessage("Remove.this.Policy.Entry."));
       
  2540         tw.addNewComponent(this, label, CRPE_LABEL1,
       
  2541                            0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2542                            ToolWindow.BOTTOM_PADDING);
       
  2543 
       
  2544         // display the policy entry
       
  2545         label = new JLabel(entries[index].codebaseToString());
       
  2546         tw.addNewComponent(this, label, CRPE_LABEL2,
       
  2547                         0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  2548         label = new JLabel(entries[index].principalsToString().trim());
       
  2549         tw.addNewComponent(this, label, CRPE_LABEL2+1,
       
  2550                         0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  2551         Vector<PolicyParser.PermissionEntry> perms =
       
  2552                         entries[index].getGrantEntry().permissionEntries;
       
  2553         for (int i = 0; i < perms.size(); i++) {
       
  2554             PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);
       
  2555             String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);
       
  2556             label = new JLabel("    " + permString);
       
  2557             if (i == (perms.size()-1)) {
       
  2558                 tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
       
  2559                                  1, 3 + i, 1, 1, 0.0, 0.0,
       
  2560                                  GridBagConstraints.BOTH,
       
  2561                                  ToolWindow.BOTTOM_PADDING);
       
  2562             } else {
       
  2563                 tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
       
  2564                                  1, 3 + i, 1, 1, 0.0, 0.0,
       
  2565                                  GridBagConstraints.BOTH);
       
  2566             }
       
  2567         }
       
  2568 
       
  2569 
       
  2570         // add OK/CANCEL buttons in a new panel
       
  2571         JPanel panel = new JPanel();
       
  2572         panel.setLayout(new GridBagLayout());
       
  2573 
       
  2574         // OK button
       
  2575         JButton okButton = new JButton(PolicyTool.getMessage("OK"));
       
  2576         okButton.addActionListener
       
  2577                 (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));
       
  2578         tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,
       
  2579                            0, 0, 1, 1, 0.0, 0.0,
       
  2580                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
       
  2581 
       
  2582         // cancel button
       
  2583         JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));
       
  2584         ActionListener cancelListener = new CancelButtonListener(this);
       
  2585         cancelButton.addActionListener(cancelListener);
       
  2586         tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,
       
  2587                            1, 0, 1, 1, 0.0, 0.0,
       
  2588                            GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);
       
  2589 
       
  2590         tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(),
       
  2591                            0, 3 + perms.size(), 2, 1, 0.0, 0.0,
       
  2592                            GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING);
       
  2593 
       
  2594         getRootPane().setDefaultButton(okButton);
       
  2595         getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2596 
       
  2597         pack();
       
  2598         setLocationRelativeTo(tw);
       
  2599         setVisible(true);
       
  2600     }
       
  2601 
       
  2602     /**
       
  2603      * perform SAVE AS
       
  2604      */
       
  2605     void displaySaveAsDialog(int nextEvent) {
       
  2606 
       
  2607         // pop up a dialog box for the user to enter a filename.
       
  2608         FileDialog fd = new FileDialog
       
  2609                 (tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);
       
  2610         fd.addWindowListener(new WindowAdapter() {
       
  2611             public void windowClosing(WindowEvent e) {
       
  2612                 e.getWindow().setVisible(false);
       
  2613             }
       
  2614         });
       
  2615         fd.setVisible(true);
       
  2616 
       
  2617         // see if the user hit cancel
       
  2618         if (fd.getFile() == null ||
       
  2619             fd.getFile().equals(""))
       
  2620             return;
       
  2621 
       
  2622         // get the entered filename
       
  2623         File saveAsFile = new File(fd.getDirectory(), fd.getFile());
       
  2624         String filename = saveAsFile.getPath();
       
  2625         fd.dispose();
       
  2626 
       
  2627         try {
       
  2628             // save the policy entries to a file
       
  2629             tool.savePolicy(filename);
       
  2630 
       
  2631             // display status
       
  2632             MessageFormat form = new MessageFormat(PolicyTool.getMessage
       
  2633                     ("Policy.successfully.written.to.filename"));
       
  2634             Object[] source = {filename};
       
  2635             tw.displayStatusDialog(null, form.format(source));
       
  2636 
       
  2637             // display the new policy filename
       
  2638             JTextField newFilename = (JTextField)tw.getComponent
       
  2639                             (ToolWindow.MW_FILENAME_TEXTFIELD);
       
  2640             newFilename.setText(filename);
       
  2641             tw.setVisible(true);
       
  2642 
       
  2643             // now continue with the originally requested command
       
  2644             // (QUIT, NEW, or OPEN)
       
  2645             userSaveContinue(tool, tw, this, nextEvent);
       
  2646 
       
  2647         } catch (FileNotFoundException fnfe) {
       
  2648             if (filename == null || filename.equals("")) {
       
  2649                 tw.displayErrorDialog(null, new FileNotFoundException
       
  2650                             (PolicyTool.getMessage("null.filename")));
       
  2651             } else {
       
  2652                 tw.displayErrorDialog(null, fnfe);
       
  2653             }
       
  2654         } catch (Exception ee) {
       
  2655             tw.displayErrorDialog(null, ee);
       
  2656         }
       
  2657     }
       
  2658 
       
  2659     /**
       
  2660      * ask user if they want to save changes
       
  2661      */
       
  2662     void displayUserSave(int select) {
       
  2663 
       
  2664         if (tool.modified == true) {
       
  2665 
       
  2666             // find where the PolicyTool gui is
       
  2667             Point location = tw.getLocationOnScreen();
       
  2668             //setBounds(location.x + 75, location.y + 100, 400, 150);
       
  2669             setLayout(new GridBagLayout());
       
  2670 
       
  2671             JLabel label = new JLabel
       
  2672                 (PolicyTool.getMessage("Save.changes."));
       
  2673             tw.addNewComponent(this, label, USC_LABEL,
       
  2674                                0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
       
  2675                                ToolWindow.L_TOP_BOTTOM_PADDING);
       
  2676 
       
  2677             JPanel panel = new JPanel();
       
  2678             panel.setLayout(new GridBagLayout());
       
  2679 
       
  2680             JButton yesButton = new JButton();
       
  2681             ToolWindow.configureButton(yesButton, "Yes");
       
  2682             yesButton.addActionListener
       
  2683                         (new UserSaveYesButtonListener(this, tool, tw, select));
       
  2684             tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,
       
  2685                                0, 0, 1, 1, 0.0, 0.0,
       
  2686                                GridBagConstraints.VERTICAL,
       
  2687                                ToolWindow.LR_BOTTOM_PADDING);
       
  2688             JButton noButton = new JButton();
       
  2689             ToolWindow.configureButton(noButton, "No");
       
  2690             noButton.addActionListener
       
  2691                         (new UserSaveNoButtonListener(this, tool, tw, select));
       
  2692             tw.addNewComponent(panel, noButton, USC_NO_BUTTON,
       
  2693                                1, 0, 1, 1, 0.0, 0.0,
       
  2694                                GridBagConstraints.VERTICAL,
       
  2695                                ToolWindow.LR_BOTTOM_PADDING);
       
  2696             JButton cancelButton = new JButton();
       
  2697             ToolWindow.configureButton(cancelButton, "Cancel");
       
  2698             ActionListener cancelListener = new CancelButtonListener(this);
       
  2699             cancelButton.addActionListener(cancelListener);
       
  2700             tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,
       
  2701                                2, 0, 1, 1, 0.0, 0.0,
       
  2702                                GridBagConstraints.VERTICAL,
       
  2703                                ToolWindow.LR_BOTTOM_PADDING);
       
  2704 
       
  2705             tw.addNewComponent(this, panel, USC_PANEL,
       
  2706                                0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
       
  2707 
       
  2708             getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);
       
  2709 
       
  2710             pack();
       
  2711             setLocationRelativeTo(tw);
       
  2712             setVisible(true);
       
  2713         } else {
       
  2714             // just do the original request (QUIT, NEW, or OPEN)
       
  2715             userSaveContinue(tool, tw, this, select);
       
  2716         }
       
  2717     }
       
  2718 
       
  2719     /**
       
  2720      * when the user sees the 'YES', 'NO', 'CANCEL' buttons on the
       
  2721      * displayUserSave dialog, and the click on one of them,
       
  2722      * we need to continue the originally requested action
       
  2723      * (either QUITting, opening NEW policy file, or OPENing an existing
       
  2724      * policy file.  do that now.
       
  2725      */
       
  2726     @SuppressWarnings("fallthrough")
       
  2727     void userSaveContinue(PolicyTool tool, ToolWindow tw,
       
  2728                         ToolDialog us, int select) {
       
  2729 
       
  2730         // now either QUIT, open a NEW policy file, or OPEN an existing policy
       
  2731         switch(select) {
       
  2732         case ToolDialog.QUIT:
       
  2733 
       
  2734             tw.setVisible(false);
       
  2735             tw.dispose();
       
  2736             System.exit(0);
       
  2737 
       
  2738         case ToolDialog.NEW:
       
  2739 
       
  2740             try {
       
  2741                 tool.openPolicy(null);
       
  2742             } catch (Exception ee) {
       
  2743                 tool.modified = false;
       
  2744                 tw.displayErrorDialog(null, ee);
       
  2745             }
       
  2746 
       
  2747             // display the policy entries via the policy list textarea
       
  2748             JList<String> list = new JList<>(new DefaultListModel<>());
       
  2749             list.setVisibleRowCount(15);
       
  2750             list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2751             list.addMouseListener(new PolicyListListener(tool, tw));
       
  2752             tw.replacePolicyList(list);
       
  2753 
       
  2754             // display null policy filename and keystore
       
  2755             JTextField newFilename = (JTextField)tw.getComponent(
       
  2756                     ToolWindow.MW_FILENAME_TEXTFIELD);
       
  2757             newFilename.setText("");
       
  2758             tw.setVisible(true);
       
  2759             break;
       
  2760 
       
  2761         case ToolDialog.OPEN:
       
  2762 
       
  2763             // pop up a dialog box for the user to enter a filename.
       
  2764             FileDialog fd = new FileDialog
       
  2765                 (tw, PolicyTool.getMessage("Open"), FileDialog.LOAD);
       
  2766             fd.addWindowListener(new WindowAdapter() {
       
  2767                 public void windowClosing(WindowEvent e) {
       
  2768                     e.getWindow().setVisible(false);
       
  2769                 }
       
  2770             });
       
  2771             fd.setVisible(true);
       
  2772 
       
  2773             // see if the user hit 'cancel'
       
  2774             if (fd.getFile() == null ||
       
  2775                 fd.getFile().equals(""))
       
  2776                 return;
       
  2777 
       
  2778             // get the entered filename
       
  2779             String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath();
       
  2780 
       
  2781             try {
       
  2782                 // open the policy file
       
  2783                 tool.openPolicy(policyFile);
       
  2784 
       
  2785                 // display the policy entries via the policy list textarea
       
  2786                 DefaultListModel<String> listModel = new DefaultListModel<>();
       
  2787                 list = new JList<>(listModel);
       
  2788                 list.setVisibleRowCount(15);
       
  2789                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2790                 list.addMouseListener(new PolicyListListener(tool, tw));
       
  2791                 PolicyEntry entries[] = tool.getEntry();
       
  2792                 if (entries != null) {
       
  2793                     for (int i = 0; i < entries.length; i++) {
       
  2794                         listModel.addElement(entries[i].headerToString());
       
  2795                     }
       
  2796                 }
       
  2797                 tw.replacePolicyList(list);
       
  2798                 tool.modified = false;
       
  2799 
       
  2800                 // display the new policy filename
       
  2801                 newFilename = (JTextField)tw.getComponent(
       
  2802                         ToolWindow.MW_FILENAME_TEXTFIELD);
       
  2803                 newFilename.setText(policyFile);
       
  2804                 tw.setVisible(true);
       
  2805 
       
  2806                 // inform user of warnings
       
  2807                 if (tool.newWarning == true) {
       
  2808                     tw.displayStatusDialog(null, PolicyTool.getMessage
       
  2809                         ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
       
  2810                 }
       
  2811 
       
  2812             } catch (Exception e) {
       
  2813                 // add blank policy listing
       
  2814                 list = new JList<>(new DefaultListModel<>());
       
  2815                 list.setVisibleRowCount(15);
       
  2816                 list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  2817                 list.addMouseListener(new PolicyListListener(tool, tw));
       
  2818                 tw.replacePolicyList(list);
       
  2819                 tool.setPolicyFileName(null);
       
  2820                 tool.modified = false;
       
  2821 
       
  2822                 // display a null policy filename
       
  2823                 newFilename = (JTextField)tw.getComponent(
       
  2824                         ToolWindow.MW_FILENAME_TEXTFIELD);
       
  2825                 newFilename.setText("");
       
  2826                 tw.setVisible(true);
       
  2827 
       
  2828                 // display the error
       
  2829                 MessageFormat form = new MessageFormat(PolicyTool.getMessage
       
  2830                     ("Could.not.open.policy.file.policyFile.e.toString."));
       
  2831                 Object[] source = {policyFile, e.toString()};
       
  2832                 tw.displayErrorDialog(null, form.format(source));
       
  2833             }
       
  2834             break;
       
  2835         }
       
  2836     }
       
  2837 
       
  2838     /**
       
  2839      * Return a Menu list of names for a given permission
       
  2840      *
       
  2841      * If inputPerm's TARGETS are null, then this means TARGETS are
       
  2842      * not allowed to be entered (and the TextField is set to be
       
  2843      * non-editable).
       
  2844      *
       
  2845      * If TARGETS are valid but there are no standard ones
       
  2846      * (user must enter them by hand) then the TARGETS array may be empty
       
  2847      * (and of course non-null).
       
  2848      */
       
  2849     void setPermissionNames(Perm inputPerm, JComboBox<String> names, JTextField field) {
       
  2850         names.removeAllItems();
       
  2851         names.addItem(PERM_NAME);
       
  2852 
       
  2853         if (inputPerm == null) {
       
  2854             // custom permission
       
  2855             field.setEditable(true);
       
  2856         } else if (inputPerm.TARGETS == null) {
       
  2857             // standard permission with no targets
       
  2858             field.setEditable(false);
       
  2859         } else {
       
  2860             // standard permission with standard targets
       
  2861             field.setEditable(true);
       
  2862             for (int i = 0; i < inputPerm.TARGETS.length; i++) {
       
  2863                 names.addItem(inputPerm.TARGETS[i]);
       
  2864             }
       
  2865         }
       
  2866     }
       
  2867 
       
  2868     /**
       
  2869      * Return a Menu list of actions for a given permission
       
  2870      *
       
  2871      * If inputPerm's ACTIONS are null, then this means ACTIONS are
       
  2872      * not allowed to be entered (and the TextField is set to be
       
  2873      * non-editable).  This is typically true for BasicPermissions.
       
  2874      *
       
  2875      * If ACTIONS are valid but there are no standard ones
       
  2876      * (user must enter them by hand) then the ACTIONS array may be empty
       
  2877      * (and of course non-null).
       
  2878      */
       
  2879     void setPermissionActions(Perm inputPerm, JComboBox<String> actions, JTextField field) {
       
  2880         actions.removeAllItems();
       
  2881         actions.addItem(PERM_ACTIONS);
       
  2882 
       
  2883         if (inputPerm == null) {
       
  2884             // custom permission
       
  2885             field.setEditable(true);
       
  2886         } else if (inputPerm.ACTIONS == null) {
       
  2887             // standard permission with no actions
       
  2888             field.setEditable(false);
       
  2889         } else {
       
  2890             // standard permission with standard actions
       
  2891             field.setEditable(true);
       
  2892             for (int i = 0; i < inputPerm.ACTIONS.length; i++) {
       
  2893                 actions.addItem(inputPerm.ACTIONS[i]);
       
  2894             }
       
  2895         }
       
  2896     }
       
  2897 
       
  2898     static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) {
       
  2899         String result = pppe.permission;
       
  2900         if (pppe.name != null) {
       
  2901             result += " " + pppe.name;
       
  2902         }
       
  2903         if (pppe.action != null) {
       
  2904             result += ", \"" + pppe.action + "\"";
       
  2905         }
       
  2906         if (pppe.signedBy != null) {
       
  2907             result += ", signedBy " + pppe.signedBy;
       
  2908         }
       
  2909         return result;
       
  2910     }
       
  2911 
       
  2912     static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) {
       
  2913         StringWriter sw = new StringWriter();
       
  2914         PrintWriter pw = new PrintWriter(sw);
       
  2915         pppe.write(pw);
       
  2916         return sw.toString();
       
  2917     }
       
  2918 }
       
  2919 
       
  2920 /**
       
  2921  * Event handler for the PolicyTool window
       
  2922  */
       
  2923 class ToolWindowListener implements WindowListener {
       
  2924 
       
  2925     private PolicyTool tool;
       
  2926     private ToolWindow tw;
       
  2927 
       
  2928     ToolWindowListener(PolicyTool tool, ToolWindow tw) {
       
  2929         this.tool = tool;
       
  2930         this.tw = tw;
       
  2931     }
       
  2932 
       
  2933     public void windowOpened(WindowEvent we) {
       
  2934     }
       
  2935 
       
  2936     public void windowClosing(WindowEvent we) {
       
  2937         // Closing the window acts the same as choosing Menu->Exit.
       
  2938 
       
  2939         // ask user if they want to save changes
       
  2940         ToolDialog td = new ToolDialog(PolicyTool.getMessage("Save.Changes"), tool, tw, true);
       
  2941         td.displayUserSave(ToolDialog.QUIT);
       
  2942 
       
  2943         // the above method will perform the QUIT as long as the
       
  2944         // user does not CANCEL the request
       
  2945     }
       
  2946 
       
  2947     public void windowClosed(WindowEvent we) {
       
  2948         System.exit(0);
       
  2949     }
       
  2950 
       
  2951     public void windowIconified(WindowEvent we) {
       
  2952     }
       
  2953 
       
  2954     public void windowDeiconified(WindowEvent we) {
       
  2955     }
       
  2956 
       
  2957     public void windowActivated(WindowEvent we) {
       
  2958     }
       
  2959 
       
  2960     public void windowDeactivated(WindowEvent we) {
       
  2961     }
       
  2962 }
       
  2963 
       
  2964 /**
       
  2965  * Event handler for the Policy List
       
  2966  */
       
  2967 class PolicyListListener extends MouseAdapter implements ActionListener {
       
  2968 
       
  2969     private PolicyTool tool;
       
  2970     private ToolWindow tw;
       
  2971 
       
  2972     PolicyListListener(PolicyTool tool, ToolWindow tw) {
       
  2973         this.tool = tool;
       
  2974         this.tw = tw;
       
  2975 
       
  2976     }
       
  2977 
       
  2978     public void actionPerformed(ActionEvent e) {
       
  2979 
       
  2980         // display the permission list for a policy entry
       
  2981         ToolDialog td = new ToolDialog
       
  2982                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
       
  2983         td.displayPolicyEntryDialog(true);
       
  2984     }
       
  2985 
       
  2986     public void mouseClicked(MouseEvent evt) {
       
  2987         if (evt.getClickCount() == 2) {
       
  2988             actionPerformed(null);
       
  2989         }
       
  2990     }
       
  2991 }
       
  2992 
       
  2993 /**
       
  2994  * Event handler for the File Menu
       
  2995  */
       
  2996 class FileMenuListener implements ActionListener {
       
  2997 
       
  2998     private PolicyTool tool;
       
  2999     private ToolWindow tw;
       
  3000 
       
  3001     FileMenuListener(PolicyTool tool, ToolWindow tw) {
       
  3002         this.tool = tool;
       
  3003         this.tw = tw;
       
  3004     }
       
  3005 
       
  3006     public void actionPerformed(ActionEvent e) {
       
  3007 
       
  3008         if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3009                                        ToolWindow.QUIT) == 0) {
       
  3010 
       
  3011             // ask user if they want to save changes
       
  3012             ToolDialog td = new ToolDialog
       
  3013                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
       
  3014             td.displayUserSave(ToolDialog.QUIT);
       
  3015 
       
  3016             // the above method will perform the QUIT as long as the
       
  3017             // user does not CANCEL the request
       
  3018 
       
  3019         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3020                                    ToolWindow.NEW_POLICY_FILE) == 0) {
       
  3021 
       
  3022             // ask user if they want to save changes
       
  3023             ToolDialog td = new ToolDialog
       
  3024                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
       
  3025             td.displayUserSave(ToolDialog.NEW);
       
  3026 
       
  3027             // the above method will perform the NEW as long as the
       
  3028             // user does not CANCEL the request
       
  3029 
       
  3030         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3031                                   ToolWindow.OPEN_POLICY_FILE) == 0) {
       
  3032 
       
  3033             // ask user if they want to save changes
       
  3034             ToolDialog td = new ToolDialog
       
  3035                 (PolicyTool.getMessage("Save.Changes"), tool, tw, true);
       
  3036             td.displayUserSave(ToolDialog.OPEN);
       
  3037 
       
  3038             // the above method will perform the OPEN as long as the
       
  3039             // user does not CANCEL the request
       
  3040 
       
  3041         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3042                                   ToolWindow.SAVE_POLICY_FILE) == 0) {
       
  3043 
       
  3044             // get the previously entered filename
       
  3045             String filename = ((JTextField)tw.getComponent(
       
  3046                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
       
  3047 
       
  3048             // if there is no filename, do a SAVE_AS
       
  3049             if (filename == null || filename.length() == 0) {
       
  3050                 // user wants to SAVE AS
       
  3051                 ToolDialog td = new ToolDialog
       
  3052                         (PolicyTool.getMessage("Save.As"), tool, tw, true);
       
  3053                 td.displaySaveAsDialog(ToolDialog.NOACTION);
       
  3054             } else {
       
  3055                 try {
       
  3056                     // save the policy entries to a file
       
  3057                     tool.savePolicy(filename);
       
  3058 
       
  3059                     // display status
       
  3060                     MessageFormat form = new MessageFormat
       
  3061                         (PolicyTool.getMessage
       
  3062                         ("Policy.successfully.written.to.filename"));
       
  3063                     Object[] source = {filename};
       
  3064                     tw.displayStatusDialog(null, form.format(source));
       
  3065                 } catch (FileNotFoundException fnfe) {
       
  3066                     if (filename == null || filename.equals("")) {
       
  3067                         tw.displayErrorDialog(null, new FileNotFoundException
       
  3068                                 (PolicyTool.getMessage("null.filename")));
       
  3069                     } else {
       
  3070                         tw.displayErrorDialog(null, fnfe);
       
  3071                     }
       
  3072                 } catch (Exception ee) {
       
  3073                     tw.displayErrorDialog(null, ee);
       
  3074                 }
       
  3075             }
       
  3076         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3077                                ToolWindow.SAVE_AS_POLICY_FILE) == 0) {
       
  3078 
       
  3079             // user wants to SAVE AS
       
  3080             ToolDialog td = new ToolDialog
       
  3081                 (PolicyTool.getMessage("Save.As"), tool, tw, true);
       
  3082             td.displaySaveAsDialog(ToolDialog.NOACTION);
       
  3083 
       
  3084         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3085                                      ToolWindow.VIEW_WARNINGS) == 0) {
       
  3086             tw.displayWarningLog(null);
       
  3087         }
       
  3088     }
       
  3089 }
       
  3090 
       
  3091 /**
       
  3092  * Event handler for the main window buttons and Edit Menu
       
  3093  */
       
  3094 class MainWindowListener implements ActionListener {
       
  3095 
       
  3096     private PolicyTool tool;
       
  3097     private ToolWindow tw;
       
  3098 
       
  3099     MainWindowListener(PolicyTool tool, ToolWindow tw) {
       
  3100         this.tool = tool;
       
  3101         this.tw = tw;
       
  3102     }
       
  3103 
       
  3104     public void actionPerformed(ActionEvent e) {
       
  3105 
       
  3106         if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3107                            ToolWindow.ADD_POLICY_ENTRY) == 0) {
       
  3108 
       
  3109             // display a dialog box for the user to enter policy info
       
  3110             ToolDialog td = new ToolDialog
       
  3111                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
       
  3112             td.displayPolicyEntryDialog(false);
       
  3113 
       
  3114         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3115                                ToolWindow.REMOVE_POLICY_ENTRY) == 0) {
       
  3116 
       
  3117             // get the selected entry
       
  3118             @SuppressWarnings("unchecked")
       
  3119             JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  3120             int index = list.getSelectedIndex();
       
  3121             if (index < 0) {
       
  3122                 tw.displayErrorDialog(null, new Exception
       
  3123                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
       
  3124                 return;
       
  3125             }
       
  3126 
       
  3127             // ask the user if they really want to remove the policy entry
       
  3128             ToolDialog td = new ToolDialog(PolicyTool.getMessage
       
  3129                 ("Remove.Policy.Entry"), tool, tw, true);
       
  3130             td.displayConfirmRemovePolicyEntry();
       
  3131 
       
  3132         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3133                                  ToolWindow.EDIT_POLICY_ENTRY) == 0) {
       
  3134 
       
  3135             // get the selected entry
       
  3136             @SuppressWarnings("unchecked")
       
  3137             JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  3138             int index = list.getSelectedIndex();
       
  3139             if (index < 0) {
       
  3140                 tw.displayErrorDialog(null, new Exception
       
  3141                         (PolicyTool.getMessage("No.Policy.Entry.selected")));
       
  3142                 return;
       
  3143             }
       
  3144 
       
  3145             // display the permission list for a policy entry
       
  3146             ToolDialog td = new ToolDialog
       
  3147                 (PolicyTool.getMessage("Policy.Entry"), tool, tw, true);
       
  3148             td.displayPolicyEntryDialog(true);
       
  3149 
       
  3150         } else if (PolicyTool.collator.compare(e.getActionCommand(),
       
  3151                                      ToolWindow.EDIT_KEYSTORE) == 0) {
       
  3152 
       
  3153             // display a dialog box for the user to enter keystore info
       
  3154             ToolDialog td = new ToolDialog
       
  3155                 (PolicyTool.getMessage("KeyStore"), tool, tw, true);
       
  3156             td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE);
       
  3157         }
       
  3158     }
       
  3159 }
       
  3160 
       
  3161 /**
       
  3162  * Event handler for AddEntryDoneButton button
       
  3163  *
       
  3164  * -- if edit is TRUE, then we are EDITing an existing PolicyEntry
       
  3165  *    and we need to update both the policy and the GUI listing.
       
  3166  *    if edit is FALSE, then we are ADDing a new PolicyEntry,
       
  3167  *    so we only need to update the GUI listing.
       
  3168  */
       
  3169 class AddEntryDoneButtonListener implements ActionListener {
       
  3170 
       
  3171     private PolicyTool tool;
       
  3172     private ToolWindow tw;
       
  3173     private ToolDialog td;
       
  3174     private boolean edit;
       
  3175 
       
  3176     AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw,
       
  3177                                 ToolDialog td, boolean edit) {
       
  3178         this.tool = tool;
       
  3179         this.tw = tw;
       
  3180         this.td = td;
       
  3181         this.edit = edit;
       
  3182     }
       
  3183 
       
  3184     public void actionPerformed(ActionEvent e) {
       
  3185 
       
  3186         try {
       
  3187             // get a PolicyEntry object from the dialog policy info
       
  3188             PolicyEntry newEntry = td.getPolicyEntryFromDialog();
       
  3189             PolicyParser.GrantEntry newGe = newEntry.getGrantEntry();
       
  3190 
       
  3191             // see if all the signers have public keys
       
  3192             if (newGe.signedBy != null) {
       
  3193                 String signers[] = tool.parseSigners(newGe.signedBy);
       
  3194                 for (int i = 0; i < signers.length; i++) {
       
  3195                     PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
       
  3196                     if (pubKey == null) {
       
  3197                         MessageFormat form = new MessageFormat
       
  3198                             (PolicyTool.getMessage
       
  3199                             ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
       
  3200                         Object[] source = {signers[i]};
       
  3201                         tool.warnings.addElement(form.format(source));
       
  3202                         tw.displayStatusDialog(td, form.format(source));
       
  3203                     }
       
  3204                 }
       
  3205             }
       
  3206 
       
  3207             // add the entry
       
  3208             @SuppressWarnings("unchecked")
       
  3209             JList<String> policyList = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  3210             if (edit) {
       
  3211                 int listIndex = policyList.getSelectedIndex();
       
  3212                 tool.addEntry(newEntry, listIndex);
       
  3213                 String newCodeBaseStr = newEntry.headerToString();
       
  3214                 if (PolicyTool.collator.compare
       
  3215                         (newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)
       
  3216                     tool.modified = true;
       
  3217                 ((DefaultListModel<String>)policyList.getModel()).set(listIndex, newCodeBaseStr);
       
  3218             } else {
       
  3219                 tool.addEntry(newEntry, -1);
       
  3220                 ((DefaultListModel<String>)policyList.getModel()).addElement(newEntry.headerToString());
       
  3221                 tool.modified = true;
       
  3222             }
       
  3223             td.setVisible(false);
       
  3224             td.dispose();
       
  3225 
       
  3226         } catch (Exception eee) {
       
  3227             tw.displayErrorDialog(td, eee);
       
  3228         }
       
  3229     }
       
  3230 }
       
  3231 
       
  3232 /**
       
  3233  * Event handler for ChangeKeyStoreOKButton button
       
  3234  */
       
  3235 class ChangeKeyStoreOKButtonListener implements ActionListener {
       
  3236 
       
  3237     private PolicyTool tool;
       
  3238     private ToolWindow tw;
       
  3239     private ToolDialog td;
       
  3240 
       
  3241     ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw,
       
  3242                 ToolDialog td) {
       
  3243         this.tool = tool;
       
  3244         this.tw = tw;
       
  3245         this.td = td;
       
  3246     }
       
  3247 
       
  3248     public void actionPerformed(ActionEvent e) {
       
  3249 
       
  3250         String URLString = ((JTextField)td.getComponent(
       
  3251                 ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim();
       
  3252         String type = ((JTextField)td.getComponent(
       
  3253                 ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim();
       
  3254         String provider = ((JTextField)td.getComponent(
       
  3255                 ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim();
       
  3256         String pwdURL = ((JTextField)td.getComponent(
       
  3257                 ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim();
       
  3258 
       
  3259         try {
       
  3260             tool.openKeyStore
       
  3261                         ((URLString.length() == 0 ? null : URLString),
       
  3262                         (type.length() == 0 ? null : type),
       
  3263                         (provider.length() == 0 ? null : provider),
       
  3264                         (pwdURL.length() == 0 ? null : pwdURL));
       
  3265             tool.modified = true;
       
  3266         } catch (Exception ex) {
       
  3267             MessageFormat form = new MessageFormat(PolicyTool.getMessage
       
  3268                 ("Unable.to.open.KeyStore.ex.toString."));
       
  3269             Object[] source = {ex.toString()};
       
  3270             tw.displayErrorDialog(td, form.format(source));
       
  3271             return;
       
  3272         }
       
  3273 
       
  3274         td.dispose();
       
  3275     }
       
  3276 }
       
  3277 
       
  3278 /**
       
  3279  * Event handler for AddPrinButton button
       
  3280  */
       
  3281 class AddPrinButtonListener implements ActionListener {
       
  3282 
       
  3283     private PolicyTool tool;
       
  3284     private ToolWindow tw;
       
  3285     private ToolDialog td;
       
  3286     private boolean editPolicyEntry;
       
  3287 
       
  3288     AddPrinButtonListener(PolicyTool tool, ToolWindow tw,
       
  3289                                 ToolDialog td, boolean editPolicyEntry) {
       
  3290         this.tool = tool;
       
  3291         this.tw = tw;
       
  3292         this.td = td;
       
  3293         this.editPolicyEntry = editPolicyEntry;
       
  3294     }
       
  3295 
       
  3296     public void actionPerformed(ActionEvent e) {
       
  3297 
       
  3298         // display a dialog box for the user to enter principal info
       
  3299         td.displayPrincipalDialog(editPolicyEntry, false);
       
  3300     }
       
  3301 }
       
  3302 
       
  3303 /**
       
  3304  * Event handler for AddPermButton button
       
  3305  */
       
  3306 class AddPermButtonListener implements ActionListener {
       
  3307 
       
  3308     private PolicyTool tool;
       
  3309     private ToolWindow tw;
       
  3310     private ToolDialog td;
       
  3311     private boolean editPolicyEntry;
       
  3312 
       
  3313     AddPermButtonListener(PolicyTool tool, ToolWindow tw,
       
  3314                                 ToolDialog td, boolean editPolicyEntry) {
       
  3315         this.tool = tool;
       
  3316         this.tw = tw;
       
  3317         this.td = td;
       
  3318         this.editPolicyEntry = editPolicyEntry;
       
  3319     }
       
  3320 
       
  3321     public void actionPerformed(ActionEvent e) {
       
  3322 
       
  3323         // display a dialog box for the user to enter permission info
       
  3324         td.displayPermissionDialog(editPolicyEntry, false);
       
  3325     }
       
  3326 }
       
  3327 
       
  3328 /**
       
  3329  * Event handler for AddPrinOKButton button
       
  3330  */
       
  3331 class NewPolicyPrinOKButtonListener implements ActionListener {
       
  3332 
       
  3333     private PolicyTool tool;
       
  3334     private ToolWindow tw;
       
  3335     private ToolDialog listDialog;
       
  3336     private ToolDialog infoDialog;
       
  3337     private boolean edit;
       
  3338 
       
  3339     NewPolicyPrinOKButtonListener(PolicyTool tool,
       
  3340                                 ToolWindow tw,
       
  3341                                 ToolDialog listDialog,
       
  3342                                 ToolDialog infoDialog,
       
  3343                                 boolean edit) {
       
  3344         this.tool = tool;
       
  3345         this.tw = tw;
       
  3346         this.listDialog = listDialog;
       
  3347         this.infoDialog = infoDialog;
       
  3348         this.edit = edit;
       
  3349     }
       
  3350 
       
  3351     public void actionPerformed(ActionEvent e) {
       
  3352 
       
  3353         try {
       
  3354             // read in the new principal info from Dialog Box
       
  3355             PolicyParser.PrincipalEntry pppe =
       
  3356                         infoDialog.getPrinFromDialog();
       
  3357             if (pppe != null) {
       
  3358                 try {
       
  3359                     tool.verifyPrincipal(pppe.getPrincipalClass(),
       
  3360                                         pppe.getPrincipalName());
       
  3361                 } catch (ClassNotFoundException cnfe) {
       
  3362                     MessageFormat form = new MessageFormat
       
  3363                                 (PolicyTool.getMessage
       
  3364                                 ("Warning.Class.not.found.class"));
       
  3365                     Object[] source = {pppe.getPrincipalClass()};
       
  3366                     tool.warnings.addElement(form.format(source));
       
  3367                     tw.displayStatusDialog(infoDialog, form.format(source));
       
  3368                 }
       
  3369 
       
  3370                 // add the principal to the GUI principal list
       
  3371                 TaggedList prinList =
       
  3372                     (TaggedList)listDialog.getComponent(ToolDialog.PE_PRIN_LIST);
       
  3373 
       
  3374                 String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe);
       
  3375                 if (edit) {
       
  3376                     // if editing, replace the original principal
       
  3377                     int index = prinList.getSelectedIndex();
       
  3378                     prinList.replaceTaggedItem(prinString, pppe, index);
       
  3379                 } else {
       
  3380                     // if adding, just add it to the end
       
  3381                     prinList.addTaggedItem(prinString, pppe);
       
  3382                 }
       
  3383             }
       
  3384             infoDialog.dispose();
       
  3385         } catch (Exception ee) {
       
  3386             tw.displayErrorDialog(infoDialog, ee);
       
  3387         }
       
  3388     }
       
  3389 }
       
  3390 
       
  3391 /**
       
  3392  * Event handler for AddPermOKButton button
       
  3393  */
       
  3394 class NewPolicyPermOKButtonListener implements ActionListener {
       
  3395 
       
  3396     private PolicyTool tool;
       
  3397     private ToolWindow tw;
       
  3398     private ToolDialog listDialog;
       
  3399     private ToolDialog infoDialog;
       
  3400     private boolean edit;
       
  3401 
       
  3402     NewPolicyPermOKButtonListener(PolicyTool tool,
       
  3403                                 ToolWindow tw,
       
  3404                                 ToolDialog listDialog,
       
  3405                                 ToolDialog infoDialog,
       
  3406                                 boolean edit) {
       
  3407         this.tool = tool;
       
  3408         this.tw = tw;
       
  3409         this.listDialog = listDialog;
       
  3410         this.infoDialog = infoDialog;
       
  3411         this.edit = edit;
       
  3412     }
       
  3413 
       
  3414     public void actionPerformed(ActionEvent e) {
       
  3415 
       
  3416         try {
       
  3417             // read in the new permission info from Dialog Box
       
  3418             PolicyParser.PermissionEntry pppe =
       
  3419                         infoDialog.getPermFromDialog();
       
  3420 
       
  3421             try {
       
  3422                 tool.verifyPermission(pppe.permission, pppe.name, pppe.action);
       
  3423             } catch (ClassNotFoundException cnfe) {
       
  3424                 MessageFormat form = new MessageFormat(PolicyTool.getMessage
       
  3425                                 ("Warning.Class.not.found.class"));
       
  3426                 Object[] source = {pppe.permission};
       
  3427                 tool.warnings.addElement(form.format(source));
       
  3428                 tw.displayStatusDialog(infoDialog, form.format(source));
       
  3429             }
       
  3430 
       
  3431             // add the permission to the GUI permission list
       
  3432             TaggedList permList =
       
  3433                 (TaggedList)listDialog.getComponent(ToolDialog.PE_PERM_LIST);
       
  3434 
       
  3435             String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe);
       
  3436             if (edit) {
       
  3437                 // if editing, replace the original permission
       
  3438                 int which = permList.getSelectedIndex();
       
  3439                 permList.replaceTaggedItem(permString, pppe, which);
       
  3440             } else {
       
  3441                 // if adding, just add it to the end
       
  3442                 permList.addTaggedItem(permString, pppe);
       
  3443             }
       
  3444             infoDialog.dispose();
       
  3445 
       
  3446         } catch (InvocationTargetException ite) {
       
  3447             tw.displayErrorDialog(infoDialog, ite.getTargetException());
       
  3448         } catch (Exception ee) {
       
  3449             tw.displayErrorDialog(infoDialog, ee);
       
  3450         }
       
  3451     }
       
  3452 }
       
  3453 
       
  3454 /**
       
  3455  * Event handler for RemovePrinButton button
       
  3456  */
       
  3457 class RemovePrinButtonListener implements ActionListener {
       
  3458 
       
  3459     private PolicyTool tool;
       
  3460     private ToolWindow tw;
       
  3461     private ToolDialog td;
       
  3462     private boolean edit;
       
  3463 
       
  3464     RemovePrinButtonListener(PolicyTool tool, ToolWindow tw,
       
  3465                                 ToolDialog td, boolean edit) {
       
  3466         this.tool = tool;
       
  3467         this.tw = tw;
       
  3468         this.td = td;
       
  3469         this.edit = edit;
       
  3470     }
       
  3471 
       
  3472     public void actionPerformed(ActionEvent e) {
       
  3473 
       
  3474         // get the Principal selected from the Principal List
       
  3475         TaggedList prinList = (TaggedList)td.getComponent(
       
  3476                 ToolDialog.PE_PRIN_LIST);
       
  3477         int prinIndex = prinList.getSelectedIndex();
       
  3478 
       
  3479         if (prinIndex < 0) {
       
  3480             tw.displayErrorDialog(td, new Exception
       
  3481                 (PolicyTool.getMessage("No.principal.selected")));
       
  3482             return;
       
  3483         }
       
  3484         // remove the principal from the display
       
  3485         prinList.removeTaggedItem(prinIndex);
       
  3486     }
       
  3487 }
       
  3488 
       
  3489 /**
       
  3490  * Event handler for RemovePermButton button
       
  3491  */
       
  3492 class RemovePermButtonListener implements ActionListener {
       
  3493 
       
  3494     private PolicyTool tool;
       
  3495     private ToolWindow tw;
       
  3496     private ToolDialog td;
       
  3497     private boolean edit;
       
  3498 
       
  3499     RemovePermButtonListener(PolicyTool tool, ToolWindow tw,
       
  3500                                 ToolDialog td, boolean edit) {
       
  3501         this.tool = tool;
       
  3502         this.tw = tw;
       
  3503         this.td = td;
       
  3504         this.edit = edit;
       
  3505     }
       
  3506 
       
  3507     public void actionPerformed(ActionEvent e) {
       
  3508 
       
  3509         // get the Permission selected from the Permission List
       
  3510         TaggedList permList = (TaggedList)td.getComponent(
       
  3511                 ToolDialog.PE_PERM_LIST);
       
  3512         int permIndex = permList.getSelectedIndex();
       
  3513 
       
  3514         if (permIndex < 0) {
       
  3515             tw.displayErrorDialog(td, new Exception
       
  3516                 (PolicyTool.getMessage("No.permission.selected")));
       
  3517             return;
       
  3518         }
       
  3519         // remove the permission from the display
       
  3520         permList.removeTaggedItem(permIndex);
       
  3521 
       
  3522     }
       
  3523 }
       
  3524 
       
  3525 /**
       
  3526  * Event handler for Edit Principal button
       
  3527  *
       
  3528  * We need the editPolicyEntry boolean to tell us if the user is
       
  3529  * adding a new PolicyEntry at this time, or editing an existing entry.
       
  3530  * If the user is adding a new PolicyEntry, we ONLY update the
       
  3531  * GUI listing.  If the user is editing an existing PolicyEntry, we
       
  3532  * update both the GUI listing and the actual PolicyEntry.
       
  3533  */
       
  3534 class EditPrinButtonListener extends MouseAdapter implements ActionListener {
       
  3535 
       
  3536     private PolicyTool tool;
       
  3537     private ToolWindow tw;
       
  3538     private ToolDialog td;
       
  3539     private boolean editPolicyEntry;
       
  3540 
       
  3541     EditPrinButtonListener(PolicyTool tool, ToolWindow tw,
       
  3542                                 ToolDialog td, boolean editPolicyEntry) {
       
  3543         this.tool = tool;
       
  3544         this.tw = tw;
       
  3545         this.td = td;
       
  3546         this.editPolicyEntry = editPolicyEntry;
       
  3547     }
       
  3548 
       
  3549     public void actionPerformed(ActionEvent e) {
       
  3550 
       
  3551         // get the Principal selected from the Principal List
       
  3552         TaggedList list = (TaggedList)td.getComponent(
       
  3553                 ToolDialog.PE_PRIN_LIST);
       
  3554         int prinIndex = list.getSelectedIndex();
       
  3555 
       
  3556         if (prinIndex < 0) {
       
  3557             tw.displayErrorDialog(td, new Exception
       
  3558                 (PolicyTool.getMessage("No.principal.selected")));
       
  3559             return;
       
  3560         }
       
  3561         td.displayPrincipalDialog(editPolicyEntry, true);
       
  3562     }
       
  3563 
       
  3564     public void mouseClicked(MouseEvent evt) {
       
  3565         if (evt.getClickCount() == 2) {
       
  3566             actionPerformed(null);
       
  3567         }
       
  3568     }
       
  3569 }
       
  3570 
       
  3571 /**
       
  3572  * Event handler for Edit Permission button
       
  3573  *
       
  3574  * We need the editPolicyEntry boolean to tell us if the user is
       
  3575  * adding a new PolicyEntry at this time, or editing an existing entry.
       
  3576  * If the user is adding a new PolicyEntry, we ONLY update the
       
  3577  * GUI listing.  If the user is editing an existing PolicyEntry, we
       
  3578  * update both the GUI listing and the actual PolicyEntry.
       
  3579  */
       
  3580 class EditPermButtonListener extends MouseAdapter implements ActionListener {
       
  3581 
       
  3582     private PolicyTool tool;
       
  3583     private ToolWindow tw;
       
  3584     private ToolDialog td;
       
  3585     private boolean editPolicyEntry;
       
  3586 
       
  3587     EditPermButtonListener(PolicyTool tool, ToolWindow tw,
       
  3588                                 ToolDialog td, boolean editPolicyEntry) {
       
  3589         this.tool = tool;
       
  3590         this.tw = tw;
       
  3591         this.td = td;
       
  3592         this.editPolicyEntry = editPolicyEntry;
       
  3593     }
       
  3594 
       
  3595     public void actionPerformed(ActionEvent e) {
       
  3596 
       
  3597         // get the Permission selected from the Permission List
       
  3598         @SuppressWarnings("unchecked")
       
  3599         JList<String> list = (JList<String>)td.getComponent(ToolDialog.PE_PERM_LIST);
       
  3600         int permIndex = list.getSelectedIndex();
       
  3601 
       
  3602         if (permIndex < 0) {
       
  3603             tw.displayErrorDialog(td, new Exception
       
  3604                 (PolicyTool.getMessage("No.permission.selected")));
       
  3605             return;
       
  3606         }
       
  3607         td.displayPermissionDialog(editPolicyEntry, true);
       
  3608     }
       
  3609 
       
  3610     public void mouseClicked(MouseEvent evt) {
       
  3611         if (evt.getClickCount() == 2) {
       
  3612             actionPerformed(null);
       
  3613         }
       
  3614     }
       
  3615 }
       
  3616 
       
  3617 /**
       
  3618  * Event handler for Principal Popup Menu
       
  3619  */
       
  3620 class PrincipalTypeMenuListener implements ItemListener {
       
  3621 
       
  3622     private ToolDialog td;
       
  3623 
       
  3624     PrincipalTypeMenuListener(ToolDialog td) {
       
  3625         this.td = td;
       
  3626     }
       
  3627 
       
  3628     public void itemStateChanged(ItemEvent e) {
       
  3629         if (e.getStateChange() == ItemEvent.DESELECTED) {
       
  3630             // We're only interested in SELECTED events
       
  3631             return;
       
  3632         }
       
  3633 
       
  3634         @SuppressWarnings("unchecked")
       
  3635         JComboBox<String> prin = (JComboBox<String>)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);
       
  3636         JTextField prinField = (JTextField)td.getComponent(
       
  3637                 ToolDialog.PRD_PRIN_TEXTFIELD);
       
  3638         JTextField nameField = (JTextField)td.getComponent(
       
  3639                 ToolDialog.PRD_NAME_TEXTFIELD);
       
  3640 
       
  3641         prin.getAccessibleContext().setAccessibleName(
       
  3642             PolicyTool.splitToWords((String)e.getItem()));
       
  3643         if (((String)e.getItem()).equals(ToolDialog.PRIN_TYPE)) {
       
  3644             // ignore if they choose "Principal Type:" item
       
  3645             if (prinField.getText() != null &&
       
  3646                 prinField.getText().length() > 0) {
       
  3647                 Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);
       
  3648                 prin.setSelectedItem(inputPrin.CLASS);
       
  3649             }
       
  3650             return;
       
  3651         }
       
  3652 
       
  3653         // if you change the principal, clear the name
       
  3654         if (prinField.getText().indexOf((String)e.getItem()) == -1) {
       
  3655             nameField.setText("");
       
  3656         }
       
  3657 
       
  3658         // set the text in the textfield and also modify the
       
  3659         // pull-down choice menus to reflect the correct possible
       
  3660         // set of names and actions
       
  3661         Prin inputPrin = ToolDialog.getPrin((String)e.getItem(), false);
       
  3662         if (inputPrin != null) {
       
  3663             prinField.setText(inputPrin.FULL_CLASS);
       
  3664         }
       
  3665     }
       
  3666 }
       
  3667 
       
  3668 /**
       
  3669  * Event handler for Permission Popup Menu
       
  3670  */
       
  3671 class PermissionMenuListener implements ItemListener {
       
  3672 
       
  3673     private ToolDialog td;
       
  3674 
       
  3675     PermissionMenuListener(ToolDialog td) {
       
  3676         this.td = td;
       
  3677     }
       
  3678 
       
  3679     public void itemStateChanged(ItemEvent e) {
       
  3680         if (e.getStateChange() == ItemEvent.DESELECTED) {
       
  3681             // We're only interested in SELECTED events
       
  3682             return;
       
  3683         }
       
  3684 
       
  3685         @SuppressWarnings("unchecked")
       
  3686         JComboBox<String> perms = (JComboBox<String>)td.getComponent(
       
  3687                 ToolDialog.PD_PERM_CHOICE);
       
  3688         @SuppressWarnings("unchecked")
       
  3689         JComboBox<String> names = (JComboBox<String>)td.getComponent(
       
  3690                 ToolDialog.PD_NAME_CHOICE);
       
  3691         @SuppressWarnings("unchecked")
       
  3692         JComboBox<String> actions = (JComboBox<String>)td.getComponent(
       
  3693                 ToolDialog.PD_ACTIONS_CHOICE);
       
  3694         JTextField nameField = (JTextField)td.getComponent(
       
  3695                 ToolDialog.PD_NAME_TEXTFIELD);
       
  3696         JTextField actionsField = (JTextField)td.getComponent(
       
  3697                 ToolDialog.PD_ACTIONS_TEXTFIELD);
       
  3698         JTextField permField = (JTextField)td.getComponent(
       
  3699                 ToolDialog.PD_PERM_TEXTFIELD);
       
  3700         JTextField signedbyField = (JTextField)td.getComponent(
       
  3701                 ToolDialog.PD_SIGNEDBY_TEXTFIELD);
       
  3702 
       
  3703         perms.getAccessibleContext().setAccessibleName(
       
  3704             PolicyTool.splitToWords((String)e.getItem()));
       
  3705 
       
  3706         // ignore if they choose the 'Permission:' item
       
  3707         if (PolicyTool.collator.compare((String)e.getItem(),
       
  3708                                       ToolDialog.PERM) == 0) {
       
  3709             if (permField.getText() != null &&
       
  3710                 permField.getText().length() > 0) {
       
  3711 
       
  3712                 Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);
       
  3713                 if (inputPerm != null) {
       
  3714                     perms.setSelectedItem(inputPerm.CLASS);
       
  3715                 }
       
  3716             }
       
  3717             return;
       
  3718         }
       
  3719 
       
  3720         // if you change the permission, clear the name, actions, and signedBy
       
  3721         if (permField.getText().indexOf((String)e.getItem()) == -1) {
       
  3722             nameField.setText("");
       
  3723             actionsField.setText("");
       
  3724             signedbyField.setText("");
       
  3725         }
       
  3726 
       
  3727         // set the text in the textfield and also modify the
       
  3728         // pull-down choice menus to reflect the correct possible
       
  3729         // set of names and actions
       
  3730 
       
  3731         Perm inputPerm = ToolDialog.getPerm((String)e.getItem(), false);
       
  3732         if (inputPerm == null) {
       
  3733             permField.setText("");
       
  3734         } else {
       
  3735             permField.setText(inputPerm.FULL_CLASS);
       
  3736         }
       
  3737         td.setPermissionNames(inputPerm, names, nameField);
       
  3738         td.setPermissionActions(inputPerm, actions, actionsField);
       
  3739     }
       
  3740 }
       
  3741 
       
  3742 /**
       
  3743  * Event handler for Permission Name Popup Menu
       
  3744  */
       
  3745 class PermissionNameMenuListener implements ItemListener {
       
  3746 
       
  3747     private ToolDialog td;
       
  3748 
       
  3749     PermissionNameMenuListener(ToolDialog td) {
       
  3750         this.td = td;
       
  3751     }
       
  3752 
       
  3753     public void itemStateChanged(ItemEvent e) {
       
  3754         if (e.getStateChange() == ItemEvent.DESELECTED) {
       
  3755             // We're only interested in SELECTED events
       
  3756             return;
       
  3757         }
       
  3758 
       
  3759         @SuppressWarnings("unchecked")
       
  3760         JComboBox<String> names = (JComboBox<String>)td.getComponent(ToolDialog.PD_NAME_CHOICE);
       
  3761         names.getAccessibleContext().setAccessibleName(
       
  3762             PolicyTool.splitToWords((String)e.getItem()));
       
  3763 
       
  3764         if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)
       
  3765             return;
       
  3766 
       
  3767         JTextField tf = (JTextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD);
       
  3768         tf.setText((String)e.getItem());
       
  3769     }
       
  3770 }
       
  3771 
       
  3772 /**
       
  3773  * Event handler for Permission Actions Popup Menu
       
  3774  */
       
  3775 class PermissionActionsMenuListener implements ItemListener {
       
  3776 
       
  3777     private ToolDialog td;
       
  3778 
       
  3779     PermissionActionsMenuListener(ToolDialog td) {
       
  3780         this.td = td;
       
  3781     }
       
  3782 
       
  3783     public void itemStateChanged(ItemEvent e) {
       
  3784         if (e.getStateChange() == ItemEvent.DESELECTED) {
       
  3785             // We're only interested in SELECTED events
       
  3786             return;
       
  3787         }
       
  3788 
       
  3789         @SuppressWarnings("unchecked")
       
  3790         JComboBox<String> actions = (JComboBox<String>)td.getComponent(
       
  3791                 ToolDialog.PD_ACTIONS_CHOICE);
       
  3792         actions.getAccessibleContext().setAccessibleName((String)e.getItem());
       
  3793 
       
  3794         if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)
       
  3795             return;
       
  3796 
       
  3797         JTextField tf = (JTextField)td.getComponent(
       
  3798                 ToolDialog.PD_ACTIONS_TEXTFIELD);
       
  3799         if (tf.getText() == null || tf.getText().equals("")) {
       
  3800             tf.setText((String)e.getItem());
       
  3801         } else {
       
  3802             if (tf.getText().indexOf((String)e.getItem()) == -1)
       
  3803                 tf.setText(tf.getText() + ", " + (String)e.getItem());
       
  3804         }
       
  3805     }
       
  3806 }
       
  3807 
       
  3808 /**
       
  3809  * Event handler for all the children dialogs/windows
       
  3810  */
       
  3811 class ChildWindowListener implements WindowListener {
       
  3812 
       
  3813     private ToolDialog td;
       
  3814 
       
  3815     ChildWindowListener(ToolDialog td) {
       
  3816         this.td = td;
       
  3817     }
       
  3818 
       
  3819     public void windowOpened(WindowEvent we) {
       
  3820     }
       
  3821 
       
  3822     public void windowClosing(WindowEvent we) {
       
  3823         // same as pressing the "cancel" button
       
  3824         td.setVisible(false);
       
  3825         td.dispose();
       
  3826     }
       
  3827 
       
  3828     public void windowClosed(WindowEvent we) {
       
  3829     }
       
  3830 
       
  3831     public void windowIconified(WindowEvent we) {
       
  3832     }
       
  3833 
       
  3834     public void windowDeiconified(WindowEvent we) {
       
  3835     }
       
  3836 
       
  3837     public void windowActivated(WindowEvent we) {
       
  3838     }
       
  3839 
       
  3840     public void windowDeactivated(WindowEvent we) {
       
  3841     }
       
  3842 }
       
  3843 
       
  3844 /**
       
  3845  * Event handler for CancelButton button
       
  3846  */
       
  3847 class CancelButtonListener implements ActionListener {
       
  3848 
       
  3849     private ToolDialog td;
       
  3850 
       
  3851     CancelButtonListener(ToolDialog td) {
       
  3852         this.td = td;
       
  3853     }
       
  3854 
       
  3855     public void actionPerformed(ActionEvent e) {
       
  3856         td.setVisible(false);
       
  3857         td.dispose();
       
  3858     }
       
  3859 }
       
  3860 
       
  3861 /**
       
  3862  * Event handler for ErrorOKButton button
       
  3863  */
       
  3864 class ErrorOKButtonListener implements ActionListener {
       
  3865 
       
  3866     private ToolDialog ed;
       
  3867 
       
  3868     ErrorOKButtonListener(ToolDialog ed) {
       
  3869         this.ed = ed;
       
  3870     }
       
  3871 
       
  3872     public void actionPerformed(ActionEvent e) {
       
  3873         ed.setVisible(false);
       
  3874         ed.dispose();
       
  3875     }
       
  3876 }
       
  3877 
       
  3878 /**
       
  3879  * Event handler for StatusOKButton button
       
  3880  */
       
  3881 class StatusOKButtonListener implements ActionListener {
       
  3882 
       
  3883     private ToolDialog sd;
       
  3884 
       
  3885     StatusOKButtonListener(ToolDialog sd) {
       
  3886         this.sd = sd;
       
  3887     }
       
  3888 
       
  3889     public void actionPerformed(ActionEvent e) {
       
  3890         sd.setVisible(false);
       
  3891         sd.dispose();
       
  3892     }
       
  3893 }
       
  3894 
       
  3895 /**
       
  3896  * Event handler for UserSaveYes button
       
  3897  */
       
  3898 class UserSaveYesButtonListener implements ActionListener {
       
  3899 
       
  3900     private ToolDialog us;
       
  3901     private PolicyTool tool;
       
  3902     private ToolWindow tw;
       
  3903     private int select;
       
  3904 
       
  3905     UserSaveYesButtonListener(ToolDialog us, PolicyTool tool,
       
  3906                         ToolWindow tw, int select) {
       
  3907         this.us = us;
       
  3908         this.tool = tool;
       
  3909         this.tw = tw;
       
  3910         this.select = select;
       
  3911     }
       
  3912 
       
  3913     public void actionPerformed(ActionEvent e) {
       
  3914 
       
  3915         // first get rid of the window
       
  3916         us.setVisible(false);
       
  3917         us.dispose();
       
  3918 
       
  3919         try {
       
  3920             String filename = ((JTextField)tw.getComponent(
       
  3921                     ToolWindow.MW_FILENAME_TEXTFIELD)).getText();
       
  3922             if (filename == null || filename.equals("")) {
       
  3923                 us.displaySaveAsDialog(select);
       
  3924 
       
  3925                 // the above dialog will continue with the originally
       
  3926                 // requested command if necessary
       
  3927             } else {
       
  3928                 // save the policy entries to a file
       
  3929                 tool.savePolicy(filename);
       
  3930 
       
  3931                 // display status
       
  3932                 MessageFormat form = new MessageFormat
       
  3933                         (PolicyTool.getMessage
       
  3934                         ("Policy.successfully.written.to.filename"));
       
  3935                 Object[] source = {filename};
       
  3936                 tw.displayStatusDialog(null, form.format(source));
       
  3937 
       
  3938                 // now continue with the originally requested command
       
  3939                 // (QUIT, NEW, or OPEN)
       
  3940                 us.userSaveContinue(tool, tw, us, select);
       
  3941             }
       
  3942         } catch (Exception ee) {
       
  3943             // error -- just report it and bail
       
  3944             tw.displayErrorDialog(null, ee);
       
  3945         }
       
  3946     }
       
  3947 }
       
  3948 
       
  3949 /**
       
  3950  * Event handler for UserSaveNoButton
       
  3951  */
       
  3952 class UserSaveNoButtonListener implements ActionListener {
       
  3953 
       
  3954     private PolicyTool tool;
       
  3955     private ToolWindow tw;
       
  3956     private ToolDialog us;
       
  3957     private int select;
       
  3958 
       
  3959     UserSaveNoButtonListener(ToolDialog us, PolicyTool tool,
       
  3960                         ToolWindow tw, int select) {
       
  3961         this.us = us;
       
  3962         this.tool = tool;
       
  3963         this.tw = tw;
       
  3964         this.select = select;
       
  3965     }
       
  3966 
       
  3967     public void actionPerformed(ActionEvent e) {
       
  3968         us.setVisible(false);
       
  3969         us.dispose();
       
  3970 
       
  3971         // now continue with the originally requested command
       
  3972         // (QUIT, NEW, or OPEN)
       
  3973         us.userSaveContinue(tool, tw, us, select);
       
  3974     }
       
  3975 }
       
  3976 
       
  3977 /**
       
  3978  * Event handler for UserSaveCancelButton
       
  3979  */
       
  3980 class UserSaveCancelButtonListener implements ActionListener {
       
  3981 
       
  3982     private ToolDialog us;
       
  3983 
       
  3984     UserSaveCancelButtonListener(ToolDialog us) {
       
  3985         this.us = us;
       
  3986     }
       
  3987 
       
  3988     public void actionPerformed(ActionEvent e) {
       
  3989         us.setVisible(false);
       
  3990         us.dispose();
       
  3991 
       
  3992         // do NOT continue with the originally requested command
       
  3993         // (QUIT, NEW, or OPEN)
       
  3994     }
       
  3995 }
       
  3996 
       
  3997 /**
       
  3998  * Event handler for ConfirmRemovePolicyEntryOKButtonListener
       
  3999  */
       
  4000 class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener {
       
  4001 
       
  4002     private PolicyTool tool;
       
  4003     private ToolWindow tw;
       
  4004     private ToolDialog us;
       
  4005 
       
  4006     ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool,
       
  4007                                 ToolWindow tw, ToolDialog us) {
       
  4008         this.tool = tool;
       
  4009         this.tw = tw;
       
  4010         this.us = us;
       
  4011     }
       
  4012 
       
  4013     public void actionPerformed(ActionEvent e) {
       
  4014         // remove the entry
       
  4015         @SuppressWarnings("unchecked")
       
  4016         JList<String> list = (JList<String>)tw.getComponent(ToolWindow.MW_POLICY_LIST);
       
  4017         int index = list.getSelectedIndex();
       
  4018         PolicyEntry entries[] = tool.getEntry();
       
  4019         tool.removeEntry(entries[index]);
       
  4020 
       
  4021         // redraw the window listing
       
  4022         DefaultListModel<String> listModel = new DefaultListModel<>();
       
  4023         list = new JList<>(listModel);
       
  4024         list.setVisibleRowCount(15);
       
  4025         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
       
  4026         list.addMouseListener(new PolicyListListener(tool, tw));
       
  4027         entries = tool.getEntry();
       
  4028         if (entries != null) {
       
  4029                 for (int i = 0; i < entries.length; i++) {
       
  4030                     listModel.addElement(entries[i].headerToString());
       
  4031                 }
       
  4032         }
       
  4033         tw.replacePolicyList(list);
       
  4034         us.setVisible(false);
       
  4035         us.dispose();
       
  4036     }
       
  4037 }
       
  4038 
       
  4039 /**
       
  4040  * Just a special name, so that the codes dealing with this exception knows
       
  4041  * it's special, and does not pop out a warning box.
       
  4042  */
       
  4043 class NoDisplayException extends RuntimeException {
       
  4044     private static final long serialVersionUID = -4611761427108719794L;
       
  4045 }
       
  4046 
       
  4047 /**
       
  4048  * This is a java.awt.List that bind an Object to each String it holds.
       
  4049  */
       
  4050 class TaggedList extends JList<String> {
       
  4051     private static final long serialVersionUID = -5676238110427785853L;
       
  4052 
       
  4053     private java.util.List<Object> data = new LinkedList<>();
       
  4054     public TaggedList(int i, boolean b) {
       
  4055         super(new DefaultListModel<>());
       
  4056         setVisibleRowCount(i);
       
  4057         setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);
       
  4058     }
       
  4059 
       
  4060     public Object getObject(int index) {
       
  4061         return data.get(index);
       
  4062     }
       
  4063 
       
  4064     public void addTaggedItem(String string, Object object) {
       
  4065         ((DefaultListModel<String>)getModel()).addElement(string);
       
  4066         data.add(object);
       
  4067     }
       
  4068 
       
  4069     public void replaceTaggedItem(String string, Object object, int index) {
       
  4070         ((DefaultListModel<String>)getModel()).set(index, string);
       
  4071         data.set(index, object);
       
  4072     }
       
  4073 
       
  4074     public void removeTaggedItem(int index) {
       
  4075         ((DefaultListModel<String>)getModel()).remove(index);
       
  4076         data.remove(index);
       
  4077     }
       
  4078 }
       
  4079 
       
  4080 /**
       
  4081  * Convenience Principal Classes
       
  4082  */
       
  4083 
       
  4084 class Prin {
       
  4085     public final String CLASS;
       
  4086     public final String FULL_CLASS;
       
  4087 
       
  4088     public Prin(String clazz, String fullClass) {
       
  4089         this.CLASS = clazz;
       
  4090         this.FULL_CLASS = fullClass;
       
  4091     }
       
  4092 }
       
  4093 
       
  4094 class KrbPrin extends Prin {
       
  4095     public KrbPrin() {
       
  4096         super("KerberosPrincipal",
       
  4097                 "javax.security.auth.kerberos.KerberosPrincipal");
       
  4098     }
       
  4099 }
       
  4100 
       
  4101 class X500Prin extends Prin {
       
  4102     public X500Prin() {
       
  4103         super("X500Principal",
       
  4104                 "javax.security.auth.x500.X500Principal");
       
  4105     }
       
  4106 }
       
  4107 
       
  4108 /**
       
  4109  * Convenience Permission Classes
       
  4110  */
       
  4111 
       
  4112 class Perm {
       
  4113     public final String CLASS;
       
  4114     public final String FULL_CLASS;
       
  4115     public final String[] TARGETS;
       
  4116     public final String[] ACTIONS;
       
  4117 
       
  4118     public Perm(String clazz, String fullClass,
       
  4119                 String[] targets, String[] actions) {
       
  4120 
       
  4121         this.CLASS = clazz;
       
  4122         this.FULL_CLASS = fullClass;
       
  4123         this.TARGETS = targets;
       
  4124         this.ACTIONS = actions;
       
  4125     }
       
  4126 }
       
  4127 
       
  4128 class AllPerm extends Perm {
       
  4129     public AllPerm() {
       
  4130         super("AllPermission", "java.security.AllPermission", null, null);
       
  4131     }
       
  4132 }
       
  4133 
       
  4134 class AudioPerm extends Perm {
       
  4135     public AudioPerm() {
       
  4136         super("AudioPermission",
       
  4137         "javax.sound.sampled.AudioPermission",
       
  4138         new String[]    {
       
  4139                 "play",
       
  4140                 "record"
       
  4141                 },
       
  4142         null);
       
  4143     }
       
  4144 }
       
  4145 
       
  4146 class AuthPerm extends Perm {
       
  4147     public AuthPerm() {
       
  4148     super("AuthPermission",
       
  4149         "javax.security.auth.AuthPermission",
       
  4150         new String[]    {
       
  4151                 "doAs",
       
  4152                 "doAsPrivileged",
       
  4153                 "getSubject",
       
  4154                 "getSubjectFromDomainCombiner",
       
  4155                 "setReadOnly",
       
  4156                 "modifyPrincipals",
       
  4157                 "modifyPublicCredentials",
       
  4158                 "modifyPrivateCredentials",
       
  4159                 "refreshCredential",
       
  4160                 "destroyCredential",
       
  4161                 "createLoginContext.<" + PolicyTool.getMessage("name") + ">",
       
  4162                 "getLoginConfiguration",
       
  4163                 "setLoginConfiguration",
       
  4164                 "createLoginConfiguration.<" +
       
  4165                         PolicyTool.getMessage("configuration.type") + ">",
       
  4166                 "refreshLoginConfiguration"
       
  4167                 },
       
  4168         null);
       
  4169     }
       
  4170 }
       
  4171 
       
  4172 class AWTPerm extends Perm {
       
  4173     public AWTPerm() {
       
  4174     super("AWTPermission",
       
  4175         "java.awt.AWTPermission",
       
  4176         new String[]    {
       
  4177                 "accessClipboard",
       
  4178                 "accessEventQueue",
       
  4179                 "accessSystemTray",
       
  4180                 "createRobot",
       
  4181                 "fullScreenExclusive",
       
  4182                 "listenToAllAWTEvents",
       
  4183                 "readDisplayPixels",
       
  4184                 "replaceKeyboardFocusManager",
       
  4185                 "setAppletStub",
       
  4186                 "setWindowAlwaysOnTop",
       
  4187                 "showWindowWithoutWarningBanner",
       
  4188                 "toolkitModality",
       
  4189                 "watchMousePointer"
       
  4190         },
       
  4191         null);
       
  4192     }
       
  4193 }
       
  4194 
       
  4195 class DelegationPerm extends Perm {
       
  4196     public DelegationPerm() {
       
  4197     super("DelegationPermission",
       
  4198         "javax.security.auth.kerberos.DelegationPermission",
       
  4199         new String[]    {
       
  4200                 // allow user input
       
  4201                 },
       
  4202         null);
       
  4203     }
       
  4204 }
       
  4205 
       
  4206 class FilePerm extends Perm {
       
  4207     public FilePerm() {
       
  4208     super("FilePermission",
       
  4209         "java.io.FilePermission",
       
  4210         new String[]    {
       
  4211                 "<<ALL FILES>>"
       
  4212                 },
       
  4213         new String[]    {
       
  4214                 "read",
       
  4215                 "write",
       
  4216                 "delete",
       
  4217                 "execute"
       
  4218                 });
       
  4219     }
       
  4220 }
       
  4221 
       
  4222 class URLPerm extends Perm {
       
  4223     public URLPerm() {
       
  4224         super("URLPermission",
       
  4225                 "java.net.URLPermission",
       
  4226                 new String[]    {
       
  4227                     "<"+ PolicyTool.getMessage("url") + ">",
       
  4228                 },
       
  4229                 new String[]    {
       
  4230                     "<" + PolicyTool.getMessage("method.list") + ">:<"
       
  4231                         + PolicyTool.getMessage("request.headers.list") + ">",
       
  4232                 });
       
  4233     }
       
  4234 }
       
  4235 
       
  4236 class InqSecContextPerm extends Perm {
       
  4237     public InqSecContextPerm() {
       
  4238     super("InquireSecContextPermission",
       
  4239         "com.sun.security.jgss.InquireSecContextPermission",
       
  4240         new String[]    {
       
  4241                 "KRB5_GET_SESSION_KEY",
       
  4242                 "KRB5_GET_TKT_FLAGS",
       
  4243                 "KRB5_GET_AUTHZ_DATA",
       
  4244                 "KRB5_GET_AUTHTIME"
       
  4245                 },
       
  4246         null);
       
  4247     }
       
  4248 }
       
  4249 
       
  4250 class LogPerm extends Perm {
       
  4251     public LogPerm() {
       
  4252     super("LoggingPermission",
       
  4253         "java.util.logging.LoggingPermission",
       
  4254         new String[]    {
       
  4255                 "control"
       
  4256                 },
       
  4257         null);
       
  4258     }
       
  4259 }
       
  4260 
       
  4261 class MgmtPerm extends Perm {
       
  4262     public MgmtPerm() {
       
  4263     super("ManagementPermission",
       
  4264         "java.lang.management.ManagementPermission",
       
  4265         new String[]    {
       
  4266                 "control",
       
  4267                 "monitor"
       
  4268                 },
       
  4269         null);
       
  4270     }
       
  4271 }
       
  4272 
       
  4273 class MBeanPerm extends Perm {
       
  4274     public MBeanPerm() {
       
  4275     super("MBeanPermission",
       
  4276         "javax.management.MBeanPermission",
       
  4277         new String[]    {
       
  4278                 // allow user input
       
  4279                 },
       
  4280         new String[]    {
       
  4281                 "addNotificationListener",
       
  4282                 "getAttribute",
       
  4283                 "getClassLoader",
       
  4284                 "getClassLoaderFor",
       
  4285                 "getClassLoaderRepository",
       
  4286                 "getDomains",
       
  4287                 "getMBeanInfo",
       
  4288                 "getObjectInstance",
       
  4289                 "instantiate",
       
  4290                 "invoke",
       
  4291                 "isInstanceOf",
       
  4292                 "queryMBeans",
       
  4293                 "queryNames",
       
  4294                 "registerMBean",
       
  4295                 "removeNotificationListener",
       
  4296                 "setAttribute",
       
  4297                 "unregisterMBean"
       
  4298                 });
       
  4299     }
       
  4300 }
       
  4301 
       
  4302 class MBeanSvrPerm extends Perm {
       
  4303     public MBeanSvrPerm() {
       
  4304     super("MBeanServerPermission",
       
  4305         "javax.management.MBeanServerPermission",
       
  4306         new String[]    {
       
  4307                 "createMBeanServer",
       
  4308                 "findMBeanServer",
       
  4309                 "newMBeanServer",
       
  4310                 "releaseMBeanServer"
       
  4311                 },
       
  4312         null);
       
  4313     }
       
  4314 }
       
  4315 
       
  4316 class MBeanTrustPerm extends Perm {
       
  4317     public MBeanTrustPerm() {
       
  4318     super("MBeanTrustPermission",
       
  4319         "javax.management.MBeanTrustPermission",
       
  4320         new String[]    {
       
  4321                 "register"
       
  4322                 },
       
  4323         null);
       
  4324     }
       
  4325 }
       
  4326 
       
  4327 class NetPerm extends Perm {
       
  4328     public NetPerm() {
       
  4329     super("NetPermission",
       
  4330         "java.net.NetPermission",
       
  4331         new String[]    {
       
  4332                 "allowHttpTrace",
       
  4333                 "setDefaultAuthenticator",
       
  4334                 "requestPasswordAuthentication",
       
  4335                 "specifyStreamHandler",
       
  4336                 "getNetworkInformation",
       
  4337                 "setProxySelector",
       
  4338                 "getProxySelector",
       
  4339                 "setCookieHandler",
       
  4340                 "getCookieHandler",
       
  4341                 "setResponseCache",
       
  4342                 "getResponseCache"
       
  4343                 },
       
  4344         null);
       
  4345     }
       
  4346 }
       
  4347 
       
  4348 class NetworkPerm extends Perm {
       
  4349     public NetworkPerm() {
       
  4350     super("NetworkPermission",
       
  4351         "jdk.net.NetworkPermission",
       
  4352         new String[]    {
       
  4353                 "setOption.SO_FLOW_SLA",
       
  4354                 "getOption.SO_FLOW_SLA"
       
  4355                 },
       
  4356         null);
       
  4357     }
       
  4358 }
       
  4359 
       
  4360 class PrivCredPerm extends Perm {
       
  4361     public PrivCredPerm() {
       
  4362     super("PrivateCredentialPermission",
       
  4363         "javax.security.auth.PrivateCredentialPermission",
       
  4364         new String[]    {
       
  4365                 // allow user input
       
  4366                 },
       
  4367         new String[]    {
       
  4368                 "read"
       
  4369                 });
       
  4370     }
       
  4371 }
       
  4372 
       
  4373 class PropPerm extends Perm {
       
  4374     public PropPerm() {
       
  4375     super("PropertyPermission",
       
  4376         "java.util.PropertyPermission",
       
  4377         new String[]    {
       
  4378                 // allow user input
       
  4379                 },
       
  4380         new String[]    {
       
  4381                 "read",
       
  4382                 "write"
       
  4383                 });
       
  4384     }
       
  4385 }
       
  4386 
       
  4387 class ReflectPerm extends Perm {
       
  4388     public ReflectPerm() {
       
  4389     super("ReflectPermission",
       
  4390         "java.lang.reflect.ReflectPermission",
       
  4391         new String[]    {
       
  4392                 "suppressAccessChecks"
       
  4393                 },
       
  4394         null);
       
  4395     }
       
  4396 }
       
  4397 
       
  4398 class RuntimePerm extends Perm {
       
  4399     public RuntimePerm() {
       
  4400     super("RuntimePermission",
       
  4401         "java.lang.RuntimePermission",
       
  4402         new String[]    {
       
  4403                 "createClassLoader",
       
  4404                 "getClassLoader",
       
  4405                 "setContextClassLoader",
       
  4406                 "enableContextClassLoaderOverride",
       
  4407                 "setSecurityManager",
       
  4408                 "createSecurityManager",
       
  4409                 "getenv.<" +
       
  4410                     PolicyTool.getMessage("environment.variable.name") + ">",
       
  4411                 "exitVM",
       
  4412                 "shutdownHooks",
       
  4413                 "setFactory",
       
  4414                 "setIO",
       
  4415                 "modifyThread",
       
  4416                 "stopThread",
       
  4417                 "modifyThreadGroup",
       
  4418                 "getProtectionDomain",
       
  4419                 "readFileDescriptor",
       
  4420                 "writeFileDescriptor",
       
  4421                 "loadLibrary.<" +
       
  4422                     PolicyTool.getMessage("library.name") + ">",
       
  4423                 "accessClassInPackage.<" +
       
  4424                     PolicyTool.getMessage("package.name")+">",
       
  4425                 "defineClassInPackage.<" +
       
  4426                     PolicyTool.getMessage("package.name")+">",
       
  4427                 "accessDeclaredMembers",
       
  4428                 "queuePrintJob",
       
  4429                 "getStackTrace",
       
  4430                 "setDefaultUncaughtExceptionHandler",
       
  4431                 "preferences",
       
  4432                 "usePolicy",
       
  4433                 // "inheritedChannel"
       
  4434                 },
       
  4435         null);
       
  4436     }
       
  4437 }
       
  4438 
       
  4439 class SecurityPerm extends Perm {
       
  4440     public SecurityPerm() {
       
  4441     super("SecurityPermission",
       
  4442         "java.security.SecurityPermission",
       
  4443         new String[]    {
       
  4444                 "createAccessControlContext",
       
  4445                 "getDomainCombiner",
       
  4446                 "getPolicy",
       
  4447                 "setPolicy",
       
  4448                 "createPolicy.<" +
       
  4449                     PolicyTool.getMessage("policy.type") + ">",
       
  4450                 "getProperty.<" +
       
  4451                     PolicyTool.getMessage("property.name") + ">",
       
  4452                 "setProperty.<" +
       
  4453                     PolicyTool.getMessage("property.name") + ">",
       
  4454                 "insertProvider.<" +
       
  4455                     PolicyTool.getMessage("provider.name") + ">",
       
  4456                 "removeProvider.<" +
       
  4457                     PolicyTool.getMessage("provider.name") + ">",
       
  4458                 //"setSystemScope",
       
  4459                 //"setIdentityPublicKey",
       
  4460                 //"setIdentityInfo",
       
  4461                 //"addIdentityCertificate",
       
  4462                 //"removeIdentityCertificate",
       
  4463                 //"printIdentity",
       
  4464                 "clearProviderProperties.<" +
       
  4465                     PolicyTool.getMessage("provider.name") + ">",
       
  4466                 "putProviderProperty.<" +
       
  4467                     PolicyTool.getMessage("provider.name") + ">",
       
  4468                 "removeProviderProperty.<" +
       
  4469                     PolicyTool.getMessage("provider.name") + ">",
       
  4470                 //"getSignerPrivateKey",
       
  4471                 //"setSignerKeyPair"
       
  4472                 },
       
  4473         null);
       
  4474     }
       
  4475 }
       
  4476 
       
  4477 class SerialPerm extends Perm {
       
  4478     public SerialPerm() {
       
  4479     super("SerializablePermission",
       
  4480         "java.io.SerializablePermission",
       
  4481         new String[]    {
       
  4482                 "enableSubclassImplementation",
       
  4483                 "enableSubstitution"
       
  4484                 },
       
  4485         null);
       
  4486     }
       
  4487 }
       
  4488 
       
  4489 class ServicePerm extends Perm {
       
  4490     public ServicePerm() {
       
  4491     super("ServicePermission",
       
  4492         "javax.security.auth.kerberos.ServicePermission",
       
  4493         new String[]    {
       
  4494                 // allow user input
       
  4495                 },
       
  4496         new String[]    {
       
  4497                 "initiate",
       
  4498                 "accept"
       
  4499                 });
       
  4500     }
       
  4501 }
       
  4502 
       
  4503 class SocketPerm extends Perm {
       
  4504     public SocketPerm() {
       
  4505     super("SocketPermission",
       
  4506         "java.net.SocketPermission",
       
  4507         new String[]    {
       
  4508                 // allow user input
       
  4509                 },
       
  4510         new String[]    {
       
  4511                 "accept",
       
  4512                 "connect",
       
  4513                 "listen",
       
  4514                 "resolve"
       
  4515                 });
       
  4516     }
       
  4517 }
       
  4518 
       
  4519 class SQLPerm extends Perm {
       
  4520     public SQLPerm() {
       
  4521     super("SQLPermission",
       
  4522         "java.sql.SQLPermission",
       
  4523         new String[]    {
       
  4524                 "setLog",
       
  4525                 "callAbort",
       
  4526                 "setSyncFactory",
       
  4527                 "setNetworkTimeout",
       
  4528                 },
       
  4529         null);
       
  4530     }
       
  4531 }
       
  4532 
       
  4533 class SSLPerm extends Perm {
       
  4534     public SSLPerm() {
       
  4535     super("SSLPermission",
       
  4536         "javax.net.ssl.SSLPermission",
       
  4537         new String[]    {
       
  4538                 "setHostnameVerifier",
       
  4539                 "getSSLSessionContext"
       
  4540                 },
       
  4541         null);
       
  4542     }
       
  4543 }
       
  4544 
       
  4545 class SubjDelegPerm extends Perm {
       
  4546     public SubjDelegPerm() {
       
  4547     super("SubjectDelegationPermission",
       
  4548         "javax.management.remote.SubjectDelegationPermission",
       
  4549         new String[]    {
       
  4550                 // allow user input
       
  4551                 },
       
  4552         null);
       
  4553     }
       
  4554 }