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