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