0N/A/*
3909N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
2400N/Apackage sun.security.tools.policytool;
0N/A
0N/Aimport java.io.*;
0N/Aimport java.util.LinkedList;
0N/Aimport java.util.ListIterator;
0N/Aimport java.util.Vector;
0N/Aimport java.util.Enumeration;
0N/Aimport java.net.URL;
0N/Aimport java.net.MalformedURLException;
0N/Aimport java.lang.reflect.*;
0N/Aimport java.text.Collator;
0N/Aimport java.text.MessageFormat;
0N/Aimport sun.security.util.PropertyExpander;
0N/Aimport sun.security.util.PropertyExpander.ExpandException;
0N/Aimport java.awt.*;
0N/Aimport java.awt.event.*;
0N/Aimport java.security.cert.Certificate;
0N/Aimport java.security.cert.CertificateException;
0N/Aimport java.security.*;
0N/Aimport sun.security.provider.*;
0N/Aimport sun.security.util.PolicyUtil;
0N/Aimport javax.security.auth.x500.X500Principal;
0N/A
0N/A/**
0N/A * PolicyTool may be used by users and administrators to configure the
0N/A * overall java security policy (currently stored in the policy file).
3217N/A * Using PolicyTool administrators may add and remove policies from
0N/A * the policy file. <p>
0N/A *
0N/A * @see java.security.Policy
0N/A * @since 1.2
0N/A */
0N/A
0N/Apublic class PolicyTool {
0N/A
0N/A // for i18n
0N/A static final java.util.ResourceBundle rb =
0N/A java.util.ResourceBundle.getBundle("sun.security.util.Resources");
0N/A static final Collator collator = Collator.getInstance();
0N/A static {
0N/A // this is for case insensitive string comparisons
0N/A collator.setStrength(Collator.PRIMARY);
0N/A };
0N/A
0N/A // anyone can add warnings
0N/A Vector<String> warnings;
0N/A boolean newWarning = false;
0N/A
0N/A // set to true if policy modified.
0N/A // this way upon exit we know if to ask the user to save changes
0N/A boolean modified = false;
0N/A
0N/A private static final boolean testing = false;
0N/A private static final Class[] TWOPARAMS = { String.class, String.class };
0N/A private static final Class[] ONEPARAMS = { String.class };
0N/A private static final Class[] NOPARAMS = {};
0N/A /*
0N/A * All of the policy entries are read in from the
0N/A * policy file and stored here. Updates to the policy entries
0N/A * using addEntry() and removeEntry() are made here. To ultimately save
0N/A * the policy entries back to the policy file, the SavePolicy button
0N/A * must be clicked.
0N/A **/
0N/A private static String policyFileName = null;
0N/A private Vector<PolicyEntry> policyEntries = null;
0N/A private PolicyParser parser = null;
0N/A
0N/A /* The public key alias information is stored here. */
0N/A private KeyStore keyStore = null;
0N/A private String keyStoreName = " ";
0N/A private String keyStoreType = " ";
0N/A private String keyStoreProvider = " ";
0N/A private String keyStorePwdURL = " ";
0N/A
0N/A /* standard PKCS11 KeyStore type */
0N/A private static final String P11KEYSTORE = "PKCS11";
0N/A
0N/A /* reserved word for PKCS11 KeyStores */
0N/A private static final String NONE = "NONE";
0N/A
0N/A /**
0N/A * default constructor
0N/A */
0N/A private PolicyTool() {
0N/A policyEntries = new Vector<PolicyEntry>();
0N/A parser = new PolicyParser();
0N/A warnings = new Vector<String>();
0N/A }
0N/A
0N/A /**
0N/A * get the PolicyFileName
0N/A */
0N/A String getPolicyFileName() {
0N/A return policyFileName;
0N/A }
0N/A
0N/A /**
0N/A * set the PolicyFileName
0N/A */
0N/A void setPolicyFileName(String policyFileName) {
0N/A this.policyFileName = policyFileName;
0N/A }
0N/A
0N/A /**
0N/A * clear keyStore info
0N/A */
0N/A void clearKeyStoreInfo() {
0N/A this.keyStoreName = null;
0N/A this.keyStoreType = null;
0N/A this.keyStoreProvider = null;
0N/A this.keyStorePwdURL = null;
0N/A
0N/A this.keyStore = null;
0N/A }
0N/A
0N/A /**
0N/A * get the keyStore URL name
0N/A */
0N/A String getKeyStoreName() {
0N/A return keyStoreName;
0N/A }
0N/A
0N/A /**
0N/A * get the keyStore Type
0N/A */
0N/A String getKeyStoreType() {
0N/A return keyStoreType;
0N/A }
0N/A
0N/A /**
0N/A * get the keyStore Provider
0N/A */
0N/A String getKeyStoreProvider() {
0N/A return keyStoreProvider;
0N/A }
0N/A
0N/A /**
0N/A * get the keyStore password URL
0N/A */
0N/A String getKeyStorePwdURL() {
0N/A return keyStorePwdURL;
0N/A }
0N/A
0N/A /**
0N/A * Open and read a policy file
0N/A */
0N/A void openPolicy(String filename) throws FileNotFoundException,
0N/A PolicyParser.ParsingException,
0N/A KeyStoreException,
0N/A CertificateException,
0N/A InstantiationException,
0N/A MalformedURLException,
0N/A IOException,
0N/A NoSuchAlgorithmException,
0N/A IllegalAccessException,
0N/A NoSuchMethodException,
0N/A UnrecoverableKeyException,
0N/A NoSuchProviderException,
0N/A ClassNotFoundException,
0N/A PropertyExpander.ExpandException,
0N/A InvocationTargetException {
0N/A
0N/A newWarning = false;
0N/A
0N/A // start fresh - blow away the current state
0N/A policyEntries = new Vector<PolicyEntry>();
0N/A parser = new PolicyParser();
0N/A warnings = new Vector<String>();
0N/A setPolicyFileName(null);
0N/A clearKeyStoreInfo();
0N/A
0N/A // see if user is opening a NEW policy file
0N/A if (filename == null) {
0N/A modified = false;
0N/A return;
0N/A }
0N/A
0N/A // Read in the policy entries from the file and
0N/A // populate the parser vector table. The parser vector
0N/A // table only holds the entries as strings, so it only
0N/A // guarantees that the policies are syntactically
0N/A // correct.
0N/A setPolicyFileName(filename);
0N/A parser.read(new FileReader(filename));
0N/A
0N/A // open the keystore
0N/A openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(),
0N/A parser.getKeyStoreProvider(), parser.getStorePassURL());
0N/A
0N/A // Update the local vector with the same policy entries.
0N/A // This guarantees that the policy entries are not only
0N/A // syntactically correct, but semantically valid as well.
0N/A Enumeration<PolicyParser.GrantEntry> enum_ = parser.grantElements();
0N/A while (enum_.hasMoreElements()) {
0N/A PolicyParser.GrantEntry ge = enum_.nextElement();
0N/A
0N/A // see if all the signers have public keys
0N/A if (ge.signedBy != null) {
0N/A
0N/A String signers[] = parseSigners(ge.signedBy);
0N/A for (int i = 0; i < signers.length; i++) {
0N/A PublicKey pubKey = getPublicKeyAlias(signers[i]);
0N/A if (pubKey == null) {
0N/A newWarning = true;
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
0N/A Object[] source = {signers[i]};
0N/A warnings.addElement(form.format(source));
0N/A }
0N/A }
0N/A }
0N/A
0N/A // check to see if the Principals are valid
0N/A ListIterator<PolicyParser.PrincipalEntry> prinList =
0N/A ge.principals.listIterator(0);
0N/A while (prinList.hasNext()) {
0N/A PolicyParser.PrincipalEntry pe = prinList.next();
0N/A try {
0N/A verifyPrincipal(pe.getPrincipalClass(),
0N/A pe.getPrincipalName());
0N/A } catch (ClassNotFoundException fnfe) {
0N/A newWarning = true;
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Warning.Class.not.found.class"));
0N/A Object[] source = {pe.getPrincipalClass()};
0N/A warnings.addElement(form.format(source));
0N/A }
0N/A }
0N/A
0N/A // check to see if the Permissions are valid
0N/A Enumeration<PolicyParser.PermissionEntry> perms =
0N/A ge.permissionElements();
0N/A while (perms.hasMoreElements()) {
0N/A PolicyParser.PermissionEntry pe = perms.nextElement();
0N/A try {
0N/A verifyPermission(pe.permission, pe.name, pe.action);
0N/A } catch (ClassNotFoundException fnfe) {
0N/A newWarning = true;
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Warning.Class.not.found.class"));
0N/A Object[] source = {pe.permission};
0N/A warnings.addElement(form.format(source));
0N/A } catch (InvocationTargetException ite) {
0N/A newWarning = true;
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Warning.Invalid.argument.s.for.constructor.arg"));
0N/A Object[] source = {pe.permission};
0N/A warnings.addElement(form.format(source));
0N/A }
0N/A
0N/A // see if all the permission signers have public keys
0N/A if (pe.signedBy != null) {
0N/A
0N/A String signers[] = parseSigners(pe.signedBy);
0N/A
0N/A for (int i = 0; i < signers.length; i++) {
0N/A PublicKey pubKey = getPublicKeyAlias(signers[i]);
0N/A if (pubKey == null) {
0N/A newWarning = true;
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
0N/A Object[] source = {signers[i]};
0N/A warnings.addElement(form.format(source));
0N/A }
0N/A }
0N/A }
0N/A }
0N/A PolicyEntry pEntry = new PolicyEntry(this, ge);
0N/A policyEntries.addElement(pEntry);
0N/A }
0N/A
0N/A // just read in the policy -- nothing has been modified yet
0N/A modified = false;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Save a policy to a file
0N/A */
0N/A void savePolicy(String filename)
0N/A throws FileNotFoundException, IOException {
0N/A // save the policy entries to a file
0N/A parser.setKeyStoreUrl(keyStoreName);
0N/A parser.setKeyStoreType(keyStoreType);
0N/A parser.setKeyStoreProvider(keyStoreProvider);
0N/A parser.setStorePassURL(keyStorePwdURL);
0N/A parser.write(new FileWriter(filename));
0N/A modified = false;
0N/A }
0N/A
0N/A /**
0N/A * Open the KeyStore
0N/A */
0N/A void openKeyStore(String name,
0N/A String type,
0N/A String provider,
0N/A String pwdURL) throws KeyStoreException,
0N/A NoSuchAlgorithmException,
0N/A UnrecoverableKeyException,
0N/A IOException,
0N/A CertificateException,
0N/A NoSuchProviderException,
0N/A ExpandException {
0N/A
0N/A if (name == null && type == null &&
0N/A provider == null && pwdURL == null) {
0N/A
0N/A // policy did not specify a keystore during open
0N/A // or use wants to reset keystore values
0N/A
0N/A this.keyStoreName = null;
0N/A this.keyStoreType = null;
0N/A this.keyStoreProvider = null;
0N/A this.keyStorePwdURL = null;
0N/A
0N/A // caller will set (tool.modified = true) if appropriate
0N/A
0N/A return;
0N/A }
0N/A
0N/A URL policyURL = null;
0N/A if (policyFileName != null) {
0N/A File pfile = new File(policyFileName);
0N/A policyURL = new URL("file:" + pfile.getCanonicalPath());
0N/A }
0N/A
0N/A // although PolicyUtil.getKeyStore may properly handle
0N/A // defaults and property expansion, we do it here so that
0N/A // if the call is successful, we can set the proper values
0N/A // (PolicyUtil.getKeyStore does not return expanded values)
0N/A
0N/A if (name != null && name.length() > 0) {
0N/A name = PropertyExpander.expand(name).replace
0N/A (File.separatorChar, '/');
0N/A }
0N/A if (type == null || type.length() == 0) {
0N/A type = KeyStore.getDefaultType();
0N/A }
0N/A if (pwdURL != null && pwdURL.length() > 0) {
0N/A pwdURL = PropertyExpander.expand(pwdURL).replace
0N/A (File.separatorChar, '/');
0N/A }
0N/A
0N/A try {
0N/A this.keyStore = PolicyUtil.getKeyStore(policyURL,
0N/A name,
0N/A type,
0N/A provider,
0N/A pwdURL,
0N/A null);
0N/A } catch (IOException ioe) {
0N/A
0N/A // copied from sun.security.pkcs11.SunPKCS11
0N/A String MSG = "no password provided, and no callback handler " +
0N/A "available for retrieving password";
0N/A
0N/A Throwable cause = ioe.getCause();
0N/A if (cause != null &&
0N/A cause instanceof javax.security.auth.login.LoginException &&
0N/A MSG.equals(cause.getMessage())) {
0N/A
0N/A // throw a more friendly exception message
0N/A throw new IOException(MSG);
0N/A } else {
0N/A throw ioe;
0N/A }
0N/A }
0N/A
0N/A this.keyStoreName = name;
0N/A this.keyStoreType = type;
0N/A this.keyStoreProvider = provider;
0N/A this.keyStorePwdURL = pwdURL;
0N/A
0N/A // caller will set (tool.modified = true)
0N/A }
0N/A
0N/A /**
0N/A * Add a Grant entry to the overall policy at the specified index.
0N/A * A policy entry consists of a CodeSource.
0N/A */
0N/A boolean addEntry(PolicyEntry pe, int index) {
0N/A
0N/A if (index < 0) {
0N/A // new entry -- just add it to the end
0N/A policyEntries.addElement(pe);
0N/A parser.add(pe.getGrantEntry());
0N/A } else {
0N/A // existing entry -- replace old one
0N/A PolicyEntry origPe = policyEntries.elementAt(index);
0N/A parser.replace(origPe.getGrantEntry(), pe.getGrantEntry());
0N/A policyEntries.setElementAt(pe, index);
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Add a Principal entry to an existing PolicyEntry at the specified index.
0N/A * A Principal entry consists of a class, and name.
0N/A *
0N/A * If the principal already exists, it is not added again.
0N/A */
0N/A boolean addPrinEntry(PolicyEntry pe,
0N/A PolicyParser.PrincipalEntry newPrin,
0N/A int index) {
0N/A
0N/A // first add the principal to the Policy Parser entry
0N/A PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();
0N/A if (grantEntry.contains(newPrin) == true)
0N/A return false;
0N/A
0N/A LinkedList<PolicyParser.PrincipalEntry> prinList =
0N/A grantEntry.principals;
0N/A if (index != -1)
0N/A prinList.set(index, newPrin);
0N/A else
0N/A prinList.add(newPrin);
0N/A
0N/A modified = true;
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Add a Permission entry to an existing PolicyEntry at the specified index.
0N/A * A Permission entry consists of a permission, name, and actions.
0N/A *
0N/A * If the permission already exists, it is not added again.
0N/A */
0N/A boolean addPermEntry(PolicyEntry pe,
0N/A PolicyParser.PermissionEntry newPerm,
0N/A int index) {
0N/A
0N/A // first add the permission to the Policy Parser Vector
0N/A PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();
0N/A if (grantEntry.contains(newPerm) == true)
0N/A return false;
0N/A
0N/A Vector<PolicyParser.PermissionEntry> permList =
0N/A grantEntry.permissionEntries;
0N/A if (index != -1)
0N/A permList.setElementAt(newPerm, index);
0N/A else
0N/A permList.addElement(newPerm);
0N/A
0N/A modified = true;
0N/A return true;
0N/A }
0N/A
0N/A /**
0N/A * Remove a Permission entry from an existing PolicyEntry.
0N/A */
0N/A boolean removePermEntry(PolicyEntry pe,
0N/A PolicyParser.PermissionEntry perm) {
0N/A
0N/A // remove the Permission from the GrantEntry
0N/A PolicyParser.GrantEntry ppge = pe.getGrantEntry();
0N/A modified = ppge.remove(perm);
0N/A return modified;
0N/A }
0N/A
0N/A /**
0N/A * remove an entry from the overall policy
0N/A */
0N/A boolean removeEntry(PolicyEntry pe) {
0N/A
0N/A parser.remove(pe.getGrantEntry());
0N/A modified = true;
0N/A return (policyEntries.removeElement(pe));
0N/A }
0N/A
0N/A /**
0N/A * retrieve all Policy Entries
0N/A */
0N/A PolicyEntry[] getEntry() {
0N/A
0N/A if (policyEntries.size() > 0) {
0N/A PolicyEntry entries[] = new PolicyEntry[policyEntries.size()];
0N/A for (int i = 0; i < policyEntries.size(); i++)
0N/A entries[i] = policyEntries.elementAt(i);
0N/A return entries;
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Retrieve the public key mapped to a particular name.
0N/A * If the key has expired, a KeyException is thrown.
0N/A */
0N/A PublicKey getPublicKeyAlias(String name) throws KeyStoreException {
0N/A if (keyStore == null) {
0N/A return null;
0N/A }
0N/A
0N/A Certificate cert = keyStore.getCertificate(name);
0N/A if (cert == null) {
0N/A return null;
0N/A }
0N/A PublicKey pubKey = cert.getPublicKey();
0N/A return pubKey;
0N/A }
0N/A
0N/A /**
0N/A * Retrieve all the alias names stored in the certificate database
0N/A */
0N/A String[] getPublicKeyAlias() throws KeyStoreException {
0N/A
0N/A int numAliases = 0;
0N/A String aliases[] = null;
0N/A
0N/A if (keyStore == null) {
0N/A return null;
0N/A }
0N/A Enumeration<String> enum_ = keyStore.aliases();
0N/A
0N/A // first count the number of elements
0N/A while (enum_.hasMoreElements()) {
0N/A enum_.nextElement();
0N/A numAliases++;
0N/A }
0N/A
0N/A if (numAliases > 0) {
0N/A // now copy them into an array
0N/A aliases = new String[numAliases];
0N/A numAliases = 0;
0N/A enum_ = keyStore.aliases();
0N/A while (enum_.hasMoreElements()) {
0N/A aliases[numAliases] = new String(enum_.nextElement());
0N/A numAliases++;
0N/A }
0N/A }
0N/A return aliases;
0N/A }
0N/A
0N/A /**
0N/A * This method parses a single string of signers separated by commas
0N/A * ("jordan, duke, pippen") into an array of individual strings.
0N/A */
0N/A String[] parseSigners(String signedBy) {
0N/A
0N/A String signers[] = null;
0N/A int numSigners = 1;
0N/A int signedByIndex = 0;
0N/A int commaIndex = 0;
0N/A int signerNum = 0;
0N/A
0N/A // first pass thru "signedBy" counts the number of signers
0N/A while (commaIndex >= 0) {
0N/A commaIndex = signedBy.indexOf(',', signedByIndex);
0N/A if (commaIndex >= 0) {
0N/A numSigners++;
0N/A signedByIndex = commaIndex + 1;
0N/A }
0N/A }
0N/A signers = new String[numSigners];
0N/A
0N/A // second pass thru "signedBy" transfers signers to array
0N/A commaIndex = 0;
0N/A signedByIndex = 0;
0N/A while (commaIndex >= 0) {
0N/A if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) {
0N/A // transfer signer and ignore trailing part of the string
0N/A signers[signerNum] =
0N/A signedBy.substring(signedByIndex, commaIndex).trim();
0N/A signerNum++;
0N/A signedByIndex = commaIndex + 1;
0N/A } else {
0N/A // we are at the end of the string -- transfer signer
0N/A signers[signerNum] = signedBy.substring(signedByIndex).trim();
0N/A }
0N/A }
0N/A return signers;
0N/A }
0N/A
0N/A /**
0N/A * Check to see if the Principal contents are OK
0N/A */
0N/A void verifyPrincipal(String type, String name)
0N/A throws ClassNotFoundException,
0N/A InstantiationException
0N/A {
0N/A if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) ||
0N/A type.equals(PolicyParser.REPLACE_NAME)) {
0N/A return;
0N/A };
0N/A Class<?> PRIN = Class.forName("java.security.Principal");
0N/A Class<?> pc = Class.forName(type, true,
0N/A Thread.currentThread().getContextClassLoader());
0N/A if (!PRIN.isAssignableFrom(pc)) {
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Illegal.Principal.Type.type"));
0N/A Object[] source = {type};
0N/A throw new InstantiationException(form.format(source));
0N/A }
0N/A
0N/A if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) {
0N/A // PolicyParser checks validity of X500Principal name
0N/A // - PolicyTool needs to as well so that it doesn't store
0N/A // an invalid name that can't be read in later
0N/A //
0N/A // this can throw an IllegalArgumentException
0N/A X500Principal newP = new X500Principal(name);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Check to see if the Permission contents are OK
0N/A */
0N/A void verifyPermission(String type,
0N/A String name,
0N/A String actions)
0N/A throws ClassNotFoundException,
0N/A InstantiationException,
0N/A IllegalAccessException,
0N/A NoSuchMethodException,
0N/A InvocationTargetException
0N/A {
0N/A
0N/A //XXX we might want to keep a hash of created factories...
0N/A Class<?> pc = Class.forName(type, true,
0N/A Thread.currentThread().getContextClassLoader());
0N/A Constructor<?> c = null;
3388N/A Vector<String> objects = new Vector<>(2);
0N/A if (name != null) objects.add(name);
0N/A if (actions != null) objects.add(actions);
0N/A switch (objects.size()) {
0N/A case 0:
0N/A try {
0N/A c = pc.getConstructor(NOPARAMS);
0N/A break;
0N/A } catch (NoSuchMethodException ex) {
0N/A // proceed to the one-param constructor
0N/A objects.add(null);
0N/A }
0N/A case 1:
0N/A try {
0N/A c = pc.getConstructor(ONEPARAMS);
0N/A break;
0N/A } catch (NoSuchMethodException ex) {
0N/A // proceed to the two-param constructor
0N/A objects.add(null);
0N/A }
0N/A case 2:
0N/A c = pc.getConstructor(TWOPARAMS);
0N/A break;
0N/A }
0N/A Object parameters[] = objects.toArray();
0N/A Permission p = (Permission)c.newInstance(parameters);
0N/A }
0N/A
0N/A /*
0N/A * Parse command line arguments.
0N/A */
0N/A static void parseArgs(String args[]) {
0N/A /* parse flags */
0N/A int n = 0;
0N/A
0N/A for (n=0; (n < args.length) && args[n].startsWith("-"); n++) {
0N/A
0N/A String flags = args[n];
0N/A
0N/A if (collator.compare(flags, "-file") == 0) {
0N/A if (++n == args.length) usage();
0N/A policyFileName = args[n];
0N/A } else {
0N/A MessageFormat form = new MessageFormat(rb.getString
3050N/A ("Illegal.option.option"));
0N/A Object[] source = { flags };
0N/A System.err.println(form.format(source));
0N/A usage();
0N/A }
0N/A }
0N/A }
0N/A
0N/A static void usage() {
3050N/A System.out.println(rb.getString("Usage.policytool.options."));
0N/A System.out.println();
0N/A System.out.println(rb.getString
3050N/A (".file.file.policy.file.location"));
0N/A System.out.println();
0N/A
0N/A System.exit(1);
0N/A }
0N/A
0N/A /**
0N/A * run the PolicyTool
0N/A */
0N/A public static void main(String args[]) {
0N/A parseArgs(args);
0N/A ToolWindow tw = new ToolWindow(new PolicyTool());
0N/A tw.displayToolWindow(args);
0N/A }
0N/A
0N/A // split instr to words according to capitalization,
0N/A // like, AWTControl -> A W T Control
0N/A // this method is for easy pronounciation
0N/A static String splitToWords(String instr) {
0N/A return instr.replaceAll("([A-Z])", " $1");
0N/A }
0N/A
0N/A}
0N/A
0N/A/**
0N/A * Each entry in the policy configuration file is represented by a
0N/A * PolicyEntry object.
0N/A *
0N/A * A PolicyEntry is a (CodeSource,Permission) pair. The
0N/A * CodeSource contains the (URL, PublicKey) that together identify
0N/A * where the Java bytecodes come from and who (if anyone) signed
0N/A * them. The URL could refer to localhost. The URL could also be
0N/A * null, meaning that this policy entry is given to all comers, as
0N/A * long as they match the signer field. The signer could be null,
0N/A * meaning the code is not signed.
0N/A *
0N/A * The Permission contains the (Type, Name, Action) triplet.
0N/A *
0N/A */
0N/Aclass PolicyEntry {
0N/A
0N/A private CodeSource codesource;
0N/A private PolicyTool tool;
0N/A private PolicyParser.GrantEntry grantEntry;
0N/A private boolean testing = false;
0N/A
0N/A /**
0N/A * Create a PolicyEntry object from the information read in
0N/A * from a policy file.
0N/A */
0N/A PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge)
0N/A throws MalformedURLException, NoSuchMethodException,
0N/A ClassNotFoundException, InstantiationException, IllegalAccessException,
0N/A InvocationTargetException, CertificateException,
0N/A IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
0N/A
0N/A this.tool = tool;
0N/A
0N/A URL location = null;
0N/A
0N/A // construct the CodeSource
0N/A if (ge.codeBase != null)
0N/A location = new URL(ge.codeBase);
0N/A this.codesource = new CodeSource(location,
0N/A (java.security.cert.Certificate[]) null);
0N/A
0N/A if (testing) {
0N/A System.out.println("Adding Policy Entry:");
0N/A System.out.println(" CodeBase = " + location);
0N/A System.out.println(" Signers = " + ge.signedBy);
0N/A System.out.println(" with " + ge.principals.size() +
0N/A " Principals");
0N/A }
0N/A
0N/A this.grantEntry = ge;
0N/A }
0N/A
0N/A /**
0N/A * get the codesource associated with this PolicyEntry
0N/A */
0N/A CodeSource getCodeSource() {
0N/A return codesource;
0N/A }
0N/A
0N/A /**
0N/A * get the GrantEntry associated with this PolicyEntry
0N/A */
0N/A PolicyParser.GrantEntry getGrantEntry() {
0N/A return grantEntry;
0N/A }
0N/A
0N/A /**
0N/A * convert the header portion, i.e. codebase, signer, principals, of
0N/A * this policy entry into a string
0N/A */
0N/A String headerToString() {
0N/A String pString = principalsToString();
0N/A if (pString.length() == 0) {
0N/A return codebaseToString();
0N/A } else {
0N/A return codebaseToString() + ", " + pString;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * convert the Codebase/signer portion of this policy entry into a string
0N/A */
0N/A String codebaseToString() {
0N/A
0N/A String stringEntry = new String();
0N/A
0N/A if (grantEntry.codeBase != null &&
0N/A grantEntry.codeBase.equals("") == false)
0N/A stringEntry = stringEntry.concat
0N/A ("CodeBase \"" +
0N/A grantEntry.codeBase +
0N/A "\"");
0N/A
0N/A if (grantEntry.signedBy != null &&
0N/A grantEntry.signedBy.equals("") == false)
0N/A stringEntry = ((stringEntry.length() > 0) ?
0N/A stringEntry.concat(", SignedBy \"" +
0N/A grantEntry.signedBy +
0N/A "\"") :
0N/A stringEntry.concat("SignedBy \"" +
0N/A grantEntry.signedBy +
0N/A "\""));
0N/A
0N/A if (stringEntry.length() == 0)
0N/A return new String("CodeBase <ALL>");
0N/A return stringEntry;
0N/A }
0N/A
0N/A /**
0N/A * convert the Principals portion of this policy entry into a string
0N/A */
0N/A String principalsToString() {
0N/A String result = "";
0N/A if ((grantEntry.principals != null) &&
0N/A (!grantEntry.principals.isEmpty())) {
0N/A StringBuffer buffer = new StringBuffer(200);
0N/A ListIterator<PolicyParser.PrincipalEntry> list =
0N/A grantEntry.principals.listIterator();
0N/A while (list.hasNext()) {
0N/A PolicyParser.PrincipalEntry pppe = list.next();
0N/A buffer.append(" Principal " + pppe.getDisplayClass() + " " +
0N/A pppe.getDisplayName(true));
0N/A if (list.hasNext()) buffer.append(", ");
0N/A }
0N/A result = buffer.toString();
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A /**
0N/A * convert this policy entry into a PolicyParser.PermissionEntry
0N/A */
0N/A PolicyParser.PermissionEntry toPermissionEntry(Permission perm) {
0N/A
0N/A String actions = null;
0N/A
0N/A // get the actions
0N/A if (perm.getActions() != null &&
0N/A perm.getActions().trim() != "")
0N/A actions = perm.getActions();
0N/A
0N/A PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry
0N/A (perm.getClass().getName(),
0N/A perm.getName(),
0N/A actions);
0N/A return pe;
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * The main window for the PolicyTool
0N/A */
0N/Aclass ToolWindow extends Frame {
0N/A // use serialVersionUID from JDK 1.2.2 for interoperability
0N/A private static final long serialVersionUID = 5682568601210376777L;
0N/A
0N/A /* external paddings */
0N/A public static final Insets TOP_PADDING = new Insets(25,0,0,0);
0N/A public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);
0N/A public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0);
0N/A public static final Insets LR_PADDING = new Insets(0,10,0,10);
0N/A public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);
0N/A public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);
0N/A public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);
0N/A public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);
0N/A public static final Insets R_BOTTOM_PADDING = new Insets(0,0,5,10);
0N/A
0N/A /* buttons and menus */
0N/A public static final String NEW_POLICY_FILE =
0N/A PolicyTool.rb.getString("New");
0N/A public static final String OPEN_POLICY_FILE =
0N/A PolicyTool.rb.getString("Open");
0N/A public static final String SAVE_POLICY_FILE =
0N/A PolicyTool.rb.getString("Save");
0N/A public static final String SAVE_AS_POLICY_FILE =
3050N/A PolicyTool.rb.getString("Save.As");
0N/A public static final String VIEW_WARNINGS =
3050N/A PolicyTool.rb.getString("View.Warning.Log");
0N/A public static final String QUIT =
0N/A PolicyTool.rb.getString("Exit");
0N/A public static final String ADD_POLICY_ENTRY =
3050N/A PolicyTool.rb.getString("Add.Policy.Entry");
0N/A public static final String EDIT_POLICY_ENTRY =
3050N/A PolicyTool.rb.getString("Edit.Policy.Entry");
0N/A public static final String REMOVE_POLICY_ENTRY =
3050N/A PolicyTool.rb.getString("Remove.Policy.Entry");
0N/A public static final String EDIT_KEYSTORE =
0N/A PolicyTool.rb.getString("Edit");
0N/A public static final String ADD_PUBKEY_ALIAS =
3050N/A PolicyTool.rb.getString("Add.Public.Key.Alias");
0N/A public static final String REMOVE_PUBKEY_ALIAS =
3050N/A PolicyTool.rb.getString("Remove.Public.Key.Alias");
0N/A
0N/A /* gridbag index for components in the main window (MW) */
0N/A public static final int MW_FILENAME_LABEL = 0;
0N/A public static final int MW_FILENAME_TEXTFIELD = 1;
0N/A public static final int MW_PANEL = 2;
0N/A public static final int MW_ADD_BUTTON = 0;
0N/A public static final int MW_EDIT_BUTTON = 1;
0N/A public static final int MW_REMOVE_BUTTON = 2;
0N/A public static final int MW_POLICY_LIST = 3; // follows MW_PANEL
0N/A
0N/A private PolicyTool tool;
0N/A
0N/A /**
0N/A * Constructor
0N/A */
0N/A ToolWindow(PolicyTool tool) {
0N/A this.tool = tool;
0N/A }
0N/A
0N/A /**
0N/A * Initialize the PolicyTool window with the necessary components
0N/A */
0N/A private void initWindow() {
0N/A
0N/A // create the top menu bar
0N/A MenuBar menuBar = new MenuBar();
0N/A
0N/A // create a File menu
0N/A Menu menu = new Menu(PolicyTool.rb.getString("File"));
0N/A menu.add(NEW_POLICY_FILE);
0N/A menu.add(OPEN_POLICY_FILE);
0N/A menu.add(SAVE_POLICY_FILE);
0N/A menu.add(SAVE_AS_POLICY_FILE);
0N/A menu.add(VIEW_WARNINGS);
0N/A menu.add(QUIT);
0N/A menu.addActionListener(new FileMenuListener(tool, this));
0N/A menuBar.add(menu);
0N/A setMenuBar(menuBar);
0N/A
0N/A // create a KeyStore menu
0N/A menu = new Menu(PolicyTool.rb.getString("KeyStore"));
0N/A menu.add(EDIT_KEYSTORE);
0N/A menu.addActionListener(new MainWindowListener(tool, this));
0N/A menuBar.add(menu);
0N/A setMenuBar(menuBar);
0N/A
0N/A
0N/A // policy entry listing
3050N/A Label label = new Label(PolicyTool.rb.getString("Policy.File."));
0N/A addNewComponent(this, label, MW_FILENAME_LABEL,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A TOP_BOTTOM_PADDING);
0N/A TextField tf = new TextField(50);
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Policy.File."));
0N/A tf.setEditable(false);
0N/A addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A TOP_BOTTOM_PADDING);
0N/A
0N/A
0N/A // add ADD/REMOVE/EDIT buttons in a new panel
0N/A Panel panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
0N/A Button button = new Button(ADD_POLICY_ENTRY);
0N/A button.addActionListener(new MainWindowListener(tool, this));
0N/A addNewComponent(panel, button, MW_ADD_BUTTON,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A LR_PADDING);
0N/A
0N/A button = new Button(EDIT_POLICY_ENTRY);
0N/A button.addActionListener(new MainWindowListener(tool, this));
0N/A addNewComponent(panel, button, MW_EDIT_BUTTON,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A LR_PADDING);
0N/A
0N/A button = new Button(REMOVE_POLICY_ENTRY);
0N/A button.addActionListener(new MainWindowListener(tool, this));
0N/A addNewComponent(panel, button, MW_REMOVE_BUTTON,
0N/A 2, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A LR_PADDING);
0N/A
0N/A addNewComponent(this, panel, MW_PANEL,
0N/A 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A BOTTOM_PADDING);
0N/A
0N/A
0N/A String policyFile = tool.getPolicyFileName();
0N/A if (policyFile == null) {
0N/A String userHome;
0N/A userHome = java.security.AccessController.doPrivileged(
0N/A new sun.security.action.GetPropertyAction("user.home"));
0N/A policyFile = userHome + File.separatorChar + ".java.policy";
0N/A }
0N/A
0N/A try {
0N/A // open the policy file
0N/A tool.openPolicy(policyFile);
0N/A
0N/A // display the policy entries via the policy list textarea
0N/A List list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, this));
0N/A PolicyEntry entries[] = tool.getEntry();
0N/A if (entries != null) {
0N/A for (int i = 0; i < entries.length; i++)
0N/A list.add(entries[i].headerToString());
0N/A }
0N/A TextField newFilename = (TextField)
0N/A getComponent(MW_FILENAME_TEXTFIELD);
0N/A newFilename.setText(policyFile);
0N/A initPolicyList(list);
0N/A
0N/A } catch (FileNotFoundException fnfe) {
0N/A // add blank policy listing
0N/A List list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, this));
0N/A initPolicyList(list);
0N/A tool.setPolicyFileName(null);
0N/A tool.modified = false;
0N/A setVisible(true);
0N/A
0N/A // just add warning
0N/A tool.warnings.addElement(fnfe.toString());
0N/A
0N/A } catch (Exception e) {
0N/A // add blank policy listing
0N/A List list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, this));
0N/A initPolicyList(list);
0N/A tool.setPolicyFileName(null);
0N/A tool.modified = false;
0N/A setVisible(true);
0N/A
0N/A // display the error
0N/A MessageFormat form = new MessageFormat(PolicyTool.rb.getString
3050N/A ("Could.not.open.policy.file.policyFile.e.toString."));
0N/A Object[] source = {policyFile, e.toString()};
0N/A displayErrorDialog(null, form.format(source));
0N/A }
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Add a component to the PolicyTool window
0N/A */
0N/A void addNewComponent(Container container, Component component,
0N/A int index, int gridx, int gridy, int gridwidth, int gridheight,
0N/A double weightx, double weighty, int fill, Insets is) {
0N/A
0N/A // add the component at the specified gridbag index
0N/A container.add(component, index);
0N/A
0N/A // set the constraints
0N/A GridBagLayout gbl = (GridBagLayout)container.getLayout();
0N/A GridBagConstraints gbc = new GridBagConstraints();
0N/A gbc.gridx = gridx;
0N/A gbc.gridy = gridy;
0N/A gbc.gridwidth = gridwidth;
0N/A gbc.gridheight = gridheight;
0N/A gbc.weightx = weightx;
0N/A gbc.weighty = weighty;
0N/A gbc.fill = fill;
0N/A if (is != null) gbc.insets = is;
0N/A gbl.setConstraints(component, gbc);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Add a component to the PolicyTool window without external padding
0N/A */
0N/A void addNewComponent(Container container, Component component,
0N/A int index, int gridx, int gridy, int gridwidth, int gridheight,
0N/A double weightx, double weighty, int fill) {
0N/A
0N/A // delegate with "null" external padding
0N/A addNewComponent(container, component, index, gridx, gridy,
0N/A gridwidth, gridheight, weightx, weighty,
0N/A fill, null);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Init the policy_entry_list TEXTAREA component in the
0N/A * PolicyTool window
0N/A */
0N/A void initPolicyList(List policyList) {
0N/A
0N/A // add the policy list to the window
0N/A addNewComponent(this, policyList, MW_POLICY_LIST,
0N/A 0, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);
0N/A }
0N/A
0N/A /**
0N/A * Replace the policy_entry_list TEXTAREA component in the
0N/A * PolicyTool window with an updated one.
0N/A */
0N/A void replacePolicyList(List policyList) {
0N/A
0N/A // remove the original list of Policy Entries
0N/A // and add the new list of entries
0N/A List list = (List)getComponent(MW_POLICY_LIST);
0N/A list.removeAll();
0N/A String newItems[] = policyList.getItems();
0N/A for (int i = 0; i < newItems.length; i++)
0N/A list.add(newItems[i]);
0N/A }
0N/A
0N/A /**
0N/A * display the main PolicyTool window
0N/A */
0N/A void displayToolWindow(String args[]) {
0N/A
3050N/A setTitle(PolicyTool.rb.getString("Policy.Tool"));
0N/A setResizable(true);
0N/A addWindowListener(new ToolWindowListener(this));
0N/A setBounds(135, 80, 500, 500);
0N/A setLayout(new GridBagLayout());
0N/A
0N/A initWindow();
0N/A
0N/A // display it
0N/A setVisible(true);
0N/A
0N/A if (tool.newWarning == true) {
0N/A displayStatusDialog(this, PolicyTool.rb.getString
3050N/A ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * displays a dialog box describing an error which occurred.
0N/A */
0N/A void displayErrorDialog(Window w, String error) {
0N/A ToolDialog ed = new ToolDialog
0N/A (PolicyTool.rb.getString("Error"), tool, this, true);
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = ((w == null) ?
0N/A getLocationOnScreen() : w.getLocationOnScreen());
0N/A ed.setBounds(location.x + 50, location.y + 50, 600, 100);
0N/A ed.setLayout(new GridBagLayout());
0N/A
0N/A Label label = new Label(error);
0N/A addNewComponent(ed, label, 0,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener(new ErrorOKButtonListener(ed));
0N/A addNewComponent(ed, okButton, 1,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A
0N/A ed.pack();
0N/A ed.setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * displays a dialog box describing an error which occurred.
0N/A */
0N/A void displayErrorDialog(Window w, Throwable t) {
0N/A if (t instanceof NoDisplayException) {
0N/A return;
0N/A }
0N/A displayErrorDialog(w, t.toString());
0N/A }
0N/A
0N/A /**
0N/A * displays a dialog box describing the status of an event
0N/A */
0N/A void displayStatusDialog(Window w, String status) {
0N/A ToolDialog sd = new ToolDialog
0N/A (PolicyTool.rb.getString("Status"), tool, this, true);
0N/A
0N/A // find the location of the PolicyTool gui
0N/A Point location = ((w == null) ?
0N/A getLocationOnScreen() : w.getLocationOnScreen());
0N/A sd.setBounds(location.x + 50, location.y + 50, 500, 100);
0N/A sd.setLayout(new GridBagLayout());
0N/A
0N/A Label label = new Label(status);
0N/A addNewComponent(sd, label, 0,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener(new StatusOKButtonListener(sd));
0N/A addNewComponent(sd, okButton, 1,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A sd.pack();
0N/A sd.setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * display the warning log
0N/A */
0N/A void displayWarningLog(Window w) {
0N/A
0N/A ToolDialog wd = new ToolDialog
0N/A (PolicyTool.rb.getString("Warning"), tool, this, true);
0N/A
0N/A // find the location of the PolicyTool gui
0N/A Point location = ((w == null) ?
0N/A getLocationOnScreen() : w.getLocationOnScreen());
0N/A wd.setBounds(location.x + 50, location.y + 50, 500, 100);
0N/A wd.setLayout(new GridBagLayout());
0N/A
0N/A TextArea ta = new TextArea();
0N/A ta.setEditable(false);
0N/A for (int i = 0; i < tool.warnings.size(); i++) {
0N/A ta.append(tool.warnings.elementAt(i));
3050N/A ta.append(PolicyTool.rb.getString("NEWLINE"));
0N/A }
0N/A addNewComponent(wd, ta, 0,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A BOTTOM_PADDING);
0N/A ta.setFocusable(false);
0N/A
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener(new CancelButtonListener(wd));
0N/A addNewComponent(wd, okButton, 1,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A LR_PADDING);
0N/A
0N/A wd.pack();
0N/A wd.setVisible(true);
0N/A }
0N/A
0N/A char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) {
0N/A
0N/A final ToolDialog tw = new ToolDialog
0N/A (title, tool, this, true);
0N/A Point location = ((w == null) ?
0N/A getLocationOnScreen() : w.getLocationOnScreen());
0N/A tw.setBounds(location.x + 75, location.y + 100, 400, 150);
0N/A tw.setLayout(new GridBagLayout());
0N/A
0N/A TextArea ta = new TextArea(prompt, 10, 50, TextArea.SCROLLBARS_VERTICAL_ONLY);
0N/A ta.setEditable(false);
0N/A addNewComponent(tw, ta, 0,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A ta.setFocusable(false);
0N/A
0N/A Panel panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
0N/A // StringBuffer to store button press. Must be final.
0N/A final StringBuffer chooseResult = new StringBuffer();
0N/A
0N/A Button button = new Button(yes);
0N/A button.addActionListener(new ActionListener() {
0N/A public void actionPerformed(ActionEvent e) {
0N/A chooseResult.append('Y');
0N/A tw.setVisible(false);
0N/A tw.dispose();
0N/A }
0N/A });
0N/A addNewComponent(panel, button, 0,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A LR_PADDING);
0N/A
0N/A button = new Button(no);
0N/A button.addActionListener(new ActionListener() {
0N/A public void actionPerformed(ActionEvent e) {
0N/A chooseResult.append('N');
0N/A tw.setVisible(false);
0N/A tw.dispose();
0N/A }
0N/A });
0N/A addNewComponent(panel, button, 1,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A LR_PADDING);
0N/A
0N/A addNewComponent(tw, panel, 1,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A
0N/A tw.pack();
0N/A tw.setVisible(true);
0N/A if (chooseResult.length() > 0) {
0N/A return chooseResult.charAt(0);
0N/A } else {
0N/A // I did encounter this once, don't why.
0N/A return 'N';
0N/A }
0N/A }
0N/A
0N/A}
0N/A
0N/A/**
0N/A * General dialog window
0N/A */
0N/Aclass ToolDialog extends Dialog {
0N/A // use serialVersionUID from JDK 1.2.2 for interoperability
0N/A private static final long serialVersionUID = -372244357011301190L;
0N/A
0N/A /* necessary constants */
0N/A public static final int NOACTION = 0;
0N/A public static final int QUIT = 1;
0N/A public static final int NEW = 2;
0N/A public static final int OPEN = 3;
0N/A
0N/A public static final String ALL_PERM_CLASS =
0N/A "java.security.AllPermission";
0N/A public static final String FILE_PERM_CLASS =
0N/A "java.io.FilePermission";
0N/A
0N/A public static final String X500_PRIN_CLASS =
0N/A "javax.security.auth.x500.X500Principal";
0N/A
0N/A /* popup menus */
0N/A public static final String PERM =
0N/A PolicyTool.rb.getString
3050N/A ("Permission.");
0N/A
0N/A public static final String PRIN_TYPE =
3050N/A PolicyTool.rb.getString("Principal.Type.");
0N/A public static final String PRIN_NAME =
3050N/A PolicyTool.rb.getString("Principal.Name.");
0N/A
0N/A /* more popu menus */
0N/A public static final String PERM_NAME =
0N/A PolicyTool.rb.getString
3050N/A ("Target.Name.");
0N/A
0N/A /* and more popup menus */
0N/A public static final String PERM_ACTIONS =
0N/A PolicyTool.rb.getString
3050N/A ("Actions.");
0N/A
0N/A /* gridbag index for display PolicyEntry (PE) components */
0N/A public static final int PE_CODEBASE_LABEL = 0;
0N/A public static final int PE_CODEBASE_TEXTFIELD = 1;
0N/A public static final int PE_SIGNEDBY_LABEL = 2;
0N/A public static final int PE_SIGNEDBY_TEXTFIELD = 3;
0N/A
0N/A public static final int PE_PANEL0 = 4;
0N/A public static final int PE_ADD_PRIN_BUTTON = 0;
0N/A public static final int PE_EDIT_PRIN_BUTTON = 1;
0N/A public static final int PE_REMOVE_PRIN_BUTTON = 2;
0N/A
0N/A public static final int PE_PRIN_LABEL = 5;
0N/A public static final int PE_PRIN_LIST = 6;
0N/A
0N/A public static final int PE_PANEL1 = 7;
0N/A public static final int PE_ADD_PERM_BUTTON = 0;
0N/A public static final int PE_EDIT_PERM_BUTTON = 1;
0N/A public static final int PE_REMOVE_PERM_BUTTON = 2;
0N/A
0N/A public static final int PE_PERM_LIST = 8;
0N/A
0N/A public static final int PE_PANEL2 = 9;
0N/A public static final int PE_CANCEL_BUTTON = 1;
0N/A public static final int PE_DONE_BUTTON = 0;
0N/A
0N/A /* the gridbag index for components in the Principal Dialog (PRD) */
0N/A public static final int PRD_DESC_LABEL = 0;
0N/A public static final int PRD_PRIN_CHOICE = 1;
0N/A public static final int PRD_PRIN_TEXTFIELD = 2;
0N/A public static final int PRD_NAME_LABEL = 3;
0N/A public static final int PRD_NAME_TEXTFIELD = 4;
0N/A public static final int PRD_CANCEL_BUTTON = 6;
0N/A public static final int PRD_OK_BUTTON = 5;
0N/A
0N/A /* the gridbag index for components in the Permission Dialog (PD) */
0N/A public static final int PD_DESC_LABEL = 0;
0N/A public static final int PD_PERM_CHOICE = 1;
0N/A public static final int PD_PERM_TEXTFIELD = 2;
0N/A public static final int PD_NAME_CHOICE = 3;
0N/A public static final int PD_NAME_TEXTFIELD = 4;
0N/A public static final int PD_ACTIONS_CHOICE = 5;
0N/A public static final int PD_ACTIONS_TEXTFIELD = 6;
0N/A public static final int PD_SIGNEDBY_LABEL = 7;
0N/A public static final int PD_SIGNEDBY_TEXTFIELD = 8;
0N/A public static final int PD_CANCEL_BUTTON = 10;
0N/A public static final int PD_OK_BUTTON = 9;
0N/A
0N/A /* modes for KeyStore */
0N/A public static final int EDIT_KEYSTORE = 0;
0N/A
0N/A /* the gridbag index for components in the Change KeyStore Dialog (KSD) */
0N/A public static final int KSD_NAME_LABEL = 0;
0N/A public static final int KSD_NAME_TEXTFIELD = 1;
0N/A public static final int KSD_TYPE_LABEL = 2;
0N/A public static final int KSD_TYPE_TEXTFIELD = 3;
0N/A public static final int KSD_PROVIDER_LABEL = 4;
0N/A public static final int KSD_PROVIDER_TEXTFIELD = 5;
0N/A public static final int KSD_PWD_URL_LABEL = 6;
0N/A public static final int KSD_PWD_URL_TEXTFIELD = 7;
0N/A public static final int KSD_CANCEL_BUTTON = 9;
0N/A public static final int KSD_OK_BUTTON = 8;
0N/A
0N/A /* the gridbag index for components in the User Save Changes Dialog (USC) */
0N/A public static final int USC_LABEL = 0;
0N/A public static final int USC_PANEL = 1;
0N/A public static final int USC_YES_BUTTON = 0;
0N/A public static final int USC_NO_BUTTON = 1;
0N/A public static final int USC_CANCEL_BUTTON = 2;
0N/A
0N/A /* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */
0N/A public static final int CRPE_LABEL1 = 0;
0N/A public static final int CRPE_LABEL2 = 1;
0N/A public static final int CRPE_PANEL = 2;
0N/A public static final int CRPE_PANEL_OK = 0;
0N/A public static final int CRPE_PANEL_CANCEL = 1;
0N/A
0N/A /* some private static finals */
0N/A private static final int PERMISSION = 0;
0N/A private static final int PERMISSION_NAME = 1;
0N/A private static final int PERMISSION_ACTIONS = 2;
0N/A private static final int PERMISSION_SIGNEDBY = 3;
0N/A private static final int PRINCIPAL_TYPE = 4;
0N/A private static final int PRINCIPAL_NAME = 5;
0N/A
0N/A public static java.util.ArrayList<Perm> PERM_ARRAY;
0N/A public static java.util.ArrayList<Prin> PRIN_ARRAY;
0N/A PolicyTool tool;
0N/A ToolWindow tw;
0N/A
0N/A static {
0N/A
0N/A // set up permission objects
0N/A
0N/A PERM_ARRAY = new java.util.ArrayList<Perm>();
0N/A PERM_ARRAY.add(new AllPerm());
0N/A PERM_ARRAY.add(new AudioPerm());
0N/A PERM_ARRAY.add(new AuthPerm());
0N/A PERM_ARRAY.add(new AWTPerm());
0N/A PERM_ARRAY.add(new DelegationPerm());
0N/A PERM_ARRAY.add(new FilePerm());
1535N/A PERM_ARRAY.add(new InqSecContextPerm());
0N/A PERM_ARRAY.add(new LogPerm());
0N/A PERM_ARRAY.add(new MgmtPerm());
0N/A PERM_ARRAY.add(new MBeanPerm());
0N/A PERM_ARRAY.add(new MBeanSvrPerm());
0N/A PERM_ARRAY.add(new MBeanTrustPerm());
0N/A PERM_ARRAY.add(new NetPerm());
0N/A PERM_ARRAY.add(new PrivCredPerm());
0N/A PERM_ARRAY.add(new PropPerm());
0N/A PERM_ARRAY.add(new ReflectPerm());
0N/A PERM_ARRAY.add(new RuntimePerm());
0N/A PERM_ARRAY.add(new SecurityPerm());
0N/A PERM_ARRAY.add(new SerialPerm());
0N/A PERM_ARRAY.add(new ServicePerm());
0N/A PERM_ARRAY.add(new SocketPerm());
0N/A PERM_ARRAY.add(new SQLPerm());
0N/A PERM_ARRAY.add(new SSLPerm());
0N/A PERM_ARRAY.add(new SubjDelegPerm());
0N/A
0N/A // set up principal objects
0N/A
0N/A PRIN_ARRAY = new java.util.ArrayList<Prin>();
0N/A PRIN_ARRAY.add(new KrbPrin());
0N/A PRIN_ARRAY.add(new X500Prin());
0N/A }
0N/A
0N/A ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) {
0N/A super(tw, modal);
0N/A setTitle(title);
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A addWindowListener(new ChildWindowListener(this));
0N/A }
0N/A
0N/A /**
0N/A * get the Perm instance based on either the (shortened) class name
0N/A * or the fully qualified class name
0N/A */
0N/A static Perm getPerm(String clazz, boolean fullClassName) {
0N/A for (int i = 0; i < PERM_ARRAY.size(); i++) {
0N/A Perm next = PERM_ARRAY.get(i);
0N/A if (fullClassName) {
0N/A if (next.FULL_CLASS.equals(clazz)) {
0N/A return next;
0N/A }
0N/A } else {
0N/A if (next.CLASS.equals(clazz)) {
0N/A return next;
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * get the Prin instance based on either the (shortened) class name
0N/A * or the fully qualified class name
0N/A */
0N/A static Prin getPrin(String clazz, boolean fullClassName) {
0N/A for (int i = 0; i < PRIN_ARRAY.size(); i++) {
0N/A Prin next = PRIN_ARRAY.get(i);
0N/A if (fullClassName) {
0N/A if (next.FULL_CLASS.equals(clazz)) {
0N/A return next;
0N/A }
0N/A } else {
0N/A if (next.CLASS.equals(clazz)) {
0N/A return next;
0N/A }
0N/A }
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * pop up a dialog so the user can enter info to add a new PolicyEntry
0N/A * - if edit is TRUE, then the user is editing an existing entry
0N/A * and we should display the original info as well.
0N/A *
0N/A * - the other reason we need the 'edit' boolean is we need to know
0N/A * when we are adding a NEW policy entry. in this case, we can
0N/A * not simply update the existing entry, because it doesn't exist.
0N/A * we ONLY update the GUI listing/info, and then when the user
0N/A * finally clicks 'OK' or 'DONE', then we can collect that info
0N/A * and add it to the policy.
0N/A */
0N/A void displayPolicyEntryDialog(boolean edit) {
0N/A
0N/A int listIndex = 0;
0N/A PolicyEntry entries[] = null;
0N/A TaggedList prinList = new TaggedList(3, false);
0N/A prinList.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Principal.List"));
0N/A prinList.addActionListener
0N/A (new EditPrinButtonListener(tool, tw, this, edit));
0N/A TaggedList permList = new TaggedList(10, false);
0N/A permList.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Permission.List"));
0N/A permList.addActionListener
0N/A (new EditPermButtonListener(tool, tw, this, edit));
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = tw.getLocationOnScreen();
0N/A setBounds(location.x + 75, location.y + 200, 650, 500);
0N/A setLayout(new GridBagLayout());
0N/A setResizable(true);
0N/A
0N/A if (edit) {
0N/A // get the selected item
0N/A entries = tool.getEntry();
0N/A List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A listIndex = policyList.getSelectedIndex();
0N/A
0N/A // get principal list
0N/A LinkedList principals =
0N/A entries[listIndex].getGrantEntry().principals;
0N/A for (int i = 0; i < principals.size(); i++) {
0N/A String prinString = null;
0N/A PolicyParser.PrincipalEntry nextPrin =
0N/A (PolicyParser.PrincipalEntry)principals.get(i);
0N/A prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin);
0N/A }
0N/A
0N/A // get permission list
0N/A Vector<PolicyParser.PermissionEntry> permissions =
0N/A entries[listIndex].getGrantEntry().permissionEntries;
0N/A for (int i = 0; i < permissions.size(); i++) {
0N/A String permString = null;
0N/A PolicyParser.PermissionEntry nextPerm =
0N/A permissions.elementAt(i);
0N/A permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm);
0N/A }
0N/A }
0N/A
0N/A // codebase label and textfield
3050N/A Label label = new Label(PolicyTool.rb.getString("CodeBase."));
0N/A tw.addNewComponent(this, label, PE_CODEBASE_LABEL,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A TextField tf;
0N/A tf = (edit ?
0N/A new TextField(entries[listIndex].getGrantEntry().codeBase, 60) :
0N/A new TextField(60));
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Code.Base"));
0N/A tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A
0N/A // signedby label and textfield
3050N/A label = new Label(PolicyTool.rb.getString("SignedBy."));
0N/A tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A tf = (edit ?
0N/A new TextField(entries[listIndex].getGrantEntry().signedBy, 60) :
0N/A new TextField(60));
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Signed.By."));
0N/A tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,
0N/A 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A
0N/A // panel for principal buttons
0N/A Panel panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
3050N/A Button button = new Button(PolicyTool.rb.getString("Add.Principal"));
0N/A button.addActionListener
0N/A (new AddPrinButtonListener(tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,
0N/A 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
3050N/A button = new Button(PolicyTool.rb.getString("Edit.Principal"));
0N/A button.addActionListener(new EditPrinButtonListener
0N/A (tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,
0N/A 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
3050N/A button = new Button(PolicyTool.rb.getString("Remove.Principal"));
0N/A button.addActionListener(new RemovePrinButtonListener
0N/A (tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,
0N/A 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
0N/A tw.addNewComponent(this, panel, PE_PANEL0,
0N/A 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
0N/A // principal label and list
3050N/A label = new Label(PolicyTool.rb.getString("Principals."));
0N/A tw.addNewComponent(this, label, PE_PRIN_LABEL,
0N/A 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A tw.addNewComponent(this, prinList, PE_PRIN_LIST,
0N/A 1, 3, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // panel for permission buttons
0N/A panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
3050N/A button = new Button(PolicyTool.rb.getString(".Add.Permission"));
0N/A button.addActionListener(new AddPermButtonListener
0N/A (tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,
0N/A 0, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
3050N/A button = new Button(PolicyTool.rb.getString(".Edit.Permission"));
0N/A button.addActionListener(new EditPermButtonListener
0N/A (tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,
0N/A 1, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
0N/A
3050N/A button = new Button(PolicyTool.rb.getString("Remove.Permission"));
0N/A button.addActionListener(new RemovePermButtonListener
0N/A (tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,
0N/A 2, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);
0N/A
0N/A tw.addNewComponent(this, panel, PE_PANEL1,
0N/A 0, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,
0N/A tw.LITE_BOTTOM_PADDING);
0N/A
0N/A // permission list
0N/A tw.addNewComponent(this, permList, PE_PERM_LIST,
0N/A 0, 5, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A
0N/A // panel for Done and Cancel buttons
0N/A panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
0N/A // Done Button
0N/A button = new Button(PolicyTool.rb.getString("Done"));
0N/A button.addActionListener
0N/A (new AddEntryDoneButtonListener(tool, tw, this, edit));
0N/A tw.addNewComponent(panel, button, PE_DONE_BUTTON,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.LR_PADDING);
0N/A
0N/A // Cancel Button
0N/A button = new Button(PolicyTool.rb.getString("Cancel"));
0N/A button.addActionListener(new CancelButtonListener(this));
0N/A tw.addNewComponent(panel, button, PE_CANCEL_BUTTON,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.LR_PADDING);
0N/A
0N/A // add the panel
0N/A tw.addNewComponent(this, panel, PE_PANEL2,
0N/A 0, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A
0N/A setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * Read all the Policy information data in the dialog box
0N/A * and construct a PolicyEntry object with it.
0N/A */
0N/A PolicyEntry getPolicyEntryFromDialog()
0N/A throws InvalidParameterException, MalformedURLException,
0N/A NoSuchMethodException, ClassNotFoundException, InstantiationException,
0N/A IllegalAccessException, InvocationTargetException,
0N/A CertificateException, IOException, Exception {
0N/A
0N/A // get the Codebase
0N/A TextField tf = (TextField)getComponent(PE_CODEBASE_TEXTFIELD);
0N/A String codebase = null;
0N/A if (tf.getText().trim().equals("") == false)
0N/A codebase = new String(tf.getText().trim());
0N/A
0N/A // get the SignedBy
0N/A tf = (TextField)getComponent(PE_SIGNEDBY_TEXTFIELD);
0N/A String signedby = null;
0N/A if (tf.getText().trim().equals("") == false)
0N/A signedby = new String(tf.getText().trim());
0N/A
0N/A // construct a new GrantEntry
0N/A PolicyParser.GrantEntry ge =
0N/A new PolicyParser.GrantEntry(signedby, codebase);
0N/A
0N/A // get the new Principals
3388N/A LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();
0N/A TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
0N/A for (int i = 0; i < prinList.getItemCount(); i++) {
0N/A prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));
0N/A }
0N/A ge.principals = prins;
0N/A
0N/A // get the new Permissions
3388N/A Vector<PolicyParser.PermissionEntry> perms = new Vector<>();
0N/A TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
0N/A for (int i = 0; i < permList.getItemCount(); i++) {
0N/A perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));
0N/A }
0N/A ge.permissionEntries = perms;
0N/A
0N/A // construct a new PolicyEntry object
0N/A PolicyEntry entry = new PolicyEntry(tool, ge);
0N/A
0N/A return entry;
0N/A }
0N/A
0N/A /**
0N/A * display a dialog box for the user to enter KeyStore information
0N/A */
0N/A void keyStoreDialog(int mode) {
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = tw.getLocationOnScreen();
0N/A setBounds(location.x + 25, location.y + 100, 500, 300);
0N/A setLayout(new GridBagLayout());
0N/A
0N/A if (mode == EDIT_KEYSTORE) {
0N/A
0N/A // KeyStore label and textfield
0N/A Label label = new Label
3050N/A (PolicyTool.rb.getString("KeyStore.URL."));
0N/A tw.addNewComponent(this, label, KSD_NAME_LABEL,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A TextField tf = new TextField(tool.getKeyStoreName(), 30);
0N/A
0N/A // URL to U R L, so that accessibility reader will pronounce well
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("KeyStore.U.R.L."));
0N/A tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,
0N/A 1, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // KeyStore type and textfield
3050N/A label = new Label(PolicyTool.rb.getString("KeyStore.Type."));
0N/A tw.addNewComponent(this, label, KSD_TYPE_LABEL,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A tf = new TextField(tool.getKeyStoreType(), 30);
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("KeyStore.Type."));
0N/A tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,
0N/A 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // KeyStore provider and textfield
0N/A label = new Label(PolicyTool.rb.getString
3050N/A ("KeyStore.Provider."));
0N/A tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,
0N/A 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A tf = new TextField(tool.getKeyStoreProvider(), 30);
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("KeyStore.Provider."));
0N/A tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,
0N/A 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // KeyStore password URL and textfield
0N/A label = new Label(PolicyTool.rb.getString
3050N/A ("KeyStore.Password.URL."));
0N/A tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,
0N/A 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A tf = new TextField(tool.getKeyStorePwdURL(), 30);
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("KeyStore.Password.U.R.L."));
0N/A tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,
0N/A 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // OK button
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener
0N/A (new ChangeKeyStoreOKButtonListener(tool, tw, this));
0N/A tw.addNewComponent(this, okButton, KSD_OK_BUTTON,
0N/A 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A
0N/A // cancel button
0N/A Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
0N/A cancelButton.addActionListener(new CancelButtonListener(this));
0N/A tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,
0N/A 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);
0N/A
0N/A }
0N/A setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * display a dialog box for the user to input Principal info
0N/A *
0N/A * if editPolicyEntry is false, then we are adding Principals to
0N/A * a new PolicyEntry, and we only update the GUI listing
0N/A * with the new Principal.
0N/A *
0N/A * if edit is true, then we are editing an existing Policy entry.
0N/A */
0N/A void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) {
0N/A
0N/A PolicyParser.PrincipalEntry editMe = null;
0N/A
0N/A // get the Principal selected from the Principal List
0N/A TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);
0N/A int prinIndex = prinList.getSelectedIndex();
0N/A
0N/A if (edit) {
0N/A editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex);
0N/A }
0N/A
0N/A ToolDialog newTD = new ToolDialog
0N/A (PolicyTool.rb.getString("Principals"), tool, tw, true);
0N/A newTD.addWindowListener(new ChildWindowListener(newTD));
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = getLocationOnScreen();
0N/A newTD.setBounds(location.x + 50, location.y + 100, 650, 190);
0N/A newTD.setLayout(new GridBagLayout());
0N/A newTD.setResizable(true);
0N/A
0N/A // description label
0N/A Label label = (edit ?
3050N/A new Label(PolicyTool.rb.getString(".Edit.Principal.")) :
3050N/A new Label(PolicyTool.rb.getString(".Add.New.Principal.")));
0N/A tw.addNewComponent(newTD, label, PRD_DESC_LABEL,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A
0N/A // principal choice
0N/A Choice choice = new Choice();
0N/A choice.add(PRIN_TYPE);
0N/A choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);
0N/A for (int i = 0; i < PRIN_ARRAY.size(); i++) {
0N/A Prin next = PRIN_ARRAY.get(i);
0N/A choice.add(next.CLASS);
0N/A }
0N/A
0N/A choice.addItemListener(new PrincipalTypeMenuListener(newTD));
0N/A if (edit) {
0N/A if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals
0N/A (editMe.getPrincipalClass())) {
0N/A choice.select(PRIN_TYPE);
0N/A } else {
0N/A Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);
0N/A if (inputPrin != null) {
0N/A choice.select(inputPrin.CLASS);
0N/A }
0N/A }
0N/A }
0N/A
0N/A tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // principal textfield
0N/A TextField tf;
0N/A tf = (edit ?
0N/A new TextField(editMe.getDisplayClass(), 30) :
0N/A new TextField(30));
0N/A tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);
0N/A tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,
0N/A 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // name label and textfield
0N/A label = new Label(PRIN_NAME);
0N/A tf = (edit ?
0N/A new TextField(editMe.getDisplayName(), 40) :
0N/A new TextField(40));
0N/A tf.getAccessibleContext().setAccessibleName(PRIN_NAME);
0N/A
0N/A tw.addNewComponent(newTD, label, PRD_NAME_LABEL,
0N/A 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,
0N/A 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // OK button
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener(
0N/A new NewPolicyPrinOKButtonListener
0N/A (tool, tw, this, newTD, edit));
0N/A tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON,
0N/A 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A // cancel button
0N/A Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
0N/A cancelButton.addActionListener(new CancelButtonListener(newTD));
0N/A tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,
0N/A 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A
0N/A newTD.setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * display a dialog box for the user to input Permission info
0N/A *
0N/A * if editPolicyEntry is false, then we are adding Permissions to
0N/A * a new PolicyEntry, and we only update the GUI listing
0N/A * with the new Permission.
0N/A *
0N/A * if edit is true, then we are editing an existing Permission entry.
0N/A */
0N/A void displayPermissionDialog(boolean editPolicyEntry, boolean edit) {
0N/A
0N/A PolicyParser.PermissionEntry editMe = null;
0N/A
0N/A // get the Permission selected from the Permission List
0N/A TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);
0N/A int permIndex = permList.getSelectedIndex();
0N/A
0N/A if (edit) {
0N/A editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex);
0N/A }
0N/A
0N/A ToolDialog newTD = new ToolDialog
0N/A (PolicyTool.rb.getString("Permissions"), tool, tw, true);
0N/A newTD.addWindowListener(new ChildWindowListener(newTD));
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = getLocationOnScreen();
0N/A newTD.setBounds(location.x + 50, location.y + 100, 700, 250);
0N/A newTD.setLayout(new GridBagLayout());
0N/A newTD.setResizable(true);
0N/A
0N/A // description label
0N/A Label label = (edit ?
3050N/A new Label(PolicyTool.rb.getString(".Edit.Permission.")) :
3050N/A new Label(PolicyTool.rb.getString(".Add.New.Permission.")));
0N/A tw.addNewComponent(newTD, label, PD_DESC_LABEL,
0N/A 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A
0N/A // permission choice (added in alphabetical order)
0N/A Choice choice = new Choice();
0N/A choice.add(PERM);
0N/A choice.getAccessibleContext().setAccessibleName(PERM);
0N/A for (int i = 0; i < PERM_ARRAY.size(); i++) {
0N/A Perm next = PERM_ARRAY.get(i);
0N/A choice.add(next.CLASS);
0N/A }
0N/A choice.addItemListener(new PermissionMenuListener(newTD));
0N/A tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // permission textfield
0N/A TextField tf;
0N/A tf = (edit ? new TextField(editMe.permission, 30) : new TextField(30));
0N/A tf.getAccessibleContext().setAccessibleName(PERM);
0N/A if (edit) {
0N/A Perm inputPerm = getPerm(editMe.permission, true);
0N/A if (inputPerm != null) {
0N/A choice.select(inputPerm.CLASS);
0N/A }
0N/A }
0N/A tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,
0N/A 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // name label and textfield
0N/A choice = new Choice();
0N/A choice.add(PERM_NAME);
0N/A choice.getAccessibleContext().setAccessibleName(PERM_NAME);
0N/A choice.addItemListener(new PermissionNameMenuListener(newTD));
0N/A tf = (edit ? new TextField(editMe.name, 40) : new TextField(40));
0N/A tf.getAccessibleContext().setAccessibleName(PERM_NAME);
0N/A if (edit) {
0N/A setPermissionNames(getPerm(editMe.permission, true), choice, tf);
0N/A }
0N/A tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,
0N/A 0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,
0N/A 1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // actions label and textfield
0N/A choice = new Choice();
0N/A choice.add(PERM_ACTIONS);
0N/A choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
0N/A choice.addItemListener(new PermissionActionsMenuListener(newTD));
0N/A tf = (edit ? new TextField(editMe.action, 40) : new TextField(40));
0N/A tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);
0N/A if (edit) {
0N/A setPermissionActions(getPerm(editMe.permission, true), choice, tf);
0N/A }
0N/A tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,
0N/A 0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,
0N/A 1, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // signedby label and textfield
3050N/A label = new Label(PolicyTool.rb.getString("Signed.By."));
0N/A tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,
0N/A 0, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A tf = (edit ? new TextField(editMe.signedBy, 40) : new TextField(40));
0N/A tf.getAccessibleContext().setAccessibleName(
3050N/A PolicyTool.rb.getString("Signed.By."));
0N/A tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,
0N/A 1, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.LR_PADDING);
0N/A
0N/A // OK button
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener(
0N/A new NewPolicyPermOKButtonListener
0N/A (tool, tw, this, newTD, edit));
0N/A tw.addNewComponent(newTD, okButton, PD_OK_BUTTON,
0N/A 0, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A
0N/A // cancel button
0N/A Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
0N/A cancelButton.addActionListener(new CancelButtonListener(newTD));
0N/A tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,
0N/A 1, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,
0N/A tw.TOP_BOTTOM_PADDING);
0N/A
0N/A newTD.setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * construct a Principal object from the Principal Info Dialog Box
0N/A */
0N/A PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {
0N/A
0N/A TextField tf = (TextField)getComponent(PRD_PRIN_TEXTFIELD);
0N/A String pclass = new String(tf.getText().trim());
0N/A tf = (TextField)getComponent(PRD_NAME_TEXTFIELD);
0N/A String pname = new String(tf.getText().trim());
0N/A if (pclass.equals("*")) {
0N/A pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;
0N/A }
0N/A if (pname.equals("*")) {
0N/A pname = PolicyParser.PrincipalEntry.WILDCARD_NAME;
0N/A }
0N/A
0N/A PolicyParser.PrincipalEntry pppe = null;
0N/A
0N/A if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&
0N/A (!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {
0N/A throw new Exception
3050N/A (PolicyTool.rb.getString("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));
0N/A } else if (pname.equals("")) {
0N/A throw new Exception
3050N/A (PolicyTool.rb.getString("Cannot.Specify.Principal.without.a.Name"));
0N/A } else if (pclass.equals("")) {
0N/A // make this consistent with what PolicyParser does
0N/A // when it sees an empty principal class
0N/A pclass = PolicyParser.REPLACE_NAME;
0N/A tool.warnings.addElement(
0N/A "Warning: Principal name '" + pname +
0N/A "' specified without a Principal class.\n" +
0N/A "\t'" + pname + "' will be interpreted " +
0N/A "as a key store alias.\n" +
0N/A "\tThe final principal class will be " +
0N/A ToolDialog.X500_PRIN_CLASS + ".\n" +
0N/A "\tThe final principal name will be " +
0N/A "determined by the following:\n" +
0N/A "\n" +
0N/A "\tIf the key store entry identified by '"
0N/A + pname + "'\n" +
0N/A "\tis a key entry, then the principal name will be\n" +
0N/A "\tthe subject distinguished name from the first\n" +
0N/A "\tcertificate in the entry's certificate chain.\n" +
0N/A "\n" +
0N/A "\tIf the key store entry identified by '" +
0N/A pname + "'\n" +
0N/A "\tis a trusted certificate entry, then the\n" +
0N/A "\tprincipal name will be the subject distinguished\n" +
0N/A "\tname from the trusted public key certificate.");
0N/A tw.displayStatusDialog(this,
0N/A "'" + pname + "' will be interpreted as a key " +
0N/A "store alias. View Warning Log for details.");
0N/A }
0N/A return new PolicyParser.PrincipalEntry(pclass, pname);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * construct a Permission object from the Permission Info Dialog Box
0N/A */
0N/A PolicyParser.PermissionEntry getPermFromDialog() {
0N/A
0N/A TextField tf = (TextField)getComponent(PD_PERM_TEXTFIELD);
0N/A String permission = new String(tf.getText().trim());
0N/A tf = (TextField)getComponent(PD_NAME_TEXTFIELD);
0N/A String name = null;
0N/A if (tf.getText().trim().equals("") == false)
0N/A name = new String(tf.getText().trim());
0N/A if (permission.equals("") ||
0N/A (!permission.equals(ALL_PERM_CLASS) && name == null)) {
0N/A throw new InvalidParameterException(PolicyTool.rb.getString
3050N/A ("Permission.and.Target.Name.must.have.a.value"));
0N/A }
0N/A
0N/A // When the permission is FilePermission, we need to check the name
0N/A // to make sure it's not escaped. We believe --
0N/A //
0N/A // String name.lastIndexOf("\\\\")
0N/A // ---------------- ------------------------
0N/A // c:\foo\bar -1, legal
0N/A // c:\\foo\\bar 2, illegal
0N/A // \\server\share 0, legal
0N/A // \\\\server\share 2, illegal
0N/A
0N/A if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {
0N/A char result = tw.displayYesNoDialog(this,
0N/A PolicyTool.rb.getString("Warning"),
0N/A PolicyTool.rb.getString(
3050N/A "Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),
0N/A PolicyTool.rb.getString("Retain"),
0N/A PolicyTool.rb.getString("Edit")
0N/A );
0N/A if (result != 'Y') {
0N/A // an invisible exception
0N/A throw new NoDisplayException();
0N/A }
0N/A }
0N/A // get the Actions
0N/A tf = (TextField)getComponent(PD_ACTIONS_TEXTFIELD);
0N/A String actions = null;
0N/A if (tf.getText().trim().equals("") == false)
0N/A actions = new String(tf.getText().trim());
0N/A
0N/A // get the Signed By
0N/A tf = (TextField)getComponent(PD_SIGNEDBY_TEXTFIELD);
0N/A String signedBy = null;
0N/A if (tf.getText().trim().equals("") == false)
0N/A signedBy = new String(tf.getText().trim());
0N/A
0N/A PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry
0N/A (permission, name, actions);
0N/A pppe.signedBy = signedBy;
0N/A
0N/A // see if the signers have public keys
0N/A if (signedBy != null) {
0N/A String signers[] = tool.parseSigners(pppe.signedBy);
0N/A for (int i = 0; i < signers.length; i++) {
0N/A try {
0N/A PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
0N/A if (pubKey == null) {
0N/A MessageFormat form = new MessageFormat
0N/A (PolicyTool.rb.getString
3050N/A ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
0N/A Object[] source = {signers[i]};
0N/A tool.warnings.addElement(form.format(source));
0N/A tw.displayStatusDialog(this, form.format(source));
0N/A }
0N/A } catch (Exception e) {
0N/A tw.displayErrorDialog(this, e);
0N/A }
0N/A }
0N/A }
0N/A return pppe;
0N/A }
0N/A
0N/A /**
0N/A * confirm that the user REALLY wants to remove the Policy Entry
0N/A */
0N/A void displayConfirmRemovePolicyEntry() {
0N/A
0N/A // find the entry to be removed
0N/A List list = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A int index = list.getSelectedIndex();
0N/A PolicyEntry entries[] = tool.getEntry();
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = tw.getLocationOnScreen();
0N/A setBounds(location.x + 25, location.y + 100, 600, 400);
0N/A setLayout(new GridBagLayout());
0N/A
0N/A // ask the user do they really want to do this?
0N/A Label label = new Label
3050N/A (PolicyTool.rb.getString("Remove.this.Policy.Entry."));
0N/A tw.addNewComponent(this, label, CRPE_LABEL1,
0N/A 0, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.BOTTOM_PADDING);
0N/A
0N/A // display the policy entry
0N/A label = new Label(entries[index].codebaseToString());
0N/A tw.addNewComponent(this, label, CRPE_LABEL2,
0N/A 0, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A label = new Label(entries[index].principalsToString().trim());
0N/A tw.addNewComponent(this, label, CRPE_LABEL2+1,
0N/A 0, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A Vector<PolicyParser.PermissionEntry> perms =
0N/A entries[index].getGrantEntry().permissionEntries;
0N/A for (int i = 0; i < perms.size(); i++) {
0N/A PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);
0N/A String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);
0N/A label = new Label(" " + permString);
0N/A if (i == (perms.size()-1)) {
0N/A tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
0N/A 1, 3 + i, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.BOTH, tw.BOTTOM_PADDING);
0N/A } else {
0N/A tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,
0N/A 1, 3 + i, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.BOTH);
0N/A }
0N/A }
0N/A
0N/A
0N/A // add OK/CANCEL buttons in a new panel
0N/A Panel panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
0N/A // OK button
0N/A Button okButton = new Button(PolicyTool.rb.getString("OK"));
0N/A okButton.addActionListener
0N/A (new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));
0N/A tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,
0N/A 0, 0, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL, tw.LR_PADDING);
0N/A
0N/A // cancel button
0N/A Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
0N/A cancelButton.addActionListener(new CancelButtonListener(this));
0N/A tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,
0N/A 1, 0, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL, tw.LR_PADDING);
0N/A
0N/A tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(),
0N/A 0, 3 + perms.size(), 2, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL, tw.TOP_BOTTOM_PADDING);
0N/A
0N/A pack();
0N/A setVisible(true);
0N/A }
0N/A
0N/A /**
0N/A * perform SAVE AS
0N/A */
0N/A void displaySaveAsDialog(int nextEvent) {
0N/A
0N/A // pop up a dialog box for the user to enter a filename.
0N/A FileDialog fd = new FileDialog
3050N/A (tw, PolicyTool.rb.getString("Save.As"), FileDialog.SAVE);
0N/A fd.addWindowListener(new WindowAdapter() {
0N/A public void windowClosing(WindowEvent e) {
0N/A e.getWindow().setVisible(false);
0N/A }
0N/A });
0N/A fd.setVisible(true);
0N/A
0N/A // see if the user hit cancel
0N/A if (fd.getFile() == null ||
0N/A fd.getFile().equals(""))
0N/A return;
0N/A
0N/A // get the entered filename
3217N/A File saveAsFile = new File(fd.getDirectory(), fd.getFile());
3217N/A String filename = saveAsFile.getPath();
0N/A fd.dispose();
0N/A
3217N/A try {
3217N/A // save the policy entries to a file
3217N/A tool.savePolicy(filename);
3217N/A
3217N/A // display status
3217N/A MessageFormat form = new MessageFormat(PolicyTool.rb.getString
3217N/A ("Policy.successfully.written.to.filename"));
3217N/A Object[] source = {filename};
3217N/A tw.displayStatusDialog(null, form.format(source));
3217N/A
3217N/A // display the new policy filename
3217N/A TextField newFilename = (TextField)tw.getComponent
3217N/A (tw.MW_FILENAME_TEXTFIELD);
3217N/A newFilename.setText(filename);
3217N/A tw.setVisible(true);
3217N/A
3217N/A // now continue with the originally requested command
3217N/A // (QUIT, NEW, or OPEN)
3217N/A userSaveContinue(tool, tw, this, nextEvent);
3217N/A
3217N/A } catch (FileNotFoundException fnfe) {
3217N/A if (filename == null || filename.equals("")) {
3217N/A tw.displayErrorDialog(null, new FileNotFoundException
3217N/A (PolicyTool.rb.getString("null.filename")));
3217N/A } else {
3217N/A tw.displayErrorDialog(null, fnfe);
0N/A }
3217N/A } catch (Exception ee) {
3217N/A tw.displayErrorDialog(null, ee);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * ask user if they want to save changes
0N/A */
0N/A void displayUserSave(int select) {
0N/A
0N/A if (tool.modified == true) {
0N/A
0N/A // find where the PolicyTool gui is
0N/A Point location = tw.getLocationOnScreen();
0N/A setBounds(location.x + 75, location.y + 100, 400, 150);
0N/A setLayout(new GridBagLayout());
0N/A
0N/A Label label = new Label
3050N/A (PolicyTool.rb.getString("Save.changes."));
0N/A tw.addNewComponent(this, label, USC_LABEL,
0N/A 0, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,
0N/A tw.L_TOP_BOTTOM_PADDING);
0N/A
0N/A Panel panel = new Panel();
0N/A panel.setLayout(new GridBagLayout());
0N/A
0N/A Button yesButton = new Button(PolicyTool.rb.getString("Yes"));
0N/A yesButton.addActionListener
0N/A (new UserSaveYesButtonListener(this, tool, tw, select));
0N/A tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,
0N/A 0, 0, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL,
0N/A tw.LR_BOTTOM_PADDING);
0N/A Button noButton = new Button(PolicyTool.rb.getString("No"));
0N/A noButton.addActionListener
0N/A (new UserSaveNoButtonListener(this, tool, tw, select));
0N/A tw.addNewComponent(panel, noButton, USC_NO_BUTTON,
0N/A 1, 0, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL,
0N/A tw.LR_BOTTOM_PADDING);
0N/A Button cancelButton = new Button(PolicyTool.rb.getString("Cancel"));
0N/A cancelButton.addActionListener
0N/A (new UserSaveCancelButtonListener(this));
0N/A tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,
0N/A 2, 0, 1, 1, 0.0, 0.0,
0N/A GridBagConstraints.VERTICAL,
0N/A tw.LR_BOTTOM_PADDING);
0N/A
0N/A tw.addNewComponent(this, panel, USC_PANEL,
0N/A 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);
0N/A
0N/A pack();
0N/A setVisible(true);
0N/A } else {
0N/A // just do the original request (QUIT, NEW, or OPEN)
0N/A userSaveContinue(tool, tw, this, select);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * when the user sees the 'YES', 'NO', 'CANCEL' buttons on the
0N/A * displayUserSave dialog, and the click on one of them,
0N/A * we need to continue the originally requested action
0N/A * (either QUITting, opening NEW policy file, or OPENing an existing
0N/A * policy file. do that now.
0N/A */
0N/A void userSaveContinue(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog us, int select) {
0N/A
0N/A // now either QUIT, open a NEW policy file, or OPEN an existing policy
0N/A switch(select) {
0N/A case ToolDialog.QUIT:
0N/A
0N/A tw.setVisible(false);
0N/A tw.dispose();
0N/A System.exit(0);
0N/A
0N/A case ToolDialog.NEW:
0N/A
0N/A try {
0N/A tool.openPolicy(null);
0N/A } catch (Exception ee) {
0N/A tool.modified = false;
0N/A tw.displayErrorDialog(null, ee);
0N/A }
0N/A
0N/A // display the policy entries via the policy list textarea
0N/A List list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, tw));
0N/A tw.replacePolicyList(list);
0N/A
0N/A // display null policy filename and keystore
0N/A TextField newFilename = (TextField)
0N/A tw.getComponent(tw.MW_FILENAME_TEXTFIELD);
0N/A newFilename.setText("");
0N/A tw.setVisible(true);
0N/A break;
0N/A
0N/A case ToolDialog.OPEN:
0N/A
0N/A // pop up a dialog box for the user to enter a filename.
0N/A FileDialog fd = new FileDialog
0N/A (tw, PolicyTool.rb.getString("Open"), FileDialog.LOAD);
0N/A fd.addWindowListener(new WindowAdapter() {
0N/A public void windowClosing(WindowEvent e) {
0N/A e.getWindow().setVisible(false);
0N/A }
0N/A });
0N/A fd.setVisible(true);
0N/A
0N/A // see if the user hit 'cancel'
0N/A if (fd.getFile() == null ||
0N/A fd.getFile().equals(""))
0N/A return;
0N/A
0N/A // get the entered filename
3217N/A String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath();
0N/A
0N/A try {
0N/A // open the policy file
0N/A tool.openPolicy(policyFile);
0N/A
0N/A // display the policy entries via the policy list textarea
0N/A list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, tw));
0N/A PolicyEntry entries[] = tool.getEntry();
0N/A if (entries != null) {
0N/A for (int i = 0; i < entries.length; i++)
0N/A list.add(entries[i].headerToString());
0N/A }
0N/A tw.replacePolicyList(list);
0N/A tool.modified = false;
0N/A
0N/A // display the new policy filename
0N/A newFilename = (TextField)
0N/A tw.getComponent(tw.MW_FILENAME_TEXTFIELD);
0N/A newFilename.setText(policyFile);
0N/A tw.setVisible(true);
0N/A
0N/A // inform user of warnings
0N/A if (tool.newWarning == true) {
0N/A tw.displayStatusDialog(null, PolicyTool.rb.getString
3050N/A ("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));
0N/A }
0N/A
0N/A } catch (Exception e) {
0N/A // add blank policy listing
0N/A list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, tw));
0N/A tw.replacePolicyList(list);
0N/A tool.setPolicyFileName(null);
0N/A tool.modified = false;
0N/A
0N/A // display a null policy filename
0N/A newFilename = (TextField)
0N/A tw.getComponent(tw.MW_FILENAME_TEXTFIELD);
0N/A newFilename.setText("");
0N/A tw.setVisible(true);
0N/A
0N/A // display the error
0N/A MessageFormat form = new MessageFormat(PolicyTool.rb.getString
3050N/A ("Could.not.open.policy.file.policyFile.e.toString."));
0N/A Object[] source = {policyFile, e.toString()};
0N/A tw.displayErrorDialog(null, form.format(source));
0N/A }
0N/A break;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return a Menu list of names for a given permission
0N/A *
0N/A * If inputPerm's TARGETS are null, then this means TARGETS are
0N/A * not allowed to be entered (and the TextField is set to be
0N/A * non-editable).
0N/A *
0N/A * If TARGETS are valid but there are no standard ones
0N/A * (user must enter them by hand) then the TARGETS array may be empty
0N/A * (and of course non-null).
0N/A */
0N/A void setPermissionNames(Perm inputPerm, Choice names, TextField field) {
0N/A names.removeAll();
0N/A names.add(PERM_NAME);
0N/A
0N/A if (inputPerm == null) {
0N/A // custom permission
0N/A field.setEditable(true);
0N/A } else if (inputPerm.TARGETS == null) {
0N/A // standard permission with no targets
0N/A field.setEditable(false);
0N/A } else {
0N/A // standard permission with standard targets
0N/A field.setEditable(true);
0N/A for (int i = 0; i < inputPerm.TARGETS.length; i++) {
0N/A names.add(inputPerm.TARGETS[i]);
0N/A }
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return a Menu list of actions for a given permission
0N/A *
0N/A * If inputPerm's ACTIONS are null, then this means ACTIONS are
0N/A * not allowed to be entered (and the TextField is set to be
0N/A * non-editable). This is typically true for BasicPermissions.
0N/A *
0N/A * If ACTIONS are valid but there are no standard ones
0N/A * (user must enter them by hand) then the ACTIONS array may be empty
0N/A * (and of course non-null).
0N/A */
0N/A void setPermissionActions(Perm inputPerm, Choice actions, TextField field) {
0N/A actions.removeAll();
0N/A actions.add(PERM_ACTIONS);
0N/A
0N/A if (inputPerm == null) {
0N/A // custom permission
0N/A field.setEditable(true);
0N/A } else if (inputPerm.ACTIONS == null) {
0N/A // standard permission with no actions
0N/A field.setEditable(false);
0N/A } else {
0N/A // standard permission with standard actions
0N/A field.setEditable(true);
0N/A for (int i = 0; i < inputPerm.ACTIONS.length; i++) {
0N/A actions.add(inputPerm.ACTIONS[i]);
0N/A }
0N/A }
0N/A }
0N/A
0N/A static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) {
0N/A String result = pppe.permission;
0N/A if (pppe.name != null) {
0N/A result += " " + pppe.name;
0N/A }
0N/A if (pppe.action != null) {
0N/A result += ", \"" + pppe.action + "\"";
0N/A }
0N/A if (pppe.signedBy != null) {
0N/A result += ", signedBy " + pppe.signedBy;
0N/A }
0N/A return result;
0N/A }
0N/A
0N/A static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) {
0N/A StringWriter sw = new StringWriter();
0N/A PrintWriter pw = new PrintWriter(sw);
0N/A pppe.write(pw);
0N/A return sw.toString();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for the PolicyTool window
0N/A */
0N/Aclass ToolWindowListener implements WindowListener {
0N/A
0N/A private ToolWindow tw;
0N/A
0N/A ToolWindowListener(ToolWindow tw) {
0N/A this.tw = tw;
0N/A }
0N/A
0N/A public void windowOpened(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowClosing(WindowEvent we) {
0N/A
0N/A // XXX
0N/A // should we ask user if they want to save changes?
0N/A // (we do if they choose the Menu->Exit)
0N/A // seems that if they kill the application by hand,
0N/A // we don't have to ask.
0N/A
0N/A tw.setVisible(false);
0N/A tw.dispose();
0N/A System.exit(0);
0N/A }
0N/A
0N/A public void windowClosed(WindowEvent we) {
0N/A System.exit(0);
0N/A }
0N/A
0N/A public void windowIconified(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowDeiconified(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowActivated(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowDeactivated(WindowEvent we) {
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for the Policy List
0N/A */
0N/Aclass PolicyListListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A
0N/A PolicyListListener(PolicyTool tool, ToolWindow tw) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // display the permission list for a policy entry
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
0N/A td.displayPolicyEntryDialog(true);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for the File Menu
0N/A */
0N/Aclass FileMenuListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A
0N/A FileMenuListener(PolicyTool tool, ToolWindow tw) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A if (PolicyTool.collator.compare(e.getActionCommand(), tw.QUIT) == 0) {
0N/A
0N/A // ask user if they want to save changes
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
0N/A td.displayUserSave(td.QUIT);
0N/A
0N/A // the above method will perform the QUIT as long as the
0N/A // user does not CANCEL the request
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.NEW_POLICY_FILE) == 0) {
0N/A
0N/A // ask user if they want to save changes
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
0N/A td.displayUserSave(td.NEW);
0N/A
0N/A // the above method will perform the NEW as long as the
0N/A // user does not CANCEL the request
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.OPEN_POLICY_FILE) == 0) {
0N/A
0N/A // ask user if they want to save changes
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Save.Changes"), tool, tw, true);
0N/A td.displayUserSave(td.OPEN);
0N/A
0N/A // the above method will perform the OPEN as long as the
0N/A // user does not CANCEL the request
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.SAVE_POLICY_FILE) == 0) {
0N/A
0N/A // get the previously entered filename
0N/A String filename = ((TextField)
0N/A tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText();
0N/A
0N/A // if there is no filename, do a SAVE_AS
0N/A if (filename == null || filename.length() == 0) {
0N/A // user wants to SAVE AS
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Save.As"), tool, tw, true);
0N/A td.displaySaveAsDialog(td.NOACTION);
0N/A } else {
0N/A try {
0N/A // save the policy entries to a file
0N/A tool.savePolicy(filename);
0N/A
0N/A // display status
0N/A MessageFormat form = new MessageFormat
0N/A (PolicyTool.rb.getString
3050N/A ("Policy.successfully.written.to.filename"));
0N/A Object[] source = {filename};
0N/A tw.displayStatusDialog(null, form.format(source));
0N/A } catch (FileNotFoundException fnfe) {
0N/A if (filename == null || filename.equals("")) {
0N/A tw.displayErrorDialog(null, new FileNotFoundException
3050N/A (PolicyTool.rb.getString("null.filename")));
0N/A } else {
0N/A tw.displayErrorDialog(null, fnfe);
0N/A }
0N/A } catch (Exception ee) {
0N/A tw.displayErrorDialog(null, ee);
0N/A }
0N/A }
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.SAVE_AS_POLICY_FILE) == 0) {
0N/A
0N/A // user wants to SAVE AS
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Save.As"), tool, tw, true);
0N/A td.displaySaveAsDialog(td.NOACTION);
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.VIEW_WARNINGS) == 0) {
0N/A tw.displayWarningLog(null);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for the main window buttons and Edit Menu
0N/A */
0N/Aclass MainWindowListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A
0N/A MainWindowListener(PolicyTool tool, ToolWindow tw) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.ADD_POLICY_ENTRY) == 0) {
0N/A
0N/A // display a dialog box for the user to enter policy info
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
0N/A td.displayPolicyEntryDialog(false);
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.REMOVE_POLICY_ENTRY) == 0) {
0N/A
0N/A // get the selected entry
0N/A List list = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A int index = list.getSelectedIndex();
0N/A if (index < 0) {
0N/A tw.displayErrorDialog(null, new Exception
3050N/A (PolicyTool.rb.getString("No.Policy.Entry.selected")));
0N/A return;
0N/A }
0N/A
0N/A // ask the user if they really want to remove the policy entry
0N/A ToolDialog td = new ToolDialog(PolicyTool.rb.getString
3050N/A ("Remove.Policy.Entry"), tool, tw, true);
0N/A td.displayConfirmRemovePolicyEntry();
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.EDIT_POLICY_ENTRY) == 0) {
0N/A
0N/A // get the selected entry
0N/A List list = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A int index = list.getSelectedIndex();
0N/A if (index < 0) {
0N/A tw.displayErrorDialog(null, new Exception
3050N/A (PolicyTool.rb.getString("No.Policy.Entry.selected")));
0N/A return;
0N/A }
0N/A
0N/A // display the permission list for a policy entry
0N/A ToolDialog td = new ToolDialog
3050N/A (PolicyTool.rb.getString("Policy.Entry"), tool, tw, true);
0N/A td.displayPolicyEntryDialog(true);
0N/A
0N/A } else if (PolicyTool.collator.compare(e.getActionCommand(),
0N/A tw.EDIT_KEYSTORE) == 0) {
0N/A
0N/A // display a dialog box for the user to enter keystore info
0N/A ToolDialog td = new ToolDialog
0N/A (PolicyTool.rb.getString("KeyStore"), tool, tw, true);
0N/A td.keyStoreDialog(td.EDIT_KEYSTORE);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for AddEntryDoneButton button
0N/A *
0N/A * -- if edit is TRUE, then we are EDITing an existing PolicyEntry
0N/A * and we need to update both the policy and the GUI listing.
0N/A * if edit is FALSE, then we are ADDing a new PolicyEntry,
0N/A * so we only need to update the GUI listing.
0N/A */
0N/Aclass AddEntryDoneButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean edit;
0N/A
0N/A AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean edit) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.edit = edit;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A try {
0N/A // get a PolicyEntry object from the dialog policy info
0N/A PolicyEntry newEntry = td.getPolicyEntryFromDialog();
0N/A PolicyParser.GrantEntry newGe = newEntry.getGrantEntry();
0N/A
0N/A // see if all the signers have public keys
0N/A if (newGe.signedBy != null) {
0N/A String signers[] = tool.parseSigners(newGe.signedBy);
0N/A for (int i = 0; i < signers.length; i++) {
0N/A PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);
0N/A if (pubKey == null) {
0N/A MessageFormat form = new MessageFormat
0N/A (PolicyTool.rb.getString
3050N/A ("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));
0N/A Object[] source = {signers[i]};
0N/A tool.warnings.addElement(form.format(source));
0N/A tw.displayStatusDialog(td, form.format(source));
0N/A }
0N/A }
0N/A }
0N/A
0N/A // add the entry
0N/A List policyList = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A if (edit) {
0N/A int listIndex = policyList.getSelectedIndex();
0N/A tool.addEntry(newEntry, listIndex);
0N/A String newCodeBaseStr = newEntry.headerToString();
0N/A if (PolicyTool.collator.compare
0N/A (newCodeBaseStr, policyList.getItem(listIndex)) != 0)
0N/A tool.modified = true;
0N/A policyList.replaceItem(newCodeBaseStr, listIndex);
0N/A } else {
0N/A tool.addEntry(newEntry, -1);
0N/A policyList.add(newEntry.headerToString());
0N/A tool.modified = true;
0N/A }
0N/A td.setVisible(false);
0N/A td.dispose();
0N/A
0N/A } catch (Exception eee) {
0N/A tw.displayErrorDialog(td, eee);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for ChangeKeyStoreOKButton button
0N/A */
0N/Aclass ChangeKeyStoreOKButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A
0N/A ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A String URLString = ((TextField)
0N/A td.getComponent(td.KSD_NAME_TEXTFIELD)).getText().trim();
0N/A String type = ((TextField)
0N/A td.getComponent(td.KSD_TYPE_TEXTFIELD)).getText().trim();
0N/A String provider = ((TextField)
0N/A td.getComponent(td.KSD_PROVIDER_TEXTFIELD)).getText().trim();
0N/A String pwdURL = ((TextField)
0N/A td.getComponent(td.KSD_PWD_URL_TEXTFIELD)).getText().trim();
0N/A
0N/A try {
0N/A tool.openKeyStore
0N/A ((URLString.length() == 0 ? null : URLString),
0N/A (type.length() == 0 ? null : type),
0N/A (provider.length() == 0 ? null : provider),
0N/A (pwdURL.length() == 0 ? null : pwdURL));
0N/A tool.modified = true;
0N/A } catch (Exception ex) {
0N/A MessageFormat form = new MessageFormat(PolicyTool.rb.getString
3050N/A ("Unable.to.open.KeyStore.ex.toString."));
0N/A Object[] source = {ex.toString()};
0N/A tw.displayErrorDialog(td, form.format(source));
0N/A return;
0N/A }
0N/A
0N/A td.dispose();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for AddPrinButton button
0N/A */
0N/Aclass AddPrinButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean editPolicyEntry;
0N/A
0N/A AddPrinButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean editPolicyEntry) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.editPolicyEntry = editPolicyEntry;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // display a dialog box for the user to enter principal info
0N/A td.displayPrincipalDialog(editPolicyEntry, false);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for AddPermButton button
0N/A */
0N/Aclass AddPermButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean editPolicyEntry;
0N/A
0N/A AddPermButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean editPolicyEntry) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.editPolicyEntry = editPolicyEntry;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // display a dialog box for the user to enter permission info
0N/A td.displayPermissionDialog(editPolicyEntry, false);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for AddPrinOKButton button
0N/A */
0N/Aclass NewPolicyPrinOKButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog listDialog;
0N/A private ToolDialog infoDialog;
0N/A private boolean edit;
0N/A
0N/A NewPolicyPrinOKButtonListener(PolicyTool tool,
0N/A ToolWindow tw,
0N/A ToolDialog listDialog,
0N/A ToolDialog infoDialog,
0N/A boolean edit) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.listDialog = listDialog;
0N/A this.infoDialog = infoDialog;
0N/A this.edit = edit;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A try {
0N/A // read in the new principal info from Dialog Box
0N/A PolicyParser.PrincipalEntry pppe =
0N/A infoDialog.getPrinFromDialog();
0N/A if (pppe != null) {
0N/A try {
0N/A tool.verifyPrincipal(pppe.getPrincipalClass(),
0N/A pppe.getPrincipalName());
0N/A } catch (ClassNotFoundException cnfe) {
0N/A MessageFormat form = new MessageFormat
0N/A (PolicyTool.rb.getString
3050N/A ("Warning.Class.not.found.class"));
0N/A Object[] source = {pppe.getPrincipalClass()};
0N/A tool.warnings.addElement(form.format(source));
0N/A tw.displayStatusDialog(infoDialog, form.format(source));
0N/A }
0N/A
0N/A // add the principal to the GUI principal list
0N/A TaggedList prinList =
0N/A (TaggedList)listDialog.getComponent(listDialog.PE_PRIN_LIST);
0N/A
0N/A String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe);
0N/A if (edit) {
0N/A // if editing, replace the original principal
0N/A int index = prinList.getSelectedIndex();
0N/A prinList.replaceTaggedItem(prinString, pppe, index);
0N/A } else {
0N/A // if adding, just add it to the end
0N/A prinList.addTaggedItem(prinString, pppe);
0N/A }
0N/A }
0N/A infoDialog.dispose();
0N/A } catch (Exception ee) {
0N/A tw.displayErrorDialog(infoDialog, ee);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for AddPermOKButton button
0N/A */
0N/Aclass NewPolicyPermOKButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog listDialog;
0N/A private ToolDialog infoDialog;
0N/A private boolean edit;
0N/A
0N/A NewPolicyPermOKButtonListener(PolicyTool tool,
0N/A ToolWindow tw,
0N/A ToolDialog listDialog,
0N/A ToolDialog infoDialog,
0N/A boolean edit) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.listDialog = listDialog;
0N/A this.infoDialog = infoDialog;
0N/A this.edit = edit;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A try {
0N/A // read in the new permission info from Dialog Box
0N/A PolicyParser.PermissionEntry pppe =
0N/A infoDialog.getPermFromDialog();
0N/A
0N/A try {
0N/A tool.verifyPermission(pppe.permission, pppe.name, pppe.action);
0N/A } catch (ClassNotFoundException cnfe) {
0N/A MessageFormat form = new MessageFormat(PolicyTool.rb.getString
3050N/A ("Warning.Class.not.found.class"));
0N/A Object[] source = {pppe.permission};
0N/A tool.warnings.addElement(form.format(source));
0N/A tw.displayStatusDialog(infoDialog, form.format(source));
0N/A }
0N/A
0N/A // add the permission to the GUI permission list
0N/A TaggedList permList =
0N/A (TaggedList)listDialog.getComponent(listDialog.PE_PERM_LIST);
0N/A
0N/A String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe);
0N/A if (edit) {
0N/A // if editing, replace the original permission
0N/A int which = permList.getSelectedIndex();
0N/A permList.replaceTaggedItem(permString, pppe, which);
0N/A } else {
0N/A // if adding, just add it to the end
0N/A permList.addTaggedItem(permString, pppe);
0N/A }
0N/A infoDialog.dispose();
0N/A
0N/A } catch (InvocationTargetException ite) {
0N/A tw.displayErrorDialog(infoDialog, ite.getTargetException());
0N/A } catch (Exception ee) {
0N/A tw.displayErrorDialog(infoDialog, ee);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for RemovePrinButton button
0N/A */
0N/Aclass RemovePrinButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean edit;
0N/A
0N/A RemovePrinButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean edit) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.edit = edit;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // get the Principal selected from the Principal List
0N/A TaggedList prinList = (TaggedList)td.getComponent(td.PE_PRIN_LIST);
0N/A int prinIndex = prinList.getSelectedIndex();
0N/A
0N/A if (prinIndex < 0) {
0N/A tw.displayErrorDialog(td, new Exception
3050N/A (PolicyTool.rb.getString("No.principal.selected")));
0N/A return;
0N/A }
0N/A // remove the principal from the display
0N/A prinList.removeTaggedItem(prinIndex);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for RemovePermButton button
0N/A */
0N/Aclass RemovePermButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean edit;
0N/A
0N/A RemovePermButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean edit) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.edit = edit;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // get the Permission selected from the Permission List
0N/A TaggedList permList = (TaggedList)td.getComponent(td.PE_PERM_LIST);
0N/A int permIndex = permList.getSelectedIndex();
0N/A
0N/A if (permIndex < 0) {
0N/A tw.displayErrorDialog(td, new Exception
3050N/A (PolicyTool.rb.getString("No.permission.selected")));
0N/A return;
0N/A }
0N/A // remove the permission from the display
0N/A permList.removeTaggedItem(permIndex);
0N/A
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Edit Principal button
0N/A *
0N/A * We need the editPolicyEntry boolean to tell us if the user is
0N/A * adding a new PolicyEntry at this time, or editing an existing entry.
0N/A * If the user is adding a new PolicyEntry, we ONLY update the
0N/A * GUI listing. If the user is editing an existing PolicyEntry, we
0N/A * update both the GUI listing and the actual PolicyEntry.
0N/A */
0N/Aclass EditPrinButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean editPolicyEntry;
0N/A
0N/A EditPrinButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean editPolicyEntry) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.editPolicyEntry = editPolicyEntry;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // get the Principal selected from the Principal List
0N/A TaggedList list = (TaggedList)td.getComponent(td.PE_PRIN_LIST);
0N/A int prinIndex = list.getSelectedIndex();
0N/A
0N/A if (prinIndex < 0) {
0N/A tw.displayErrorDialog(td, new Exception
3050N/A (PolicyTool.rb.getString("No.principal.selected")));
0N/A return;
0N/A }
0N/A td.displayPrincipalDialog(editPolicyEntry, true);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Edit Permission button
0N/A *
0N/A * We need the editPolicyEntry boolean to tell us if the user is
0N/A * adding a new PolicyEntry at this time, or editing an existing entry.
0N/A * If the user is adding a new PolicyEntry, we ONLY update the
0N/A * GUI listing. If the user is editing an existing PolicyEntry, we
0N/A * update both the GUI listing and the actual PolicyEntry.
0N/A */
0N/Aclass EditPermButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog td;
0N/A private boolean editPolicyEntry;
0N/A
0N/A EditPermButtonListener(PolicyTool tool, ToolWindow tw,
0N/A ToolDialog td, boolean editPolicyEntry) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.td = td;
0N/A this.editPolicyEntry = editPolicyEntry;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // get the Permission selected from the Permission List
0N/A List list = (List)td.getComponent(td.PE_PERM_LIST);
0N/A int permIndex = list.getSelectedIndex();
0N/A
0N/A if (permIndex < 0) {
0N/A tw.displayErrorDialog(td, new Exception
3050N/A (PolicyTool.rb.getString("No.permission.selected")));
0N/A return;
0N/A }
0N/A td.displayPermissionDialog(editPolicyEntry, true);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Principal Popup Menu
0N/A */
0N/Aclass PrincipalTypeMenuListener implements ItemListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A PrincipalTypeMenuListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void itemStateChanged(ItemEvent e) {
0N/A
0N/A Choice prin = (Choice)td.getComponent(td.PRD_PRIN_CHOICE);
0N/A TextField prinField =
0N/A (TextField)td.getComponent(td.PRD_PRIN_TEXTFIELD);
0N/A TextField nameField =
0N/A (TextField)td.getComponent(td.PRD_NAME_TEXTFIELD);
0N/A
0N/A prin.getAccessibleContext().setAccessibleName(
0N/A PolicyTool.splitToWords((String)e.getItem()));
0N/A if (((String)e.getItem()).equals(td.PRIN_TYPE)) {
0N/A // ignore if they choose "Principal Type:" item
0N/A if (prinField.getText() != null &&
0N/A prinField.getText().length() > 0) {
0N/A Prin inputPrin = td.getPrin(prinField.getText(), true);
0N/A prin.select(inputPrin.CLASS);
0N/A }
0N/A return;
0N/A }
0N/A
0N/A // if you change the principal, clear the name
0N/A if (prinField.getText().indexOf((String)e.getItem()) == -1) {
0N/A nameField.setText("");
0N/A }
0N/A
0N/A // set the text in the textfield and also modify the
0N/A // pull-down choice menus to reflect the correct possible
0N/A // set of names and actions
0N/A Prin inputPrin = td.getPrin((String)e.getItem(), false);
0N/A if (inputPrin != null) {
0N/A prinField.setText(inputPrin.FULL_CLASS);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Permission Popup Menu
0N/A */
0N/Aclass PermissionMenuListener implements ItemListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A PermissionMenuListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void itemStateChanged(ItemEvent e) {
0N/A
0N/A Choice perms = (Choice)td.getComponent(td.PD_PERM_CHOICE);
0N/A Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE);
0N/A Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE);
0N/A TextField nameField =
0N/A (TextField)td.getComponent(td.PD_NAME_TEXTFIELD);
0N/A TextField actionsField =
0N/A (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD);
0N/A TextField permField = (TextField)td.getComponent(td.PD_PERM_TEXTFIELD);
0N/A TextField signedbyField =
0N/A (TextField)td.getComponent(td.PD_SIGNEDBY_TEXTFIELD);
0N/A
0N/A perms.getAccessibleContext().setAccessibleName(
0N/A PolicyTool.splitToWords((String)e.getItem()));
0N/A
0N/A // ignore if they choose the 'Permission:' item
0N/A if (PolicyTool.collator.compare((String)e.getItem(), td.PERM) == 0) {
0N/A if (permField.getText() != null &&
0N/A permField.getText().length() > 0) {
0N/A
0N/A Perm inputPerm = td.getPerm(permField.getText(), true);
0N/A if (inputPerm != null) {
0N/A perms.select(inputPerm.CLASS);
0N/A }
0N/A }
0N/A return;
0N/A }
0N/A
0N/A // if you change the permission, clear the name, actions, and signedBy
0N/A if (permField.getText().indexOf((String)e.getItem()) == -1) {
0N/A nameField.setText("");
0N/A actionsField.setText("");
0N/A signedbyField.setText("");
0N/A }
0N/A
0N/A // set the text in the textfield and also modify the
0N/A // pull-down choice menus to reflect the correct possible
0N/A // set of names and actions
0N/A
0N/A Perm inputPerm = td.getPerm((String)e.getItem(), false);
0N/A if (inputPerm == null) {
0N/A permField.setText("");
0N/A } else {
0N/A permField.setText(inputPerm.FULL_CLASS);
0N/A }
0N/A td.setPermissionNames(inputPerm, names, nameField);
0N/A td.setPermissionActions(inputPerm, actions, actionsField);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Permission Name Popup Menu
0N/A */
0N/Aclass PermissionNameMenuListener implements ItemListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A PermissionNameMenuListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void itemStateChanged(ItemEvent e) {
0N/A
0N/A Choice names = (Choice)td.getComponent(td.PD_NAME_CHOICE);
0N/A names.getAccessibleContext().setAccessibleName(
0N/A PolicyTool.splitToWords((String)e.getItem()));
0N/A
0N/A if (((String)e.getItem()).indexOf(td.PERM_NAME) != -1)
0N/A return;
0N/A
0N/A TextField tf = (TextField)td.getComponent(td.PD_NAME_TEXTFIELD);
0N/A tf.setText((String)e.getItem());
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for Permission Actions Popup Menu
0N/A */
0N/Aclass PermissionActionsMenuListener implements ItemListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A PermissionActionsMenuListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void itemStateChanged(ItemEvent e) {
0N/A
0N/A Choice actions = (Choice)td.getComponent(td.PD_ACTIONS_CHOICE);
0N/A actions.getAccessibleContext().setAccessibleName((String)e.getItem());
0N/A
0N/A if (((String)e.getItem()).indexOf(td.PERM_ACTIONS) != -1)
0N/A return;
0N/A
0N/A TextField tf = (TextField)td.getComponent(td.PD_ACTIONS_TEXTFIELD);
0N/A if (tf.getText() == null || tf.getText().equals("")) {
0N/A tf.setText((String)e.getItem());
0N/A } else {
0N/A if (tf.getText().indexOf((String)e.getItem()) == -1)
0N/A tf.setText(tf.getText() + ", " + (String)e.getItem());
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for all the children dialogs/windows
0N/A */
0N/Aclass ChildWindowListener implements WindowListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A ChildWindowListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void windowOpened(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowClosing(WindowEvent we) {
0N/A // same as pressing the "cancel" button
0N/A td.setVisible(false);
0N/A td.dispose();
0N/A }
0N/A
0N/A public void windowClosed(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowIconified(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowDeiconified(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowActivated(WindowEvent we) {
0N/A }
0N/A
0N/A public void windowDeactivated(WindowEvent we) {
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for CancelButton button
0N/A */
0N/Aclass CancelButtonListener implements ActionListener {
0N/A
0N/A private ToolDialog td;
0N/A
0N/A CancelButtonListener(ToolDialog td) {
0N/A this.td = td;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A td.setVisible(false);
0N/A td.dispose();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for ErrorOKButton button
0N/A */
0N/Aclass ErrorOKButtonListener implements ActionListener {
0N/A
0N/A private ToolDialog ed;
0N/A
0N/A ErrorOKButtonListener(ToolDialog ed) {
0N/A this.ed = ed;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A ed.setVisible(false);
0N/A ed.dispose();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for StatusOKButton button
0N/A */
0N/Aclass StatusOKButtonListener implements ActionListener {
0N/A
0N/A private ToolDialog sd;
0N/A
0N/A StatusOKButtonListener(ToolDialog sd) {
0N/A this.sd = sd;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A sd.setVisible(false);
0N/A sd.dispose();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for UserSaveYes button
0N/A */
0N/Aclass UserSaveYesButtonListener implements ActionListener {
0N/A
0N/A private ToolDialog us;
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private int select;
0N/A
0N/A UserSaveYesButtonListener(ToolDialog us, PolicyTool tool,
0N/A ToolWindow tw, int select) {
0N/A this.us = us;
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.select = select;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A
0N/A // first get rid of the window
0N/A us.setVisible(false);
0N/A us.dispose();
0N/A
0N/A try {
0N/A String filename = ((TextField)
0N/A tw.getComponent(tw.MW_FILENAME_TEXTFIELD)).getText();
0N/A if (filename == null || filename.equals("")) {
0N/A us.displaySaveAsDialog(select);
0N/A
0N/A // the above dialog will continue with the originally
0N/A // requested command if necessary
0N/A } else {
0N/A // save the policy entries to a file
0N/A tool.savePolicy(filename);
0N/A
0N/A // display status
0N/A MessageFormat form = new MessageFormat
0N/A (PolicyTool.rb.getString
3050N/A ("Policy.successfully.written.to.filename"));
0N/A Object[] source = {filename};
0N/A tw.displayStatusDialog(null, form.format(source));
0N/A
0N/A // now continue with the originally requested command
0N/A // (QUIT, NEW, or OPEN)
0N/A us.userSaveContinue(tool, tw, us, select);
0N/A }
0N/A } catch (Exception ee) {
0N/A // error -- just report it and bail
0N/A tw.displayErrorDialog(null, ee);
0N/A }
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for UserSaveNoButton
0N/A */
0N/Aclass UserSaveNoButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog us;
0N/A private int select;
0N/A
0N/A UserSaveNoButtonListener(ToolDialog us, PolicyTool tool,
0N/A ToolWindow tw, int select) {
0N/A this.us = us;
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.select = select;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A us.setVisible(false);
0N/A us.dispose();
0N/A
0N/A // now continue with the originally requested command
0N/A // (QUIT, NEW, or OPEN)
0N/A us.userSaveContinue(tool, tw, us, select);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for UserSaveCancelButton
0N/A */
0N/Aclass UserSaveCancelButtonListener implements ActionListener {
0N/A
0N/A private ToolDialog us;
0N/A
0N/A UserSaveCancelButtonListener(ToolDialog us) {
0N/A this.us = us;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A us.setVisible(false);
0N/A us.dispose();
0N/A
0N/A // do NOT continue with the originally requested command
0N/A // (QUIT, NEW, or OPEN)
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Event handler for ConfirmRemovePolicyEntryOKButtonListener
0N/A */
0N/Aclass ConfirmRemovePolicyEntryOKButtonListener implements ActionListener {
0N/A
0N/A private PolicyTool tool;
0N/A private ToolWindow tw;
0N/A private ToolDialog us;
0N/A
0N/A ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool,
0N/A ToolWindow tw, ToolDialog us) {
0N/A this.tool = tool;
0N/A this.tw = tw;
0N/A this.us = us;
0N/A }
0N/A
0N/A public void actionPerformed(ActionEvent e) {
0N/A // remove the entry
0N/A List list = (List)tw.getComponent(tw.MW_POLICY_LIST);
0N/A int index = list.getSelectedIndex();
0N/A PolicyEntry entries[] = tool.getEntry();
0N/A tool.removeEntry(entries[index]);
0N/A
0N/A // redraw the window listing
0N/A list = new List(40, false);
0N/A list.addActionListener(new PolicyListListener(tool, tw));
0N/A entries = tool.getEntry();
0N/A if (entries != null) {
0N/A for (int i = 0; i < entries.length; i++)
0N/A list.add(entries[i].headerToString());
0N/A }
0N/A tw.replacePolicyList(list);
0N/A us.setVisible(false);
0N/A us.dispose();
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Just a special name, so that the codes dealing with this exception knows
0N/A * it's special, and does not pop out a warning box.
0N/A */
0N/Aclass NoDisplayException extends RuntimeException {
0N/A
0N/A}
0N/A
0N/A/**
0N/A * This is a java.awt.List that bind an Object to each String it holds.
0N/A */
0N/Aclass TaggedList extends List {
3388N/A private java.util.List<Object> data = new LinkedList<>();
0N/A public TaggedList(int i, boolean b) {
0N/A super(i, b);
0N/A }
0N/A
0N/A public Object getObject(int index) {
0N/A return data.get(index);
0N/A }
0N/A
0N/A @Override @Deprecated public void add(String string) {
0N/A throw new AssertionError("should not call add in TaggedList");
0N/A }
0N/A public void addTaggedItem(String string, Object object) {
0N/A super.add(string);
0N/A data.add(object);
0N/A }
0N/A
0N/A @Override @Deprecated public void replaceItem(String string, int index) {
0N/A throw new AssertionError("should not call replaceItem in TaggedList");
0N/A }
0N/A public void replaceTaggedItem(String string, Object object, int index) {
0N/A super.replaceItem(string, index);
0N/A data.set(index, object);
0N/A }
0N/A
0N/A @Override @Deprecated public void remove(int index) {
0N/A // Cannot throw AssertionError, because replaceItem() call remove() internally
0N/A super.remove(index);
0N/A }
0N/A public void removeTaggedItem(int index) {
0N/A super.remove(index);
0N/A data.remove(index);
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Convenience Principal Classes
0N/A */
0N/A
0N/Aclass Prin {
0N/A public final String CLASS;
0N/A public final String FULL_CLASS;
0N/A
0N/A public Prin(String clazz, String fullClass) {
0N/A this.CLASS = clazz;
0N/A this.FULL_CLASS = fullClass;
0N/A }
0N/A}
0N/A
0N/Aclass KrbPrin extends Prin {
0N/A public KrbPrin() {
0N/A super("KerberosPrincipal",
0N/A "javax.security.auth.kerberos.KerberosPrincipal");
0N/A }
0N/A}
0N/A
0N/Aclass X500Prin extends Prin {
0N/A public X500Prin() {
0N/A super("X500Principal",
0N/A "javax.security.auth.x500.X500Principal");
0N/A }
0N/A}
0N/A
0N/A/**
0N/A * Convenience Permission Classes
0N/A */
0N/A
0N/Aclass Perm {
0N/A public final String CLASS;
0N/A public final String FULL_CLASS;
0N/A public final String[] TARGETS;
0N/A public final String[] ACTIONS;
0N/A
0N/A public Perm(String clazz, String fullClass,
0N/A String[] targets, String[] actions) {
0N/A
0N/A this.CLASS = clazz;
0N/A this.FULL_CLASS = fullClass;
0N/A this.TARGETS = targets;
0N/A this.ACTIONS = actions;
0N/A }
0N/A}
0N/A
0N/Aclass AllPerm extends Perm {
0N/A public AllPerm() {
0N/A super("AllPermission", "java.security.AllPermission", null, null);
0N/A }
0N/A}
0N/A
0N/Aclass AudioPerm extends Perm {
0N/A public AudioPerm() {
0N/A super("AudioPermission",
0N/A "javax.sound.sampled.AudioPermission",
0N/A new String[] {
0N/A "play",
0N/A "record"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass AuthPerm extends Perm {
0N/A public AuthPerm() {
0N/A super("AuthPermission",
0N/A "javax.security.auth.AuthPermission",
0N/A new String[] {
0N/A "doAs",
0N/A "doAsPrivileged",
0N/A "getSubject",
0N/A "getSubjectFromDomainCombiner",
0N/A "setReadOnly",
0N/A "modifyPrincipals",
0N/A "modifyPublicCredentials",
0N/A "modifyPrivateCredentials",
0N/A "refreshCredential",
0N/A "destroyCredential",
0N/A "createLoginContext.<" + PolicyTool.rb.getString("name") + ">",
0N/A "getLoginConfiguration",
0N/A "setLoginConfiguration",
0N/A "createLoginConfiguration.<" +
3050N/A PolicyTool.rb.getString("configuration.type") + ">",
0N/A "refreshLoginConfiguration"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass AWTPerm extends Perm {
0N/A public AWTPerm() {
0N/A super("AWTPermission",
0N/A "java.awt.AWTPermission",
0N/A new String[] {
0N/A "accessClipboard",
0N/A "accessEventQueue",
0N/A "accessSystemTray",
0N/A "createRobot",
0N/A "fullScreenExclusive",
0N/A "listenToAllAWTEvents",
0N/A "readDisplayPixels",
0N/A "replaceKeyboardFocusManager",
0N/A "setAppletStub",
0N/A "setWindowAlwaysOnTop",
0N/A "showWindowWithoutWarningBanner",
0N/A "toolkitModality",
0N/A "watchMousePointer"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass DelegationPerm extends Perm {
0N/A public DelegationPerm() {
0N/A super("DelegationPermission",
0N/A "javax.security.auth.kerberos.DelegationPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass FilePerm extends Perm {
0N/A public FilePerm() {
0N/A super("FilePermission",
0N/A "java.io.FilePermission",
0N/A new String[] {
0N/A "<<ALL FILES>>"
0N/A },
0N/A new String[] {
0N/A "read",
0N/A "write",
0N/A "delete",
0N/A "execute"
0N/A });
0N/A }
0N/A}
0N/A
1535N/Aclass InqSecContextPerm extends Perm {
1535N/A public InqSecContextPerm() {
1535N/A super("InquireSecContextPermission",
1535N/A "com.sun.security.jgss.InquireSecContextPermission",
1535N/A new String[] {
1536N/A "KRB5_GET_SESSION_KEY",
1536N/A "KRB5_GET_TKT_FLAGS",
1536N/A "KRB5_GET_AUTHZ_DATA",
1536N/A "KRB5_GET_AUTHTIME"
1535N/A },
1535N/A null);
1535N/A }
1535N/A}
1535N/A
0N/Aclass LogPerm extends Perm {
0N/A public LogPerm() {
0N/A super("LoggingPermission",
0N/A "java.util.logging.LoggingPermission",
0N/A new String[] {
0N/A "control"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass MgmtPerm extends Perm {
0N/A public MgmtPerm() {
0N/A super("ManagementPermission",
0N/A "java.lang.management.ManagementPermission",
0N/A new String[] {
0N/A "control",
0N/A "monitor"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass MBeanPerm extends Perm {
0N/A public MBeanPerm() {
0N/A super("MBeanPermission",
0N/A "javax.management.MBeanPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A new String[] {
0N/A "addNotificationListener",
0N/A "getAttribute",
0N/A "getClassLoader",
0N/A "getClassLoaderFor",
0N/A "getClassLoaderRepository",
0N/A "getDomains",
0N/A "getMBeanInfo",
0N/A "getObjectInstance",
0N/A "instantiate",
0N/A "invoke",
0N/A "isInstanceOf",
0N/A "queryMBeans",
0N/A "queryNames",
0N/A "registerMBean",
0N/A "removeNotificationListener",
0N/A "setAttribute",
0N/A "unregisterMBean"
0N/A });
0N/A }
0N/A}
0N/A
0N/Aclass MBeanSvrPerm extends Perm {
0N/A public MBeanSvrPerm() {
0N/A super("MBeanServerPermission",
0N/A "javax.management.MBeanServerPermission",
0N/A new String[] {
0N/A "createMBeanServer",
0N/A "findMBeanServer",
0N/A "newMBeanServer",
0N/A "releaseMBeanServer"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass MBeanTrustPerm extends Perm {
0N/A public MBeanTrustPerm() {
0N/A super("MBeanTrustPermission",
0N/A "javax.management.MBeanTrustPermission",
0N/A new String[] {
0N/A "register"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass NetPerm extends Perm {
0N/A public NetPerm() {
0N/A super("NetPermission",
0N/A "java.net.NetPermission",
0N/A new String[] {
0N/A "setDefaultAuthenticator",
0N/A "requestPasswordAuthentication",
0N/A "specifyStreamHandler",
0N/A "setProxySelector",
0N/A "getProxySelector",
0N/A "setCookieHandler",
0N/A "getCookieHandler",
0N/A "setResponseCache",
0N/A "getResponseCache"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass PrivCredPerm extends Perm {
0N/A public PrivCredPerm() {
0N/A super("PrivateCredentialPermission",
0N/A "javax.security.auth.PrivateCredentialPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A new String[] {
0N/A "read"
0N/A });
0N/A }
0N/A}
0N/A
0N/Aclass PropPerm extends Perm {
0N/A public PropPerm() {
0N/A super("PropertyPermission",
0N/A "java.util.PropertyPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A new String[] {
0N/A "read",
0N/A "write"
0N/A });
0N/A }
0N/A}
0N/A
0N/Aclass ReflectPerm extends Perm {
0N/A public ReflectPerm() {
0N/A super("ReflectPermission",
0N/A "java.lang.reflect.ReflectPermission",
0N/A new String[] {
0N/A "suppressAccessChecks"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass RuntimePerm extends Perm {
0N/A public RuntimePerm() {
0N/A super("RuntimePermission",
0N/A "java.lang.RuntimePermission",
0N/A new String[] {
0N/A "createClassLoader",
0N/A "getClassLoader",
0N/A "setContextClassLoader",
0N/A "enableContextClassLoaderOverride",
371N/A "setSecurityManager",
0N/A "createSecurityManager",
0N/A "getenv.<" +
3050N/A PolicyTool.rb.getString("environment.variable.name") + ">",
0N/A "exitVM",
0N/A "shutdownHooks",
0N/A "setFactory",
0N/A "setIO",
0N/A "modifyThread",
0N/A "stopThread",
0N/A "modifyThreadGroup",
0N/A "getProtectionDomain",
0N/A "readFileDescriptor",
0N/A "writeFileDescriptor",
0N/A "loadLibrary.<" +
3050N/A PolicyTool.rb.getString("library.name") + ">",
0N/A "accessClassInPackage.<" +
3050N/A PolicyTool.rb.getString("package.name")+">",
0N/A "defineClassInPackage.<" +
3050N/A PolicyTool.rb.getString("package.name")+">",
0N/A "accessDeclaredMembers",
0N/A "queuePrintJob",
0N/A "getStackTrace",
0N/A "setDefaultUncaughtExceptionHandler",
0N/A "preferences",
0N/A "usePolicy",
0N/A // "inheritedChannel"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass SecurityPerm extends Perm {
0N/A public SecurityPerm() {
0N/A super("SecurityPermission",
0N/A "java.security.SecurityPermission",
0N/A new String[] {
0N/A "createAccessControlContext",
0N/A "getDomainCombiner",
0N/A "getPolicy",
0N/A "setPolicy",
0N/A "createPolicy.<" +
3050N/A PolicyTool.rb.getString("policy.type") + ">",
0N/A "getProperty.<" +
3050N/A PolicyTool.rb.getString("property.name") + ">",
0N/A "setProperty.<" +
3050N/A PolicyTool.rb.getString("property.name") + ">",
0N/A "insertProvider.<" +
3050N/A PolicyTool.rb.getString("provider.name") + ">",
0N/A "removeProvider.<" +
3050N/A PolicyTool.rb.getString("provider.name") + ">",
0N/A //"setSystemScope",
0N/A //"setIdentityPublicKey",
0N/A //"setIdentityInfo",
0N/A //"addIdentityCertificate",
0N/A //"removeIdentityCertificate",
0N/A //"printIdentity",
0N/A "clearProviderProperties.<" +
3050N/A PolicyTool.rb.getString("provider.name") + ">",
0N/A "putProviderProperty.<" +
3050N/A PolicyTool.rb.getString("provider.name") + ">",
0N/A "removeProviderProperty.<" +
3050N/A PolicyTool.rb.getString("provider.name") + ">",
0N/A //"getSignerPrivateKey",
0N/A //"setSignerKeyPair"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass SerialPerm extends Perm {
0N/A public SerialPerm() {
0N/A super("SerializablePermission",
0N/A "java.io.SerializablePermission",
0N/A new String[] {
0N/A "enableSubclassImplementation",
0N/A "enableSubstitution"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass ServicePerm extends Perm {
0N/A public ServicePerm() {
0N/A super("ServicePermission",
0N/A "javax.security.auth.kerberos.ServicePermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A new String[] {
0N/A "initiate",
0N/A "accept"
0N/A });
0N/A }
0N/A}
0N/A
0N/Aclass SocketPerm extends Perm {
0N/A public SocketPerm() {
0N/A super("SocketPermission",
0N/A "java.net.SocketPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A new String[] {
0N/A "accept",
0N/A "connect",
0N/A "listen",
0N/A "resolve"
0N/A });
0N/A }
0N/A}
0N/A
0N/Aclass SQLPerm extends Perm {
0N/A public SQLPerm() {
0N/A super("SQLPermission",
0N/A "java.sql.SQLPermission",
0N/A new String[] {
2753N/A "setLog",
2753N/A "callAbort",
2753N/A "setSyncFactory",
2753N/A "setNetworkTimeout",
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass SSLPerm extends Perm {
0N/A public SSLPerm() {
0N/A super("SSLPermission",
0N/A "javax.net.ssl.SSLPermission",
0N/A new String[] {
0N/A "setHostnameVerifier",
0N/A "getSSLSessionContext"
0N/A },
0N/A null);
0N/A }
0N/A}
0N/A
0N/Aclass SubjDelegPerm extends Perm {
0N/A public SubjDelegPerm() {
0N/A super("SubjectDelegationPermission",
0N/A "javax.management.remote.SubjectDelegationPermission",
0N/A new String[] {
0N/A // allow user input
0N/A },
0N/A null);
0N/A }
0N/A}