Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/security/tools/policytool/PolicyTool.java
38832 views
/*1* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.security.tools.policytool;2627import java.io.*;28import java.util.LinkedList;29import java.util.ListIterator;30import java.util.Vector;31import java.util.Enumeration;32import java.net.URL;33import java.net.MalformedURLException;34import java.lang.reflect.*;35import java.text.Collator;36import java.text.MessageFormat;37import sun.security.util.PropertyExpander;38import sun.security.util.PropertyExpander.ExpandException;39import java.awt.Component;40import java.awt.Container;41import java.awt.Dimension;42import java.awt.FileDialog;43import java.awt.GridBagConstraints;44import java.awt.GridBagLayout;45import java.awt.Insets;46import java.awt.Point;47import java.awt.Toolkit;48import java.awt.Window;49import java.awt.event.*;50import java.security.cert.Certificate;51import java.security.cert.CertificateException;52import java.security.*;53import sun.security.provider.*;54import sun.security.util.PolicyUtil;55import javax.security.auth.x500.X500Principal;56import javax.swing.*;57import javax.swing.border.EmptyBorder;5859/**60* PolicyTool may be used by users and administrators to configure the61* overall java security policy (currently stored in the policy file).62* Using PolicyTool administrators may add and remove policies from63* the policy file. <p>64*65* @see java.security.Policy66* @since 1.267*/6869public class PolicyTool {7071// for i18n72static final java.util.ResourceBundle rb =73java.util.ResourceBundle.getBundle(74"sun.security.tools.policytool.Resources");75static final Collator collator = Collator.getInstance();76static {77// this is for case insensitive string comparisons78collator.setStrength(Collator.PRIMARY);7980// Support for Apple menu bar81if (System.getProperty("apple.laf.useScreenMenuBar") == null) {82System.setProperty("apple.laf.useScreenMenuBar", "true");83}84System.setProperty("apple.awt.application.name", getMessage("Policy.Tool"));8586// Apply the system L&F if not specified with a system property.87if (System.getProperty("swing.defaultlaf") == null) {88try {89UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());90} catch (Exception e) {91// ignore92}93}94}9596// anyone can add warnings97Vector<String> warnings;98boolean newWarning = false;99100// set to true if policy modified.101// this way upon exit we know if to ask the user to save changes102boolean modified = false;103104private static final boolean testing = false;105private static final Class<?>[] TWOPARAMS = { String.class, String.class };106private static final Class<?>[] ONEPARAMS = { String.class };107private static final Class<?>[] NOPARAMS = {};108/*109* All of the policy entries are read in from the110* policy file and stored here. Updates to the policy entries111* using addEntry() and removeEntry() are made here. To ultimately save112* the policy entries back to the policy file, the SavePolicy button113* must be clicked.114**/115private static String policyFileName = null;116private Vector<PolicyEntry> policyEntries = null;117private PolicyParser parser = null;118119/* The public key alias information is stored here. */120private KeyStore keyStore = null;121private String keyStoreName = " ";122private String keyStoreType = " ";123private String keyStoreProvider = " ";124private String keyStorePwdURL = " ";125126/* standard PKCS11 KeyStore type */127private static final String P11KEYSTORE = "PKCS11";128129/* reserved word for PKCS11 KeyStores */130private static final String NONE = "NONE";131132/**133* default constructor134*/135private PolicyTool() {136policyEntries = new Vector<PolicyEntry>();137parser = new PolicyParser();138warnings = new Vector<String>();139}140141/**142* get the PolicyFileName143*/144String getPolicyFileName() {145return policyFileName;146}147148/**149* set the PolicyFileName150*/151void setPolicyFileName(String policyFileName) {152PolicyTool.policyFileName = policyFileName;153}154155/**156* clear keyStore info157*/158void clearKeyStoreInfo() {159this.keyStoreName = null;160this.keyStoreType = null;161this.keyStoreProvider = null;162this.keyStorePwdURL = null;163164this.keyStore = null;165}166167/**168* get the keyStore URL name169*/170String getKeyStoreName() {171return keyStoreName;172}173174/**175* get the keyStore Type176*/177String getKeyStoreType() {178return keyStoreType;179}180181/**182* get the keyStore Provider183*/184String getKeyStoreProvider() {185return keyStoreProvider;186}187188/**189* get the keyStore password URL190*/191String getKeyStorePwdURL() {192return keyStorePwdURL;193}194195/**196* Open and read a policy file197*/198void openPolicy(String filename) throws FileNotFoundException,199PolicyParser.ParsingException,200KeyStoreException,201CertificateException,202InstantiationException,203MalformedURLException,204IOException,205NoSuchAlgorithmException,206IllegalAccessException,207NoSuchMethodException,208UnrecoverableKeyException,209NoSuchProviderException,210ClassNotFoundException,211PropertyExpander.ExpandException,212InvocationTargetException {213214newWarning = false;215216// start fresh - blow away the current state217policyEntries = new Vector<PolicyEntry>();218parser = new PolicyParser();219warnings = new Vector<String>();220setPolicyFileName(null);221clearKeyStoreInfo();222223// see if user is opening a NEW policy file224if (filename == null) {225modified = false;226return;227}228229// Read in the policy entries from the file and230// populate the parser vector table. The parser vector231// table only holds the entries as strings, so it only232// guarantees that the policies are syntactically233// correct.234setPolicyFileName(filename);235parser.read(new FileReader(filename));236237// open the keystore238openKeyStore(parser.getKeyStoreUrl(), parser.getKeyStoreType(),239parser.getKeyStoreProvider(), parser.getStorePassURL());240241// Update the local vector with the same policy entries.242// This guarantees that the policy entries are not only243// syntactically correct, but semantically valid as well.244Enumeration<PolicyParser.GrantEntry> enum_ = parser.grantElements();245while (enum_.hasMoreElements()) {246PolicyParser.GrantEntry ge = enum_.nextElement();247248// see if all the signers have public keys249if (ge.signedBy != null) {250251String signers[] = parseSigners(ge.signedBy);252for (int i = 0; i < signers.length; i++) {253PublicKey pubKey = getPublicKeyAlias(signers[i]);254if (pubKey == null) {255newWarning = true;256MessageFormat form = new MessageFormat(getMessage257("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));258Object[] source = {signers[i]};259warnings.addElement(form.format(source));260}261}262}263264// check to see if the Principals are valid265ListIterator<PolicyParser.PrincipalEntry> prinList =266ge.principals.listIterator(0);267while (prinList.hasNext()) {268PolicyParser.PrincipalEntry pe = prinList.next();269try {270verifyPrincipal(pe.getPrincipalClass(),271pe.getPrincipalName());272} catch (ClassNotFoundException fnfe) {273newWarning = true;274MessageFormat form = new MessageFormat(getMessage275("Warning.Class.not.found.class"));276Object[] source = {pe.getPrincipalClass()};277warnings.addElement(form.format(source));278}279}280281// check to see if the Permissions are valid282Enumeration<PolicyParser.PermissionEntry> perms =283ge.permissionElements();284while (perms.hasMoreElements()) {285PolicyParser.PermissionEntry pe = perms.nextElement();286try {287verifyPermission(pe.permission, pe.name, pe.action);288} catch (ClassNotFoundException fnfe) {289newWarning = true;290MessageFormat form = new MessageFormat(getMessage291("Warning.Class.not.found.class"));292Object[] source = {pe.permission};293warnings.addElement(form.format(source));294} catch (InvocationTargetException ite) {295newWarning = true;296MessageFormat form = new MessageFormat(getMessage297("Warning.Invalid.argument.s.for.constructor.arg"));298Object[] source = {pe.permission};299warnings.addElement(form.format(source));300}301302// see if all the permission signers have public keys303if (pe.signedBy != null) {304305String signers[] = parseSigners(pe.signedBy);306307for (int i = 0; i < signers.length; i++) {308PublicKey pubKey = getPublicKeyAlias(signers[i]);309if (pubKey == null) {310newWarning = true;311MessageFormat form = new MessageFormat(getMessage312("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));313Object[] source = {signers[i]};314warnings.addElement(form.format(source));315}316}317}318}319PolicyEntry pEntry = new PolicyEntry(this, ge);320policyEntries.addElement(pEntry);321}322323// just read in the policy -- nothing has been modified yet324modified = false;325}326327328/**329* Save a policy to a file330*/331void savePolicy(String filename)332throws FileNotFoundException, IOException {333// save the policy entries to a file334parser.setKeyStoreUrl(keyStoreName);335parser.setKeyStoreType(keyStoreType);336parser.setKeyStoreProvider(keyStoreProvider);337parser.setStorePassURL(keyStorePwdURL);338parser.write(new FileWriter(filename));339modified = false;340}341342/**343* Open the KeyStore344*/345void openKeyStore(String name,346String type,347String provider,348String pwdURL) throws KeyStoreException,349NoSuchAlgorithmException,350UnrecoverableKeyException,351IOException,352CertificateException,353NoSuchProviderException,354ExpandException {355356if (name == null && type == null &&357provider == null && pwdURL == null) {358359// policy did not specify a keystore during open360// or use wants to reset keystore values361362this.keyStoreName = null;363this.keyStoreType = null;364this.keyStoreProvider = null;365this.keyStorePwdURL = null;366367// caller will set (tool.modified = true) if appropriate368369return;370}371372URL policyURL = null;373if (policyFileName != null) {374File pfile = new File(policyFileName);375policyURL = new URL("file:" + pfile.getCanonicalPath());376}377378// although PolicyUtil.getKeyStore may properly handle379// defaults and property expansion, we do it here so that380// if the call is successful, we can set the proper values381// (PolicyUtil.getKeyStore does not return expanded values)382383if (name != null && name.length() > 0) {384name = PropertyExpander.expand(name).replace385(File.separatorChar, '/');386}387if (type == null || type.length() == 0) {388type = KeyStore.getDefaultType();389}390if (pwdURL != null && pwdURL.length() > 0) {391pwdURL = PropertyExpander.expand(pwdURL).replace392(File.separatorChar, '/');393}394395try {396this.keyStore = PolicyUtil.getKeyStore(policyURL,397name,398type,399provider,400pwdURL,401null);402} catch (IOException ioe) {403404// copied from sun.security.pkcs11.SunPKCS11405String MSG = "no password provided, and no callback handler " +406"available for retrieving password";407408Throwable cause = ioe.getCause();409if (cause != null &&410cause instanceof javax.security.auth.login.LoginException &&411MSG.equals(cause.getMessage())) {412413// throw a more friendly exception message414throw new IOException(MSG);415} else {416throw ioe;417}418}419420this.keyStoreName = name;421this.keyStoreType = type;422this.keyStoreProvider = provider;423this.keyStorePwdURL = pwdURL;424425// caller will set (tool.modified = true)426}427428/**429* Add a Grant entry to the overall policy at the specified index.430* A policy entry consists of a CodeSource.431*/432boolean addEntry(PolicyEntry pe, int index) {433434if (index < 0) {435// new entry -- just add it to the end436policyEntries.addElement(pe);437parser.add(pe.getGrantEntry());438} else {439// existing entry -- replace old one440PolicyEntry origPe = policyEntries.elementAt(index);441parser.replace(origPe.getGrantEntry(), pe.getGrantEntry());442policyEntries.setElementAt(pe, index);443}444return true;445}446447/**448* Add a Principal entry to an existing PolicyEntry at the specified index.449* A Principal entry consists of a class, and name.450*451* If the principal already exists, it is not added again.452*/453boolean addPrinEntry(PolicyEntry pe,454PolicyParser.PrincipalEntry newPrin,455int index) {456457// first add the principal to the Policy Parser entry458PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();459if (grantEntry.contains(newPrin) == true)460return false;461462LinkedList<PolicyParser.PrincipalEntry> prinList =463grantEntry.principals;464if (index != -1)465prinList.set(index, newPrin);466else467prinList.add(newPrin);468469modified = true;470return true;471}472473/**474* Add a Permission entry to an existing PolicyEntry at the specified index.475* A Permission entry consists of a permission, name, and actions.476*477* If the permission already exists, it is not added again.478*/479boolean addPermEntry(PolicyEntry pe,480PolicyParser.PermissionEntry newPerm,481int index) {482483// first add the permission to the Policy Parser Vector484PolicyParser.GrantEntry grantEntry = pe.getGrantEntry();485if (grantEntry.contains(newPerm) == true)486return false;487488Vector<PolicyParser.PermissionEntry> permList =489grantEntry.permissionEntries;490if (index != -1)491permList.setElementAt(newPerm, index);492else493permList.addElement(newPerm);494495modified = true;496return true;497}498499/**500* Remove a Permission entry from an existing PolicyEntry.501*/502boolean removePermEntry(PolicyEntry pe,503PolicyParser.PermissionEntry perm) {504505// remove the Permission from the GrantEntry506PolicyParser.GrantEntry ppge = pe.getGrantEntry();507modified = ppge.remove(perm);508return modified;509}510511/**512* remove an entry from the overall policy513*/514boolean removeEntry(PolicyEntry pe) {515516parser.remove(pe.getGrantEntry());517modified = true;518return (policyEntries.removeElement(pe));519}520521/**522* retrieve all Policy Entries523*/524PolicyEntry[] getEntry() {525526if (policyEntries.size() > 0) {527PolicyEntry entries[] = new PolicyEntry[policyEntries.size()];528for (int i = 0; i < policyEntries.size(); i++)529entries[i] = policyEntries.elementAt(i);530return entries;531}532return null;533}534535/**536* Retrieve the public key mapped to a particular name.537* If the key has expired, a KeyException is thrown.538*/539PublicKey getPublicKeyAlias(String name) throws KeyStoreException {540if (keyStore == null) {541return null;542}543544Certificate cert = keyStore.getCertificate(name);545if (cert == null) {546return null;547}548PublicKey pubKey = cert.getPublicKey();549return pubKey;550}551552/**553* Retrieve all the alias names stored in the certificate database554*/555String[] getPublicKeyAlias() throws KeyStoreException {556557int numAliases = 0;558String aliases[] = null;559560if (keyStore == null) {561return null;562}563Enumeration<String> enum_ = keyStore.aliases();564565// first count the number of elements566while (enum_.hasMoreElements()) {567enum_.nextElement();568numAliases++;569}570571if (numAliases > 0) {572// now copy them into an array573aliases = new String[numAliases];574numAliases = 0;575enum_ = keyStore.aliases();576while (enum_.hasMoreElements()) {577aliases[numAliases] = new String(enum_.nextElement());578numAliases++;579}580}581return aliases;582}583584/**585* This method parses a single string of signers separated by commas586* ("jordan, duke, pippen") into an array of individual strings.587*/588String[] parseSigners(String signedBy) {589590String signers[] = null;591int numSigners = 1;592int signedByIndex = 0;593int commaIndex = 0;594int signerNum = 0;595596// first pass thru "signedBy" counts the number of signers597while (commaIndex >= 0) {598commaIndex = signedBy.indexOf(',', signedByIndex);599if (commaIndex >= 0) {600numSigners++;601signedByIndex = commaIndex + 1;602}603}604signers = new String[numSigners];605606// second pass thru "signedBy" transfers signers to array607commaIndex = 0;608signedByIndex = 0;609while (commaIndex >= 0) {610if ((commaIndex = signedBy.indexOf(',', signedByIndex)) >= 0) {611// transfer signer and ignore trailing part of the string612signers[signerNum] =613signedBy.substring(signedByIndex, commaIndex).trim();614signerNum++;615signedByIndex = commaIndex + 1;616} else {617// we are at the end of the string -- transfer signer618signers[signerNum] = signedBy.substring(signedByIndex).trim();619}620}621return signers;622}623624/**625* Check to see if the Principal contents are OK626*/627void verifyPrincipal(String type, String name)628throws ClassNotFoundException,629InstantiationException630{631if (type.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS) ||632type.equals(PolicyParser.PrincipalEntry.REPLACE_NAME)) {633return;634}635Class<?> PRIN = Class.forName("java.security.Principal");636Class<?> pc = Class.forName(type, true,637Thread.currentThread().getContextClassLoader());638if (!PRIN.isAssignableFrom(pc)) {639MessageFormat form = new MessageFormat(getMessage640("Illegal.Principal.Type.type"));641Object[] source = {type};642throw new InstantiationException(form.format(source));643}644645if (ToolDialog.X500_PRIN_CLASS.equals(pc.getName())) {646// PolicyParser checks validity of X500Principal name647// - PolicyTool needs to as well so that it doesn't store648// an invalid name that can't be read in later649//650// this can throw an IllegalArgumentException651X500Principal newP = new X500Principal(name);652}653}654655/**656* Check to see if the Permission contents are OK657*/658@SuppressWarnings("fallthrough")659void verifyPermission(String type,660String name,661String actions)662throws ClassNotFoundException,663InstantiationException,664IllegalAccessException,665NoSuchMethodException,666InvocationTargetException667{668669//XXX we might want to keep a hash of created factories...670Class<?> pc = Class.forName(type, true,671Thread.currentThread().getContextClassLoader());672Constructor<?> c = null;673Vector<String> objects = new Vector<>(2);674if (name != null) objects.add(name);675if (actions != null) objects.add(actions);676switch (objects.size()) {677case 0:678try {679c = pc.getConstructor(NOPARAMS);680break;681} catch (NoSuchMethodException ex) {682// proceed to the one-param constructor683objects.add(null);684}685/* fall through */686case 1:687try {688c = pc.getConstructor(ONEPARAMS);689break;690} catch (NoSuchMethodException ex) {691// proceed to the two-param constructor692objects.add(null);693}694/* fall through */695case 2:696c = pc.getConstructor(TWOPARAMS);697break;698}699Object parameters[] = objects.toArray();700Permission p = (Permission)c.newInstance(parameters);701}702703/*704* Parse command line arguments.705*/706static void parseArgs(String args[]) {707/* parse flags */708int n = 0;709710for (n=0; (n < args.length) && args[n].startsWith("-"); n++) {711712String flags = args[n];713714if (collator.compare(flags, "-file") == 0) {715if (++n == args.length) usage();716policyFileName = args[n];717} else {718MessageFormat form = new MessageFormat(getMessage719("Illegal.option.option"));720Object[] source = { flags };721System.err.println(form.format(source));722usage();723}724}725}726727static void usage() {728System.out.println(getMessage("Usage.policytool.options."));729System.out.println();730System.out.println(getMessage731(".file.file.policy.file.location"));732System.out.println();733734System.exit(1);735}736737/**738* run the PolicyTool739*/740public static void main(String args[]) {741parseArgs(args);742SwingUtilities.invokeLater(new Runnable() {743public void run() {744ToolWindow tw = new ToolWindow(new PolicyTool());745tw.displayToolWindow(args);746}747});748}749750// split instr to words according to capitalization,751// like, AWTControl -> A W T Control752// this method is for easy pronounciation753static String splitToWords(String instr) {754return instr.replaceAll("([A-Z])", " $1");755}756757/**758* Returns the message corresponding to the key in the bundle.759* This is preferred over {@link #getString} because it removes760* any mnemonic '&' character in the string.761*762* @param key the key763*764* @return the message765*/766static String getMessage(String key) {767return removeMnemonicAmpersand(rb.getString(key));768}769770771/**772* Returns the mnemonic for a message.773*774* @param key the key775*776* @return the mnemonic <code>int</code>777*/778static int getMnemonicInt(String key) {779String message = rb.getString(key);780return (findMnemonicInt(message));781}782783/**784* Returns the mnemonic display index for a message.785*786* @param key the key787*788* @return the mnemonic display index789*/790static int getDisplayedMnemonicIndex(String key) {791String message = rb.getString(key);792return (findMnemonicIndex(message));793}794795/**796* Finds the mnemonic character in a message.797*798* The mnemonic character is the first character followed by the first799* <code>&</code> that is not followed by another <code>&</code>.800*801* @return the mnemonic as an <code>int</code>, or <code>0</code> if it802* can't be found.803*/804private static int findMnemonicInt(String s) {805for (int i = 0; i < s.length() - 1; i++) {806if (s.charAt(i) == '&') {807if (s.charAt(i + 1) != '&') {808return KeyEvent.getExtendedKeyCodeForChar(s.charAt(i + 1));809} else {810i++;811}812}813}814return 0;815}816817/**818* Finds the index of the mnemonic character in a message.819*820* The mnemonic character is the first character followed by the first821* <code>&</code> that is not followed by another <code>&</code>.822*823* @return the mnemonic character index as an <code>int</code>, or <code>-1</code> if it824* can't be found.825*/826private static int findMnemonicIndex(String s) {827for (int i = 0; i < s.length() - 1; i++) {828if (s.charAt(i) == '&') {829if (s.charAt(i + 1) != '&') {830// Return the index of the '&' since it will be removed831return i;832} else {833i++;834}835}836}837return -1;838}839840/**841* Removes the mnemonic identifier (<code>&</code>) from a string unless842* it's escaped by <code>&&</code> or placed at the end.843*844* @param message the message845*846* @return a message with the mnemonic identifier removed847*/848private static String removeMnemonicAmpersand(String message) {849StringBuilder s = new StringBuilder();850for (int i = 0; i < message.length(); i++) {851char current = message.charAt(i);852if (current != '&' || i == message.length() - 1853|| message.charAt(i + 1) == '&') {854s.append(current);855}856}857return s.toString();858}859}860861/**862* Each entry in the policy configuration file is represented by a863* PolicyEntry object.864*865* A PolicyEntry is a (CodeSource,Permission) pair. The866* CodeSource contains the (URL, PublicKey) that together identify867* where the Java bytecodes come from and who (if anyone) signed868* them. The URL could refer to localhost. The URL could also be869* null, meaning that this policy entry is given to all comers, as870* long as they match the signer field. The signer could be null,871* meaning the code is not signed.872*873* The Permission contains the (Type, Name, Action) triplet.874*875*/876class PolicyEntry {877878private CodeSource codesource;879private PolicyTool tool;880private PolicyParser.GrantEntry grantEntry;881private boolean testing = false;882883/**884* Create a PolicyEntry object from the information read in885* from a policy file.886*/887PolicyEntry(PolicyTool tool, PolicyParser.GrantEntry ge)888throws MalformedURLException, NoSuchMethodException,889ClassNotFoundException, InstantiationException, IllegalAccessException,890InvocationTargetException, CertificateException,891IOException, NoSuchAlgorithmException, UnrecoverableKeyException {892893this.tool = tool;894895URL location = null;896897// construct the CodeSource898if (ge.codeBase != null)899location = new URL(ge.codeBase);900this.codesource = new CodeSource(location,901(java.security.cert.Certificate[]) null);902903if (testing) {904System.out.println("Adding Policy Entry:");905System.out.println(" CodeBase = " + location);906System.out.println(" Signers = " + ge.signedBy);907System.out.println(" with " + ge.principals.size() +908" Principals");909}910911this.grantEntry = ge;912}913914/**915* get the codesource associated with this PolicyEntry916*/917CodeSource getCodeSource() {918return codesource;919}920921/**922* get the GrantEntry associated with this PolicyEntry923*/924PolicyParser.GrantEntry getGrantEntry() {925return grantEntry;926}927928/**929* convert the header portion, i.e. codebase, signer, principals, of930* this policy entry into a string931*/932String headerToString() {933String pString = principalsToString();934if (pString.length() == 0) {935return codebaseToString();936} else {937return codebaseToString() + ", " + pString;938}939}940941/**942* convert the Codebase/signer portion of this policy entry into a string943*/944String codebaseToString() {945946String stringEntry = new String();947948if (grantEntry.codeBase != null &&949grantEntry.codeBase.equals("") == false)950stringEntry = stringEntry.concat951("CodeBase \"" +952grantEntry.codeBase +953"\"");954955if (grantEntry.signedBy != null &&956grantEntry.signedBy.equals("") == false)957stringEntry = ((stringEntry.length() > 0) ?958stringEntry.concat(", SignedBy \"" +959grantEntry.signedBy +960"\"") :961stringEntry.concat("SignedBy \"" +962grantEntry.signedBy +963"\""));964965if (stringEntry.length() == 0)966return new String("CodeBase <ALL>");967return stringEntry;968}969970/**971* convert the Principals portion of this policy entry into a string972*/973String principalsToString() {974String result = "";975if ((grantEntry.principals != null) &&976(!grantEntry.principals.isEmpty())) {977StringBuffer buffer = new StringBuffer(200);978ListIterator<PolicyParser.PrincipalEntry> list =979grantEntry.principals.listIterator();980while (list.hasNext()) {981PolicyParser.PrincipalEntry pppe = list.next();982buffer.append(" Principal " + pppe.getDisplayClass() + " " +983pppe.getDisplayName(true));984if (list.hasNext()) buffer.append(", ");985}986result = buffer.toString();987}988return result;989}990991/**992* convert this policy entry into a PolicyParser.PermissionEntry993*/994PolicyParser.PermissionEntry toPermissionEntry(Permission perm) {995996String actions = null;997998// get the actions999if (perm.getActions() != null &&1000perm.getActions().trim() != "")1001actions = perm.getActions();10021003PolicyParser.PermissionEntry pe = new PolicyParser.PermissionEntry1004(perm.getClass().getName(),1005perm.getName(),1006actions);1007return pe;1008}1009}10101011/**1012* The main window for the PolicyTool1013*/1014class ToolWindow extends JFrame {1015// use serialVersionUID from JDK 1.2.2 for interoperability1016private static final long serialVersionUID = 5682568601210376777L;10171018/* ESCAPE key */1019static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);10201021/* external paddings */1022public static final Insets TOP_PADDING = new Insets(25,0,0,0);1023public static final Insets BOTTOM_PADDING = new Insets(0,0,25,0);1024public static final Insets LITE_BOTTOM_PADDING = new Insets(0,0,10,0);1025public static final Insets LR_PADDING = new Insets(0,10,0,10);1026public static final Insets TOP_BOTTOM_PADDING = new Insets(15, 0, 15, 0);1027public static final Insets L_TOP_BOTTOM_PADDING = new Insets(5,10,15,0);1028public static final Insets LR_TOP_BOTTOM_PADDING = new Insets(15, 4, 15, 4);1029public static final Insets LR_BOTTOM_PADDING = new Insets(0,10,5,10);1030public static final Insets L_BOTTOM_PADDING = new Insets(0,10,5,0);1031public static final Insets R_BOTTOM_PADDING = new Insets(0, 0, 25, 5);1032public static final Insets R_PADDING = new Insets(0, 0, 0, 5);10331034/* buttons and menus */1035public static final String NEW_POLICY_FILE = "New";1036public static final String OPEN_POLICY_FILE = "Open";1037public static final String SAVE_POLICY_FILE = "Save";1038public static final String SAVE_AS_POLICY_FILE = "Save.As";1039public static final String VIEW_WARNINGS = "View.Warning.Log";1040public static final String QUIT = "Exit";1041public static final String ADD_POLICY_ENTRY = "Add.Policy.Entry";1042public static final String EDIT_POLICY_ENTRY = "Edit.Policy.Entry";1043public static final String REMOVE_POLICY_ENTRY = "Remove.Policy.Entry";1044public static final String EDIT_KEYSTORE = "Edit";1045public static final String ADD_PUBKEY_ALIAS = "Add.Public.Key.Alias";1046public static final String REMOVE_PUBKEY_ALIAS = "Remove.Public.Key.Alias";10471048/* gridbag index for components in the main window (MW) */1049public static final int MW_FILENAME_LABEL = 0;1050public static final int MW_FILENAME_TEXTFIELD = 1;1051public static final int MW_PANEL = 2;1052public static final int MW_ADD_BUTTON = 0;1053public static final int MW_EDIT_BUTTON = 1;1054public static final int MW_REMOVE_BUTTON = 2;1055public static final int MW_POLICY_LIST = 3; // follows MW_PANEL10561057/* The preferred height of JTextField should match JComboBox. */1058static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;10591060private PolicyTool tool;10611062/**1063* Constructor1064*/1065ToolWindow(PolicyTool tool) {1066this.tool = tool;1067}10681069/**1070* Don't call getComponent directly on the window1071*/1072public Component getComponent(int n) {1073Component c = getContentPane().getComponent(n);1074if (c instanceof JScrollPane) {1075c = ((JScrollPane)c).getViewport().getView();1076}1077return c;1078}10791080/**1081* Initialize the PolicyTool window with the necessary components1082*/1083private void initWindow() {1084// The ToolWindowListener will handle closing the window.1085setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);10861087// create the top menu bar1088JMenuBar menuBar = new JMenuBar();10891090// create a File menu1091JMenu menu = new JMenu();1092configureButton(menu, "File");1093ActionListener actionListener = new FileMenuListener(tool, this);1094addMenuItem(menu, NEW_POLICY_FILE, actionListener, "N");1095addMenuItem(menu, OPEN_POLICY_FILE, actionListener, "O");1096addMenuItem(menu, SAVE_POLICY_FILE, actionListener, "S");1097addMenuItem(menu, SAVE_AS_POLICY_FILE, actionListener, null);1098addMenuItem(menu, VIEW_WARNINGS, actionListener, null);1099addMenuItem(menu, QUIT, actionListener, null);1100menuBar.add(menu);11011102// create a KeyStore menu1103menu = new JMenu();1104configureButton(menu, "KeyStore");1105actionListener = new MainWindowListener(tool, this);1106addMenuItem(menu, EDIT_KEYSTORE, actionListener, null);1107menuBar.add(menu);1108setJMenuBar(menuBar);11091110// Create some space around components1111((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));11121113// policy entry listing1114JLabel label = new JLabel(PolicyTool.getMessage("Policy.File."));1115addNewComponent(this, label, MW_FILENAME_LABEL,11160, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1117LR_TOP_BOTTOM_PADDING);1118JTextField tf = new JTextField(50);1119tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));1120tf.getAccessibleContext().setAccessibleName(1121PolicyTool.getMessage("Policy.File."));1122tf.setEditable(false);1123addNewComponent(this, tf, MW_FILENAME_TEXTFIELD,11241, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1125LR_TOP_BOTTOM_PADDING);112611271128// add ADD/REMOVE/EDIT buttons in a new panel1129JPanel panel = new JPanel();1130panel.setLayout(new GridBagLayout());11311132JButton button = new JButton();1133configureButton(button, ADD_POLICY_ENTRY);1134button.addActionListener(new MainWindowListener(tool, this));1135addNewComponent(panel, button, MW_ADD_BUTTON,11360, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1137LR_PADDING);11381139button = new JButton();1140configureButton(button, EDIT_POLICY_ENTRY);1141button.addActionListener(new MainWindowListener(tool, this));1142addNewComponent(panel, button, MW_EDIT_BUTTON,11431, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1144LR_PADDING);11451146button = new JButton();1147configureButton(button, REMOVE_POLICY_ENTRY);1148button.addActionListener(new MainWindowListener(tool, this));1149addNewComponent(panel, button, MW_REMOVE_BUTTON,11502, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1151LR_PADDING);11521153addNewComponent(this, panel, MW_PANEL,11540, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,1155BOTTOM_PADDING);115611571158String policyFile = tool.getPolicyFileName();1159if (policyFile == null) {1160String userHome;1161userHome = java.security.AccessController.doPrivileged(1162new sun.security.action.GetPropertyAction("user.home"));1163policyFile = userHome + File.separatorChar + ".java.policy";1164}11651166try {1167// open the policy file1168tool.openPolicy(policyFile);11691170// display the policy entries via the policy list textarea1171DefaultListModel listModel = new DefaultListModel();1172JList list = new JList(listModel);1173list.setVisibleRowCount(15);1174list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);1175list.addMouseListener(new PolicyListListener(tool, this));1176PolicyEntry entries[] = tool.getEntry();1177if (entries != null) {1178for (int i = 0; i < entries.length; i++) {1179listModel.addElement(entries[i].headerToString());1180}1181}1182JTextField newFilename = (JTextField)1183getComponent(MW_FILENAME_TEXTFIELD);1184newFilename.setText(policyFile);1185initPolicyList(list);11861187} catch (FileNotFoundException fnfe) {1188// add blank policy listing1189JList list = new JList(new DefaultListModel());1190list.setVisibleRowCount(15);1191list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);1192list.addMouseListener(new PolicyListListener(tool, this));1193initPolicyList(list);1194tool.setPolicyFileName(null);1195tool.modified = false;11961197// just add warning1198tool.warnings.addElement(fnfe.toString());11991200} catch (Exception e) {1201// add blank policy listing1202JList list = new JList(new DefaultListModel());1203list.setVisibleRowCount(15);1204list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);1205list.addMouseListener(new PolicyListListener(tool, this));1206initPolicyList(list);1207tool.setPolicyFileName(null);1208tool.modified = false;12091210// display the error1211MessageFormat form = new MessageFormat(PolicyTool.getMessage1212("Could.not.open.policy.file.policyFile.e.toString."));1213Object[] source = {policyFile, e.toString()};1214displayErrorDialog(null, form.format(source));1215}1216}121712181219// Platform specific modifier (control / command).1220private int shortCutModifier = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();12211222private void addMenuItem(JMenu menu, String key, ActionListener actionListener, String accelerator) {1223JMenuItem menuItem = new JMenuItem();1224configureButton(menuItem, key);12251226if (PolicyTool.rb.containsKey(key + ".accelerator")) {1227// Accelerator from resources takes precedence1228accelerator = PolicyTool.getMessage(key + ".accelerator");1229}12301231if (accelerator != null && !accelerator.isEmpty()) {1232KeyStroke keyStroke;1233if (accelerator.length() == 1) {1234keyStroke = KeyStroke.getKeyStroke(KeyEvent.getExtendedKeyCodeForChar(accelerator.charAt(0)),1235shortCutModifier);1236} else {1237keyStroke = KeyStroke.getKeyStroke(accelerator);1238}1239menuItem.setAccelerator(keyStroke);1240}12411242menuItem.addActionListener(actionListener);1243menu.add(menuItem);1244}12451246static void configureButton(AbstractButton button, String key) {1247button.setText(PolicyTool.getMessage(key));1248button.setActionCommand(key);12491250int mnemonicInt = PolicyTool.getMnemonicInt(key);1251if (mnemonicInt > 0) {1252button.setMnemonic(mnemonicInt);1253button.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));1254}1255}12561257static void configureLabelFor(JLabel label, JComponent component, String key) {1258label.setText(PolicyTool.getMessage(key));1259label.setLabelFor(component);12601261int mnemonicInt = PolicyTool.getMnemonicInt(key);1262if (mnemonicInt > 0) {1263label.setDisplayedMnemonic(mnemonicInt);1264label.setDisplayedMnemonicIndex(PolicyTool.getDisplayedMnemonicIndex(key));1265}1266}126712681269/**1270* Add a component to the PolicyTool window1271*/1272void addNewComponent(Container container, JComponent component,1273int index, int gridx, int gridy, int gridwidth, int gridheight,1274double weightx, double weighty, int fill, Insets is) {12751276if (container instanceof JFrame) {1277container = ((JFrame)container).getContentPane();1278} else if (container instanceof JDialog) {1279container = ((JDialog)container).getContentPane();1280}12811282// add the component at the specified gridbag index1283container.add(component, index);12841285// set the constraints1286GridBagLayout gbl = (GridBagLayout)container.getLayout();1287GridBagConstraints gbc = new GridBagConstraints();1288gbc.gridx = gridx;1289gbc.gridy = gridy;1290gbc.gridwidth = gridwidth;1291gbc.gridheight = gridheight;1292gbc.weightx = weightx;1293gbc.weighty = weighty;1294gbc.fill = fill;1295if (is != null) gbc.insets = is;1296gbl.setConstraints(component, gbc);1297}129812991300/**1301* Add a component to the PolicyTool window without external padding1302*/1303void addNewComponent(Container container, JComponent component,1304int index, int gridx, int gridy, int gridwidth, int gridheight,1305double weightx, double weighty, int fill) {13061307// delegate with "null" external padding1308addNewComponent(container, component, index, gridx, gridy,1309gridwidth, gridheight, weightx, weighty,1310fill, null);1311}131213131314/**1315* Init the policy_entry_list TEXTAREA component in the1316* PolicyTool window1317*/1318void initPolicyList(JList policyList) {13191320// add the policy list to the window1321//policyList.setPreferredSize(new Dimension(500, 350));1322JScrollPane scrollPane = new JScrollPane(policyList);1323addNewComponent(this, scrollPane, MW_POLICY_LIST,13240, 3, 2, 1, 1.0, 1.0, GridBagConstraints.BOTH);1325}13261327/**1328* Replace the policy_entry_list TEXTAREA component in the1329* PolicyTool window with an updated one.1330*/1331void replacePolicyList(JList policyList) {13321333// remove the original list of Policy Entries1334// and add the new list of entries1335JList list = (JList)getComponent(MW_POLICY_LIST);1336list.setModel(policyList.getModel());1337}13381339/**1340* display the main PolicyTool window1341*/1342void displayToolWindow(String args[]) {13431344setTitle(PolicyTool.getMessage("Policy.Tool"));1345setResizable(true);1346addWindowListener(new ToolWindowListener(tool, this));1347//setBounds(135, 80, 500, 500);1348getContentPane().setLayout(new GridBagLayout());13491350initWindow();1351pack();1352setLocationRelativeTo(null);13531354// display it1355setVisible(true);13561357if (tool.newWarning == true) {1358displayStatusDialog(this, PolicyTool.getMessage1359("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));1360}1361}13621363/**1364* displays a dialog box describing an error which occurred.1365*/1366void displayErrorDialog(Window w, String error) {1367ToolDialog ed = new ToolDialog1368(PolicyTool.getMessage("Error"), tool, this, true);13691370// find where the PolicyTool gui is1371Point location = ((w == null) ?1372getLocationOnScreen() : w.getLocationOnScreen());1373//ed.setBounds(location.x + 50, location.y + 50, 600, 100);1374ed.setLayout(new GridBagLayout());13751376JLabel label = new JLabel(error);1377addNewComponent(ed, label, 0,13780, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);13791380JButton okButton = new JButton(PolicyTool.getMessage("OK"));1381ActionListener okListener = new ErrorOKButtonListener(ed);1382okButton.addActionListener(okListener);1383addNewComponent(ed, okButton, 1,13840, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);13851386ed.getRootPane().setDefaultButton(okButton);1387ed.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);13881389ed.pack();1390ed.setLocationRelativeTo(w);1391ed.setVisible(true);1392}13931394/**1395* displays a dialog box describing an error which occurred.1396*/1397void displayErrorDialog(Window w, Throwable t) {1398if (t instanceof NoDisplayException) {1399return;1400}1401displayErrorDialog(w, t.toString());1402}14031404/**1405* displays a dialog box describing the status of an event1406*/1407void displayStatusDialog(Window w, String status) {1408ToolDialog sd = new ToolDialog1409(PolicyTool.getMessage("Status"), tool, this, true);14101411// find the location of the PolicyTool gui1412Point location = ((w == null) ?1413getLocationOnScreen() : w.getLocationOnScreen());1414//sd.setBounds(location.x + 50, location.y + 50, 500, 100);1415sd.setLayout(new GridBagLayout());14161417JLabel label = new JLabel(status);1418addNewComponent(sd, label, 0,14190, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);14201421JButton okButton = new JButton(PolicyTool.getMessage("OK"));1422ActionListener okListener = new StatusOKButtonListener(sd);1423okButton.addActionListener(okListener);1424addNewComponent(sd, okButton, 1,14250, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);14261427sd.getRootPane().setDefaultButton(okButton);1428sd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);14291430sd.pack();1431sd.setLocationRelativeTo(w);1432sd.setVisible(true);1433}14341435/**1436* display the warning log1437*/1438void displayWarningLog(Window w) {14391440ToolDialog wd = new ToolDialog1441(PolicyTool.getMessage("Warning"), tool, this, true);14421443// find the location of the PolicyTool gui1444Point location = ((w == null) ?1445getLocationOnScreen() : w.getLocationOnScreen());1446//wd.setBounds(location.x + 50, location.y + 50, 500, 100);1447wd.setLayout(new GridBagLayout());14481449JTextArea ta = new JTextArea();1450ta.setEditable(false);1451for (int i = 0; i < tool.warnings.size(); i++) {1452ta.append(tool.warnings.elementAt(i));1453ta.append(PolicyTool.getMessage("NEWLINE"));1454}1455addNewComponent(wd, ta, 0,14560, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1457BOTTOM_PADDING);1458ta.setFocusable(false);14591460JButton okButton = new JButton(PolicyTool.getMessage("OK"));1461ActionListener okListener = new CancelButtonListener(wd);1462okButton.addActionListener(okListener);1463addNewComponent(wd, okButton, 1,14640, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,1465LR_PADDING);14661467wd.getRootPane().setDefaultButton(okButton);1468wd.getRootPane().registerKeyboardAction(okListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);14691470wd.pack();1471wd.setLocationRelativeTo(w);1472wd.setVisible(true);1473}14741475char displayYesNoDialog(Window w, String title, String prompt, String yes, String no) {14761477final ToolDialog tw = new ToolDialog1478(title, tool, this, true);1479Point location = ((w == null) ?1480getLocationOnScreen() : w.getLocationOnScreen());1481//tw.setBounds(location.x + 75, location.y + 100, 400, 150);1482tw.setLayout(new GridBagLayout());14831484JTextArea ta = new JTextArea(prompt, 10, 50);1485ta.setEditable(false);1486ta.setLineWrap(true);1487ta.setWrapStyleWord(true);1488JScrollPane scrollPane = new JScrollPane(ta,1489JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,1490JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);1491addNewComponent(tw, scrollPane, 0,14920, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);1493ta.setFocusable(false);14941495JPanel panel = new JPanel();1496panel.setLayout(new GridBagLayout());14971498// StringBuffer to store button press. Must be final.1499final StringBuffer chooseResult = new StringBuffer();15001501JButton button = new JButton(yes);1502button.addActionListener(new ActionListener() {1503public void actionPerformed(ActionEvent e) {1504chooseResult.append('Y');1505tw.setVisible(false);1506tw.dispose();1507}1508});1509addNewComponent(panel, button, 0,15100, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,1511LR_PADDING);15121513button = new JButton(no);1514button.addActionListener(new ActionListener() {1515public void actionPerformed(ActionEvent e) {1516chooseResult.append('N');1517tw.setVisible(false);1518tw.dispose();1519}1520});1521addNewComponent(panel, button, 1,15221, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,1523LR_PADDING);15241525addNewComponent(tw, panel, 1,15260, 1, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);15271528tw.pack();1529tw.setLocationRelativeTo(w);1530tw.setVisible(true);1531if (chooseResult.length() > 0) {1532return chooseResult.charAt(0);1533} else {1534// I did encounter this once, don't why.1535return 'N';1536}1537}15381539}15401541/**1542* General dialog window1543*/1544class ToolDialog extends JDialog {1545// use serialVersionUID from JDK 1.2.2 for interoperability1546private static final long serialVersionUID = -372244357011301190L;15471548/* ESCAPE key */1549static final KeyStroke escKey = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);15501551/* necessary constants */1552public static final int NOACTION = 0;1553public static final int QUIT = 1;1554public static final int NEW = 2;1555public static final int OPEN = 3;15561557public static final String ALL_PERM_CLASS =1558"java.security.AllPermission";1559public static final String FILE_PERM_CLASS =1560"java.io.FilePermission";15611562public static final String X500_PRIN_CLASS =1563"javax.security.auth.x500.X500Principal";15641565/* popup menus */1566public static final String PERM =1567PolicyTool.getMessage1568("Permission.");15691570public static final String PRIN_TYPE =1571PolicyTool.getMessage("Principal.Type.");1572public static final String PRIN_NAME =1573PolicyTool.getMessage("Principal.Name.");15741575/* more popu menus */1576public static final String PERM_NAME =1577PolicyTool.getMessage1578("Target.Name.");15791580/* and more popup menus */1581public static final String PERM_ACTIONS =1582PolicyTool.getMessage1583("Actions.");15841585/* gridbag index for display PolicyEntry (PE) components */1586public static final int PE_CODEBASE_LABEL = 0;1587public static final int PE_CODEBASE_TEXTFIELD = 1;1588public static final int PE_SIGNEDBY_LABEL = 2;1589public static final int PE_SIGNEDBY_TEXTFIELD = 3;15901591public static final int PE_PANEL0 = 4;1592public static final int PE_ADD_PRIN_BUTTON = 0;1593public static final int PE_EDIT_PRIN_BUTTON = 1;1594public static final int PE_REMOVE_PRIN_BUTTON = 2;15951596public static final int PE_PRIN_LABEL = 5;1597public static final int PE_PRIN_LIST = 6;15981599public static final int PE_PANEL1 = 7;1600public static final int PE_ADD_PERM_BUTTON = 0;1601public static final int PE_EDIT_PERM_BUTTON = 1;1602public static final int PE_REMOVE_PERM_BUTTON = 2;16031604public static final int PE_PERM_LIST = 8;16051606public static final int PE_PANEL2 = 9;1607public static final int PE_CANCEL_BUTTON = 1;1608public static final int PE_DONE_BUTTON = 0;16091610/* the gridbag index for components in the Principal Dialog (PRD) */1611public static final int PRD_DESC_LABEL = 0;1612public static final int PRD_PRIN_CHOICE = 1;1613public static final int PRD_PRIN_TEXTFIELD = 2;1614public static final int PRD_NAME_LABEL = 3;1615public static final int PRD_NAME_TEXTFIELD = 4;1616public static final int PRD_CANCEL_BUTTON = 6;1617public static final int PRD_OK_BUTTON = 5;16181619/* the gridbag index for components in the Permission Dialog (PD) */1620public static final int PD_DESC_LABEL = 0;1621public static final int PD_PERM_CHOICE = 1;1622public static final int PD_PERM_TEXTFIELD = 2;1623public static final int PD_NAME_CHOICE = 3;1624public static final int PD_NAME_TEXTFIELD = 4;1625public static final int PD_ACTIONS_CHOICE = 5;1626public static final int PD_ACTIONS_TEXTFIELD = 6;1627public static final int PD_SIGNEDBY_LABEL = 7;1628public static final int PD_SIGNEDBY_TEXTFIELD = 8;1629public static final int PD_CANCEL_BUTTON = 10;1630public static final int PD_OK_BUTTON = 9;16311632/* modes for KeyStore */1633public static final int EDIT_KEYSTORE = 0;16341635/* the gridbag index for components in the Change KeyStore Dialog (KSD) */1636public static final int KSD_NAME_LABEL = 0;1637public static final int KSD_NAME_TEXTFIELD = 1;1638public static final int KSD_TYPE_LABEL = 2;1639public static final int KSD_TYPE_TEXTFIELD = 3;1640public static final int KSD_PROVIDER_LABEL = 4;1641public static final int KSD_PROVIDER_TEXTFIELD = 5;1642public static final int KSD_PWD_URL_LABEL = 6;1643public static final int KSD_PWD_URL_TEXTFIELD = 7;1644public static final int KSD_CANCEL_BUTTON = 9;1645public static final int KSD_OK_BUTTON = 8;16461647/* the gridbag index for components in the User Save Changes Dialog (USC) */1648public static final int USC_LABEL = 0;1649public static final int USC_PANEL = 1;1650public static final int USC_YES_BUTTON = 0;1651public static final int USC_NO_BUTTON = 1;1652public static final int USC_CANCEL_BUTTON = 2;16531654/* gridbag index for the ConfirmRemovePolicyEntryDialog (CRPE) */1655public static final int CRPE_LABEL1 = 0;1656public static final int CRPE_LABEL2 = 1;1657public static final int CRPE_PANEL = 2;1658public static final int CRPE_PANEL_OK = 0;1659public static final int CRPE_PANEL_CANCEL = 1;16601661/* some private static finals */1662private static final int PERMISSION = 0;1663private static final int PERMISSION_NAME = 1;1664private static final int PERMISSION_ACTIONS = 2;1665private static final int PERMISSION_SIGNEDBY = 3;1666private static final int PRINCIPAL_TYPE = 4;1667private static final int PRINCIPAL_NAME = 5;16681669/* The preferred height of JTextField should match JComboBox. */1670static final int TEXTFIELD_HEIGHT = new JComboBox().getPreferredSize().height;16711672public static java.util.ArrayList<Perm> PERM_ARRAY;1673public static java.util.ArrayList<Prin> PRIN_ARRAY;1674PolicyTool tool;1675ToolWindow tw;16761677static {16781679// set up permission objects16801681PERM_ARRAY = new java.util.ArrayList<Perm>();1682PERM_ARRAY.add(new AllPerm());1683PERM_ARRAY.add(new AudioPerm());1684PERM_ARRAY.add(new AuthPerm());1685PERM_ARRAY.add(new AWTPerm());1686PERM_ARRAY.add(new DelegationPerm());1687PERM_ARRAY.add(new FilePerm());1688PERM_ARRAY.add(new URLPerm());1689PERM_ARRAY.add(new InqSecContextPerm());1690PERM_ARRAY.add(new LogPerm());1691PERM_ARRAY.add(new MgmtPerm());1692PERM_ARRAY.add(new MBeanPerm());1693PERM_ARRAY.add(new MBeanSvrPerm());1694PERM_ARRAY.add(new MBeanTrustPerm());1695PERM_ARRAY.add(new NetPerm());1696PERM_ARRAY.add(new PrivCredPerm());1697PERM_ARRAY.add(new PropPerm());1698PERM_ARRAY.add(new ReflectPerm());1699PERM_ARRAY.add(new RuntimePerm());1700PERM_ARRAY.add(new SecurityPerm());1701PERM_ARRAY.add(new SerialPerm());1702PERM_ARRAY.add(new ServicePerm());1703PERM_ARRAY.add(new SocketPerm());1704PERM_ARRAY.add(new SQLPerm());1705PERM_ARRAY.add(new SSLPerm());1706PERM_ARRAY.add(new SubjDelegPerm());17071708// set up principal objects17091710PRIN_ARRAY = new java.util.ArrayList<Prin>();1711PRIN_ARRAY.add(new KrbPrin());1712PRIN_ARRAY.add(new X500Prin());1713}17141715ToolDialog(String title, PolicyTool tool, ToolWindow tw, boolean modal) {1716super(tw, modal);1717setTitle(title);1718this.tool = tool;1719this.tw = tw;1720addWindowListener(new ChildWindowListener(this));17211722// Create some space around components1723((JPanel)getContentPane()).setBorder(new EmptyBorder(6, 6, 6, 6));1724}17251726/**1727* Don't call getComponent directly on the window1728*/1729public Component getComponent(int n) {1730Component c = getContentPane().getComponent(n);1731if (c instanceof JScrollPane) {1732c = ((JScrollPane)c).getViewport().getView();1733}1734return c;1735}17361737/**1738* get the Perm instance based on either the (shortened) class name1739* or the fully qualified class name1740*/1741static Perm getPerm(String clazz, boolean fullClassName) {1742for (int i = 0; i < PERM_ARRAY.size(); i++) {1743Perm next = PERM_ARRAY.get(i);1744if (fullClassName) {1745if (next.FULL_CLASS.equals(clazz)) {1746return next;1747}1748} else {1749if (next.CLASS.equals(clazz)) {1750return next;1751}1752}1753}1754return null;1755}17561757/**1758* get the Prin instance based on either the (shortened) class name1759* or the fully qualified class name1760*/1761static Prin getPrin(String clazz, boolean fullClassName) {1762for (int i = 0; i < PRIN_ARRAY.size(); i++) {1763Prin next = PRIN_ARRAY.get(i);1764if (fullClassName) {1765if (next.FULL_CLASS.equals(clazz)) {1766return next;1767}1768} else {1769if (next.CLASS.equals(clazz)) {1770return next;1771}1772}1773}1774return null;1775}17761777/**1778* pop up a dialog so the user can enter info to add a new PolicyEntry1779* - if edit is TRUE, then the user is editing an existing entry1780* and we should display the original info as well.1781*1782* - the other reason we need the 'edit' boolean is we need to know1783* when we are adding a NEW policy entry. in this case, we can1784* not simply update the existing entry, because it doesn't exist.1785* we ONLY update the GUI listing/info, and then when the user1786* finally clicks 'OK' or 'DONE', then we can collect that info1787* and add it to the policy.1788*/1789void displayPolicyEntryDialog(boolean edit) {17901791int listIndex = 0;1792PolicyEntry entries[] = null;1793TaggedList prinList = new TaggedList(3, false);1794prinList.getAccessibleContext().setAccessibleName(1795PolicyTool.getMessage("Principal.List"));1796prinList.addMouseListener1797(new EditPrinButtonListener(tool, tw, this, edit));1798TaggedList permList = new TaggedList(10, false);1799permList.getAccessibleContext().setAccessibleName(1800PolicyTool.getMessage("Permission.List"));1801permList.addMouseListener1802(new EditPermButtonListener(tool, tw, this, edit));18031804// find where the PolicyTool gui is1805Point location = tw.getLocationOnScreen();1806//setBounds(location.x + 75, location.y + 200, 650, 500);1807setLayout(new GridBagLayout());1808setResizable(true);18091810if (edit) {1811// get the selected item1812entries = tool.getEntry();1813JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);1814listIndex = policyList.getSelectedIndex();18151816// get principal list1817LinkedList<PolicyParser.PrincipalEntry> principals =1818entries[listIndex].getGrantEntry().principals;1819for (int i = 0; i < principals.size(); i++) {1820String prinString = null;1821PolicyParser.PrincipalEntry nextPrin = principals.get(i);1822prinList.addTaggedItem(PrincipalEntryToUserFriendlyString(nextPrin), nextPrin);1823}18241825// get permission list1826Vector<PolicyParser.PermissionEntry> permissions =1827entries[listIndex].getGrantEntry().permissionEntries;1828for (int i = 0; i < permissions.size(); i++) {1829String permString = null;1830PolicyParser.PermissionEntry nextPerm =1831permissions.elementAt(i);1832permList.addTaggedItem(ToolDialog.PermissionEntryToUserFriendlyString(nextPerm), nextPerm);1833}1834}18351836// codebase label and textfield1837JLabel label = new JLabel();1838tw.addNewComponent(this, label, PE_CODEBASE_LABEL,18390, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1840ToolWindow.R_PADDING);1841JTextField tf;1842tf = (edit ?1843new JTextField(entries[listIndex].getGrantEntry().codeBase) :1844new JTextField());1845ToolWindow.configureLabelFor(label, tf, "CodeBase.");1846tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));1847tf.getAccessibleContext().setAccessibleName(1848PolicyTool.getMessage("Code.Base"));1849tw.addNewComponent(this, tf, PE_CODEBASE_TEXTFIELD,18501, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);18511852// signedby label and textfield1853label = new JLabel();1854tw.addNewComponent(this, label, PE_SIGNEDBY_LABEL,18550, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1856ToolWindow.R_PADDING);1857tf = (edit ?1858new JTextField(entries[listIndex].getGrantEntry().signedBy) :1859new JTextField());1860ToolWindow.configureLabelFor(label, tf, "SignedBy.");1861tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));1862tf.getAccessibleContext().setAccessibleName(1863PolicyTool.getMessage("Signed.By."));1864tw.addNewComponent(this, tf, PE_SIGNEDBY_TEXTFIELD,18651, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH);18661867// panel for principal buttons1868JPanel panel = new JPanel();1869panel.setLayout(new GridBagLayout());18701871JButton button = new JButton();1872ToolWindow.configureButton(button, "Add.Principal");1873button.addActionListener1874(new AddPrinButtonListener(tool, tw, this, edit));1875tw.addNewComponent(panel, button, PE_ADD_PRIN_BUTTON,18760, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);18771878button = new JButton();1879ToolWindow.configureButton(button, "Edit.Principal");1880button.addActionListener(new EditPrinButtonListener1881(tool, tw, this, edit));1882tw.addNewComponent(panel, button, PE_EDIT_PRIN_BUTTON,18831, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);18841885button = new JButton();1886ToolWindow.configureButton(button, "Remove.Principal");1887button.addActionListener(new RemovePrinButtonListener1888(tool, tw, this, edit));1889tw.addNewComponent(panel, button, PE_REMOVE_PRIN_BUTTON,18902, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);18911892tw.addNewComponent(this, panel, PE_PANEL0,18931, 2, 1, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,1894ToolWindow.LITE_BOTTOM_PADDING);18951896// principal label and list1897label = new JLabel();1898tw.addNewComponent(this, label, PE_PRIN_LABEL,18990, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,1900ToolWindow.R_BOTTOM_PADDING);1901JScrollPane scrollPane = new JScrollPane(prinList);1902ToolWindow.configureLabelFor(label, scrollPane, "Principals.");1903tw.addNewComponent(this, scrollPane, PE_PRIN_LIST,19041, 3, 3, 1, 0.0, prinList.getVisibleRowCount(), GridBagConstraints.BOTH,1905ToolWindow.BOTTOM_PADDING);19061907// panel for permission buttons1908panel = new JPanel();1909panel.setLayout(new GridBagLayout());19101911button = new JButton();1912ToolWindow.configureButton(button, ".Add.Permission");1913button.addActionListener(new AddPermButtonListener1914(tool, tw, this, edit));1915tw.addNewComponent(panel, button, PE_ADD_PERM_BUTTON,19160, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);19171918button = new JButton();1919ToolWindow.configureButton(button, ".Edit.Permission");1920button.addActionListener(new EditPermButtonListener1921(tool, tw, this, edit));1922tw.addNewComponent(panel, button, PE_EDIT_PERM_BUTTON,19231, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);192419251926button = new JButton();1927ToolWindow.configureButton(button, "Remove.Permission");1928button.addActionListener(new RemovePermButtonListener1929(tool, tw, this, edit));1930tw.addNewComponent(panel, button, PE_REMOVE_PERM_BUTTON,19312, 0, 1, 1, 100.0, 0.0, GridBagConstraints.HORIZONTAL);19321933tw.addNewComponent(this, panel, PE_PANEL1,19340, 4, 2, 1, 0.0, 0.0, GridBagConstraints.HORIZONTAL,1935ToolWindow.LITE_BOTTOM_PADDING);19361937// permission list1938scrollPane = new JScrollPane(permList);1939tw.addNewComponent(this, scrollPane, PE_PERM_LIST,19400, 5, 3, 1, 0.0, permList.getVisibleRowCount(), GridBagConstraints.BOTH,1941ToolWindow.BOTTOM_PADDING);194219431944// panel for Done and Cancel buttons1945panel = new JPanel();1946panel.setLayout(new GridBagLayout());19471948// Done Button1949JButton okButton = new JButton(PolicyTool.getMessage("Done"));1950okButton.addActionListener1951(new AddEntryDoneButtonListener(tool, tw, this, edit));1952tw.addNewComponent(panel, okButton, PE_DONE_BUTTON,19530, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,1954ToolWindow.LR_PADDING);19551956// Cancel Button1957JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));1958ActionListener cancelListener = new CancelButtonListener(this);1959cancelButton.addActionListener(cancelListener);1960tw.addNewComponent(panel, cancelButton, PE_CANCEL_BUTTON,19611, 0, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,1962ToolWindow.LR_PADDING);19631964// add the panel1965tw.addNewComponent(this, panel, PE_PANEL2,19660, 6, 2, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);19671968getRootPane().setDefaultButton(okButton);1969getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);19701971pack();1972setLocationRelativeTo(tw);1973setVisible(true);1974}19751976/**1977* Read all the Policy information data in the dialog box1978* and construct a PolicyEntry object with it.1979*/1980PolicyEntry getPolicyEntryFromDialog()1981throws InvalidParameterException, MalformedURLException,1982NoSuchMethodException, ClassNotFoundException, InstantiationException,1983IllegalAccessException, InvocationTargetException,1984CertificateException, IOException, Exception {19851986// get the Codebase1987JTextField tf = (JTextField)getComponent(PE_CODEBASE_TEXTFIELD);1988String codebase = null;1989if (tf.getText().trim().equals("") == false)1990codebase = new String(tf.getText().trim());19911992// get the SignedBy1993tf = (JTextField)getComponent(PE_SIGNEDBY_TEXTFIELD);1994String signedby = null;1995if (tf.getText().trim().equals("") == false)1996signedby = new String(tf.getText().trim());19971998// construct a new GrantEntry1999PolicyParser.GrantEntry ge =2000new PolicyParser.GrantEntry(signedby, codebase);20012002// get the new Principals2003LinkedList<PolicyParser.PrincipalEntry> prins = new LinkedList<>();2004TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);2005for (int i = 0; i < prinList.getModel().getSize(); i++) {2006prins.add((PolicyParser.PrincipalEntry)prinList.getObject(i));2007}2008ge.principals = prins;20092010// get the new Permissions2011Vector<PolicyParser.PermissionEntry> perms = new Vector<>();2012TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);2013for (int i = 0; i < permList.getModel().getSize(); i++) {2014perms.addElement((PolicyParser.PermissionEntry)permList.getObject(i));2015}2016ge.permissionEntries = perms;20172018// construct a new PolicyEntry object2019PolicyEntry entry = new PolicyEntry(tool, ge);20202021return entry;2022}20232024/**2025* display a dialog box for the user to enter KeyStore information2026*/2027void keyStoreDialog(int mode) {20282029// find where the PolicyTool gui is2030Point location = tw.getLocationOnScreen();2031//setBounds(location.x + 25, location.y + 100, 500, 300);2032setLayout(new GridBagLayout());20332034if (mode == EDIT_KEYSTORE) {20352036// KeyStore label and textfield2037JLabel label = new JLabel();2038tw.addNewComponent(this, label, KSD_NAME_LABEL,20390, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2040ToolWindow.R_BOTTOM_PADDING);2041JTextField tf = new JTextField(tool.getKeyStoreName(), 30);2042ToolWindow.configureLabelFor(label, tf, "KeyStore.URL.");2043tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));20442045// URL to U R L, so that accessibility reader will pronounce well2046tf.getAccessibleContext().setAccessibleName(2047PolicyTool.getMessage("KeyStore.U.R.L."));2048tw.addNewComponent(this, tf, KSD_NAME_TEXTFIELD,20491, 0, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2050ToolWindow.BOTTOM_PADDING);20512052// KeyStore type and textfield2053label = new JLabel();2054tw.addNewComponent(this, label, KSD_TYPE_LABEL,20550, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2056ToolWindow.R_BOTTOM_PADDING);2057tf = new JTextField(tool.getKeyStoreType(), 30);2058ToolWindow.configureLabelFor(label, tf, "KeyStore.Type.");2059tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2060tf.getAccessibleContext().setAccessibleName(2061PolicyTool.getMessage("KeyStore.Type."));2062tw.addNewComponent(this, tf, KSD_TYPE_TEXTFIELD,20631, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2064ToolWindow.BOTTOM_PADDING);20652066// KeyStore provider and textfield2067label = new JLabel();2068tw.addNewComponent(this, label, KSD_PROVIDER_LABEL,20690, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2070ToolWindow.R_BOTTOM_PADDING);2071tf = new JTextField(tool.getKeyStoreProvider(), 30);2072ToolWindow.configureLabelFor(label, tf, "KeyStore.Provider.");2073tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2074tf.getAccessibleContext().setAccessibleName(2075PolicyTool.getMessage("KeyStore.Provider."));2076tw.addNewComponent(this, tf, KSD_PROVIDER_TEXTFIELD,20771, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2078ToolWindow.BOTTOM_PADDING);20792080// KeyStore password URL and textfield2081label = new JLabel();2082tw.addNewComponent(this, label, KSD_PWD_URL_LABEL,20830, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2084ToolWindow.R_BOTTOM_PADDING);2085tf = new JTextField(tool.getKeyStorePwdURL(), 30);2086ToolWindow.configureLabelFor(label, tf, "KeyStore.Password.URL.");2087tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2088tf.getAccessibleContext().setAccessibleName(2089PolicyTool.getMessage("KeyStore.Password.U.R.L."));2090tw.addNewComponent(this, tf, KSD_PWD_URL_TEXTFIELD,20911, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2092ToolWindow.BOTTOM_PADDING);20932094// OK button2095JButton okButton = new JButton(PolicyTool.getMessage("OK"));2096okButton.addActionListener2097(new ChangeKeyStoreOKButtonListener(tool, tw, this));2098tw.addNewComponent(this, okButton, KSD_OK_BUTTON,20990, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);21002101// cancel button2102JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));2103ActionListener cancelListener = new CancelButtonListener(this);2104cancelButton.addActionListener(cancelListener);2105tw.addNewComponent(this, cancelButton, KSD_CANCEL_BUTTON,21061, 4, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL);21072108getRootPane().setDefaultButton(okButton);2109getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);2110}21112112pack();2113setLocationRelativeTo(tw);2114setVisible(true);2115}21162117/**2118* display a dialog box for the user to input Principal info2119*2120* if editPolicyEntry is false, then we are adding Principals to2121* a new PolicyEntry, and we only update the GUI listing2122* with the new Principal.2123*2124* if edit is true, then we are editing an existing Policy entry.2125*/2126void displayPrincipalDialog(boolean editPolicyEntry, boolean edit) {21272128PolicyParser.PrincipalEntry editMe = null;21292130// get the Principal selected from the Principal List2131TaggedList prinList = (TaggedList)getComponent(PE_PRIN_LIST);2132int prinIndex = prinList.getSelectedIndex();21332134if (edit) {2135editMe = (PolicyParser.PrincipalEntry)prinList.getObject(prinIndex);2136}21372138ToolDialog newTD = new ToolDialog2139(PolicyTool.getMessage("Principals"), tool, tw, true);2140newTD.addWindowListener(new ChildWindowListener(newTD));21412142// find where the PolicyTool gui is2143Point location = getLocationOnScreen();2144//newTD.setBounds(location.x + 50, location.y + 100, 650, 190);2145newTD.setLayout(new GridBagLayout());2146newTD.setResizable(true);21472148// description label2149JLabel label = (edit ?2150new JLabel(PolicyTool.getMessage(".Edit.Principal.")) :2151new JLabel(PolicyTool.getMessage(".Add.New.Principal.")));2152tw.addNewComponent(newTD, label, PRD_DESC_LABEL,21530, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2154ToolWindow.TOP_BOTTOM_PADDING);21552156// principal choice2157JComboBox choice = new JComboBox();2158choice.addItem(PRIN_TYPE);2159choice.getAccessibleContext().setAccessibleName(PRIN_TYPE);2160for (int i = 0; i < PRIN_ARRAY.size(); i++) {2161Prin next = PRIN_ARRAY.get(i);2162choice.addItem(next.CLASS);2163}21642165if (edit) {2166if (PolicyParser.PrincipalEntry.WILDCARD_CLASS.equals2167(editMe.getPrincipalClass())) {2168choice.setSelectedItem(PRIN_TYPE);2169} else {2170Prin inputPrin = getPrin(editMe.getPrincipalClass(), true);2171if (inputPrin != null) {2172choice.setSelectedItem(inputPrin.CLASS);2173}2174}2175}2176// Add listener after selected item is set2177choice.addItemListener(new PrincipalTypeMenuListener(newTD));21782179tw.addNewComponent(newTD, choice, PRD_PRIN_CHOICE,21800, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2181ToolWindow.LR_PADDING);21822183// principal textfield2184JTextField tf;2185tf = (edit ?2186new JTextField(editMe.getDisplayClass(), 30) :2187new JTextField(30));2188tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2189tf.getAccessibleContext().setAccessibleName(PRIN_TYPE);2190tw.addNewComponent(newTD, tf, PRD_PRIN_TEXTFIELD,21911, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2192ToolWindow.LR_PADDING);21932194// name label and textfield2195label = new JLabel(PRIN_NAME);2196tf = (edit ?2197new JTextField(editMe.getDisplayName(), 40) :2198new JTextField(40));2199tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2200tf.getAccessibleContext().setAccessibleName(PRIN_NAME);22012202tw.addNewComponent(newTD, label, PRD_NAME_LABEL,22030, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2204ToolWindow.LR_PADDING);2205tw.addNewComponent(newTD, tf, PRD_NAME_TEXTFIELD,22061, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2207ToolWindow.LR_PADDING);22082209// OK button2210JButton okButton = new JButton(PolicyTool.getMessage("OK"));2211okButton.addActionListener(2212new NewPolicyPrinOKButtonListener2213(tool, tw, this, newTD, edit));2214tw.addNewComponent(newTD, okButton, PRD_OK_BUTTON,22150, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,2216ToolWindow.TOP_BOTTOM_PADDING);2217// cancel button2218JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));2219ActionListener cancelListener = new CancelButtonListener(newTD);2220cancelButton.addActionListener(cancelListener);2221tw.addNewComponent(newTD, cancelButton, PRD_CANCEL_BUTTON,22221, 3, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,2223ToolWindow.TOP_BOTTOM_PADDING);22242225newTD.getRootPane().setDefaultButton(okButton);2226newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);22272228newTD.pack();2229newTD.setLocationRelativeTo(tw);2230newTD.setVisible(true);2231}22322233/**2234* display a dialog box for the user to input Permission info2235*2236* if editPolicyEntry is false, then we are adding Permissions to2237* a new PolicyEntry, and we only update the GUI listing2238* with the new Permission.2239*2240* if edit is true, then we are editing an existing Permission entry.2241*/2242void displayPermissionDialog(boolean editPolicyEntry, boolean edit) {22432244PolicyParser.PermissionEntry editMe = null;22452246// get the Permission selected from the Permission List2247TaggedList permList = (TaggedList)getComponent(PE_PERM_LIST);2248int permIndex = permList.getSelectedIndex();22492250if (edit) {2251editMe = (PolicyParser.PermissionEntry)permList.getObject(permIndex);2252}22532254ToolDialog newTD = new ToolDialog2255(PolicyTool.getMessage("Permissions"), tool, tw, true);2256newTD.addWindowListener(new ChildWindowListener(newTD));22572258// find where the PolicyTool gui is2259Point location = getLocationOnScreen();2260//newTD.setBounds(location.x + 50, location.y + 100, 700, 250);2261newTD.setLayout(new GridBagLayout());2262newTD.setResizable(true);22632264// description label2265JLabel label = (edit ?2266new JLabel(PolicyTool.getMessage(".Edit.Permission.")) :2267new JLabel(PolicyTool.getMessage(".Add.New.Permission.")));2268tw.addNewComponent(newTD, label, PD_DESC_LABEL,22690, 0, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2270ToolWindow.TOP_BOTTOM_PADDING);22712272// permission choice (added in alphabetical order)2273JComboBox choice = new JComboBox();2274choice.addItem(PERM);2275choice.getAccessibleContext().setAccessibleName(PERM);2276for (int i = 0; i < PERM_ARRAY.size(); i++) {2277Perm next = PERM_ARRAY.get(i);2278choice.addItem(next.CLASS);2279}2280tw.addNewComponent(newTD, choice, PD_PERM_CHOICE,22810, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2282ToolWindow.LR_BOTTOM_PADDING);22832284// permission textfield2285JTextField tf;2286tf = (edit ? new JTextField(editMe.permission, 30) : new JTextField(30));2287tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2288tf.getAccessibleContext().setAccessibleName(PERM);2289if (edit) {2290Perm inputPerm = getPerm(editMe.permission, true);2291if (inputPerm != null) {2292choice.setSelectedItem(inputPerm.CLASS);2293}2294}2295tw.addNewComponent(newTD, tf, PD_PERM_TEXTFIELD,22961, 1, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2297ToolWindow.LR_BOTTOM_PADDING);2298choice.addItemListener(new PermissionMenuListener(newTD));22992300// name label and textfield2301choice = new JComboBox();2302choice.addItem(PERM_NAME);2303choice.getAccessibleContext().setAccessibleName(PERM_NAME);2304tf = (edit ? new JTextField(editMe.name, 40) : new JTextField(40));2305tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2306tf.getAccessibleContext().setAccessibleName(PERM_NAME);2307if (edit) {2308setPermissionNames(getPerm(editMe.permission, true), choice, tf);2309}2310tw.addNewComponent(newTD, choice, PD_NAME_CHOICE,23110, 2, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2312ToolWindow.LR_BOTTOM_PADDING);2313tw.addNewComponent(newTD, tf, PD_NAME_TEXTFIELD,23141, 2, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2315ToolWindow.LR_BOTTOM_PADDING);2316choice.addItemListener(new PermissionNameMenuListener(newTD));23172318// actions label and textfield2319choice = new JComboBox();2320choice.addItem(PERM_ACTIONS);2321choice.getAccessibleContext().setAccessibleName(PERM_ACTIONS);2322tf = (edit ? new JTextField(editMe.action, 40) : new JTextField(40));2323tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2324tf.getAccessibleContext().setAccessibleName(PERM_ACTIONS);2325if (edit) {2326setPermissionActions(getPerm(editMe.permission, true), choice, tf);2327}2328tw.addNewComponent(newTD, choice, PD_ACTIONS_CHOICE,23290, 3, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2330ToolWindow.LR_BOTTOM_PADDING);2331tw.addNewComponent(newTD, tf, PD_ACTIONS_TEXTFIELD,23321, 3, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2333ToolWindow.LR_BOTTOM_PADDING);2334choice.addItemListener(new PermissionActionsMenuListener(newTD));23352336// signedby label and textfield2337label = new JLabel(PolicyTool.getMessage("Signed.By."));2338tw.addNewComponent(newTD, label, PD_SIGNEDBY_LABEL,23390, 4, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH,2340ToolWindow.LR_BOTTOM_PADDING);2341tf = (edit ? new JTextField(editMe.signedBy, 40) : new JTextField(40));2342tf.setPreferredSize(new Dimension(tf.getPreferredSize().width, TEXTFIELD_HEIGHT));2343tf.getAccessibleContext().setAccessibleName(2344PolicyTool.getMessage("Signed.By."));2345tw.addNewComponent(newTD, tf, PD_SIGNEDBY_TEXTFIELD,23461, 4, 1, 1, 1.0, 0.0, GridBagConstraints.BOTH,2347ToolWindow.LR_BOTTOM_PADDING);23482349// OK button2350JButton okButton = new JButton(PolicyTool.getMessage("OK"));2351okButton.addActionListener(2352new NewPolicyPermOKButtonListener2353(tool, tw, this, newTD, edit));2354tw.addNewComponent(newTD, okButton, PD_OK_BUTTON,23550, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,2356ToolWindow.TOP_BOTTOM_PADDING);23572358// cancel button2359JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));2360ActionListener cancelListener = new CancelButtonListener(newTD);2361cancelButton.addActionListener(cancelListener);2362tw.addNewComponent(newTD, cancelButton, PD_CANCEL_BUTTON,23631, 5, 1, 1, 0.0, 0.0, GridBagConstraints.VERTICAL,2364ToolWindow.TOP_BOTTOM_PADDING);23652366newTD.getRootPane().setDefaultButton(okButton);2367newTD.getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);23682369newTD.pack();2370newTD.setLocationRelativeTo(tw);2371newTD.setVisible(true);2372}23732374/**2375* construct a Principal object from the Principal Info Dialog Box2376*/2377PolicyParser.PrincipalEntry getPrinFromDialog() throws Exception {23782379JTextField tf = (JTextField)getComponent(PRD_PRIN_TEXTFIELD);2380String pclass = new String(tf.getText().trim());2381tf = (JTextField)getComponent(PRD_NAME_TEXTFIELD);2382String pname = new String(tf.getText().trim());2383if (pclass.equals("*")) {2384pclass = PolicyParser.PrincipalEntry.WILDCARD_CLASS;2385}2386if (pname.equals("*")) {2387pname = PolicyParser.PrincipalEntry.WILDCARD_NAME;2388}23892390PolicyParser.PrincipalEntry pppe = null;23912392if ((pclass.equals(PolicyParser.PrincipalEntry.WILDCARD_CLASS)) &&2393(!pname.equals(PolicyParser.PrincipalEntry.WILDCARD_NAME))) {2394throw new Exception2395(PolicyTool.getMessage("Cannot.Specify.Principal.with.a.Wildcard.Class.without.a.Wildcard.Name"));2396} else if (pname.equals("")) {2397throw new Exception2398(PolicyTool.getMessage("Cannot.Specify.Principal.without.a.Name"));2399} else if (pclass.equals("")) {2400// make this consistent with what PolicyParser does2401// when it sees an empty principal class2402pclass = PolicyParser.PrincipalEntry.REPLACE_NAME;2403tool.warnings.addElement(2404"Warning: Principal name '" + pname +2405"' specified without a Principal class.\n" +2406"\t'" + pname + "' will be interpreted " +2407"as a key store alias.\n" +2408"\tThe final principal class will be " +2409ToolDialog.X500_PRIN_CLASS + ".\n" +2410"\tThe final principal name will be " +2411"determined by the following:\n" +2412"\n" +2413"\tIf the key store entry identified by '"2414+ pname + "'\n" +2415"\tis a key entry, then the principal name will be\n" +2416"\tthe subject distinguished name from the first\n" +2417"\tcertificate in the entry's certificate chain.\n" +2418"\n" +2419"\tIf the key store entry identified by '" +2420pname + "'\n" +2421"\tis a trusted certificate entry, then the\n" +2422"\tprincipal name will be the subject distinguished\n" +2423"\tname from the trusted public key certificate.");2424tw.displayStatusDialog(this,2425"'" + pname + "' will be interpreted as a key " +2426"store alias. View Warning Log for details.");2427}2428return new PolicyParser.PrincipalEntry(pclass, pname);2429}243024312432/**2433* construct a Permission object from the Permission Info Dialog Box2434*/2435PolicyParser.PermissionEntry getPermFromDialog() {24362437JTextField tf = (JTextField)getComponent(PD_PERM_TEXTFIELD);2438String permission = new String(tf.getText().trim());2439tf = (JTextField)getComponent(PD_NAME_TEXTFIELD);2440String name = null;2441if (tf.getText().trim().equals("") == false)2442name = new String(tf.getText().trim());2443if (permission.equals("") ||2444(!permission.equals(ALL_PERM_CLASS) && name == null)) {2445throw new InvalidParameterException(PolicyTool.getMessage2446("Permission.and.Target.Name.must.have.a.value"));2447}24482449// When the permission is FilePermission, we need to check the name2450// to make sure it's not escaped. We believe --2451//2452// String name.lastIndexOf("\\\\")2453// ---------------- ------------------------2454// c:\foo\bar -1, legal2455// c:\\foo\\bar 2, illegal2456// \\server\share 0, legal2457// \\\\server\share 2, illegal24582459if (permission.equals(FILE_PERM_CLASS) && name.lastIndexOf("\\\\") > 0) {2460char result = tw.displayYesNoDialog(this,2461PolicyTool.getMessage("Warning"),2462PolicyTool.getMessage(2463"Warning.File.name.may.include.escaped.backslash.characters.It.is.not.necessary.to.escape.backslash.characters.the.tool.escapes"),2464PolicyTool.getMessage("Retain"),2465PolicyTool.getMessage("Edit")2466);2467if (result != 'Y') {2468// an invisible exception2469throw new NoDisplayException();2470}2471}2472// get the Actions2473tf = (JTextField)getComponent(PD_ACTIONS_TEXTFIELD);2474String actions = null;2475if (tf.getText().trim().equals("") == false)2476actions = new String(tf.getText().trim());24772478// get the Signed By2479tf = (JTextField)getComponent(PD_SIGNEDBY_TEXTFIELD);2480String signedBy = null;2481if (tf.getText().trim().equals("") == false)2482signedBy = new String(tf.getText().trim());24832484PolicyParser.PermissionEntry pppe = new PolicyParser.PermissionEntry2485(permission, name, actions);2486pppe.signedBy = signedBy;24872488// see if the signers have public keys2489if (signedBy != null) {2490String signers[] = tool.parseSigners(pppe.signedBy);2491for (int i = 0; i < signers.length; i++) {2492try {2493PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);2494if (pubKey == null) {2495MessageFormat form = new MessageFormat2496(PolicyTool.getMessage2497("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));2498Object[] source = {signers[i]};2499tool.warnings.addElement(form.format(source));2500tw.displayStatusDialog(this, form.format(source));2501}2502} catch (Exception e) {2503tw.displayErrorDialog(this, e);2504}2505}2506}2507return pppe;2508}25092510/**2511* confirm that the user REALLY wants to remove the Policy Entry2512*/2513void displayConfirmRemovePolicyEntry() {25142515// find the entry to be removed2516JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);2517int index = list.getSelectedIndex();2518PolicyEntry entries[] = tool.getEntry();25192520// find where the PolicyTool gui is2521Point location = tw.getLocationOnScreen();2522//setBounds(location.x + 25, location.y + 100, 600, 400);2523setLayout(new GridBagLayout());25242525// ask the user do they really want to do this?2526JLabel label = new JLabel2527(PolicyTool.getMessage("Remove.this.Policy.Entry."));2528tw.addNewComponent(this, label, CRPE_LABEL1,25290, 0, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH,2530ToolWindow.BOTTOM_PADDING);25312532// display the policy entry2533label = new JLabel(entries[index].codebaseToString());2534tw.addNewComponent(this, label, CRPE_LABEL2,25350, 1, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);2536label = new JLabel(entries[index].principalsToString().trim());2537tw.addNewComponent(this, label, CRPE_LABEL2+1,25380, 2, 2, 1, 0.0, 0.0, GridBagConstraints.BOTH);2539Vector<PolicyParser.PermissionEntry> perms =2540entries[index].getGrantEntry().permissionEntries;2541for (int i = 0; i < perms.size(); i++) {2542PolicyParser.PermissionEntry nextPerm = perms.elementAt(i);2543String permString = ToolDialog.PermissionEntryToUserFriendlyString(nextPerm);2544label = new JLabel(" " + permString);2545if (i == (perms.size()-1)) {2546tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,25471, 3 + i, 1, 1, 0.0, 0.0,2548GridBagConstraints.BOTH,2549ToolWindow.BOTTOM_PADDING);2550} else {2551tw.addNewComponent(this, label, CRPE_LABEL2 + 2 + i,25521, 3 + i, 1, 1, 0.0, 0.0,2553GridBagConstraints.BOTH);2554}2555}255625572558// add OK/CANCEL buttons in a new panel2559JPanel panel = new JPanel();2560panel.setLayout(new GridBagLayout());25612562// OK button2563JButton okButton = new JButton(PolicyTool.getMessage("OK"));2564okButton.addActionListener2565(new ConfirmRemovePolicyEntryOKButtonListener(tool, tw, this));2566tw.addNewComponent(panel, okButton, CRPE_PANEL_OK,25670, 0, 1, 1, 0.0, 0.0,2568GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);25692570// cancel button2571JButton cancelButton = new JButton(PolicyTool.getMessage("Cancel"));2572ActionListener cancelListener = new CancelButtonListener(this);2573cancelButton.addActionListener(cancelListener);2574tw.addNewComponent(panel, cancelButton, CRPE_PANEL_CANCEL,25751, 0, 1, 1, 0.0, 0.0,2576GridBagConstraints.VERTICAL, ToolWindow.LR_PADDING);25772578tw.addNewComponent(this, panel, CRPE_LABEL2 + 2 + perms.size(),25790, 3 + perms.size(), 2, 1, 0.0, 0.0,2580GridBagConstraints.VERTICAL, ToolWindow.TOP_BOTTOM_PADDING);25812582getRootPane().setDefaultButton(okButton);2583getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);25842585pack();2586setLocationRelativeTo(tw);2587setVisible(true);2588}25892590/**2591* perform SAVE AS2592*/2593void displaySaveAsDialog(int nextEvent) {25942595// pop up a dialog box for the user to enter a filename.2596FileDialog fd = new FileDialog2597(tw, PolicyTool.getMessage("Save.As"), FileDialog.SAVE);2598fd.addWindowListener(new WindowAdapter() {2599public void windowClosing(WindowEvent e) {2600e.getWindow().setVisible(false);2601}2602});2603fd.setVisible(true);26042605// see if the user hit cancel2606if (fd.getFile() == null ||2607fd.getFile().equals(""))2608return;26092610// get the entered filename2611File saveAsFile = new File(fd.getDirectory(), fd.getFile());2612String filename = saveAsFile.getPath();2613fd.dispose();26142615try {2616// save the policy entries to a file2617tool.savePolicy(filename);26182619// display status2620MessageFormat form = new MessageFormat(PolicyTool.getMessage2621("Policy.successfully.written.to.filename"));2622Object[] source = {filename};2623tw.displayStatusDialog(null, form.format(source));26242625// display the new policy filename2626JTextField newFilename = (JTextField)tw.getComponent2627(ToolWindow.MW_FILENAME_TEXTFIELD);2628newFilename.setText(filename);2629tw.setVisible(true);26302631// now continue with the originally requested command2632// (QUIT, NEW, or OPEN)2633userSaveContinue(tool, tw, this, nextEvent);26342635} catch (FileNotFoundException fnfe) {2636if (filename == null || filename.equals("")) {2637tw.displayErrorDialog(null, new FileNotFoundException2638(PolicyTool.getMessage("null.filename")));2639} else {2640tw.displayErrorDialog(null, fnfe);2641}2642} catch (Exception ee) {2643tw.displayErrorDialog(null, ee);2644}2645}26462647/**2648* ask user if they want to save changes2649*/2650void displayUserSave(int select) {26512652if (tool.modified == true) {26532654// find where the PolicyTool gui is2655Point location = tw.getLocationOnScreen();2656//setBounds(location.x + 75, location.y + 100, 400, 150);2657setLayout(new GridBagLayout());26582659JLabel label = new JLabel2660(PolicyTool.getMessage("Save.changes."));2661tw.addNewComponent(this, label, USC_LABEL,26620, 0, 3, 1, 0.0, 0.0, GridBagConstraints.BOTH,2663ToolWindow.L_TOP_BOTTOM_PADDING);26642665JPanel panel = new JPanel();2666panel.setLayout(new GridBagLayout());26672668JButton yesButton = new JButton();2669ToolWindow.configureButton(yesButton, "Yes");2670yesButton.addActionListener2671(new UserSaveYesButtonListener(this, tool, tw, select));2672tw.addNewComponent(panel, yesButton, USC_YES_BUTTON,26730, 0, 1, 1, 0.0, 0.0,2674GridBagConstraints.VERTICAL,2675ToolWindow.LR_BOTTOM_PADDING);2676JButton noButton = new JButton();2677ToolWindow.configureButton(noButton, "No");2678noButton.addActionListener2679(new UserSaveNoButtonListener(this, tool, tw, select));2680tw.addNewComponent(panel, noButton, USC_NO_BUTTON,26811, 0, 1, 1, 0.0, 0.0,2682GridBagConstraints.VERTICAL,2683ToolWindow.LR_BOTTOM_PADDING);2684JButton cancelButton = new JButton();2685ToolWindow.configureButton(cancelButton, "Cancel");2686ActionListener cancelListener = new CancelButtonListener(this);2687cancelButton.addActionListener(cancelListener);2688tw.addNewComponent(panel, cancelButton, USC_CANCEL_BUTTON,26892, 0, 1, 1, 0.0, 0.0,2690GridBagConstraints.VERTICAL,2691ToolWindow.LR_BOTTOM_PADDING);26922693tw.addNewComponent(this, panel, USC_PANEL,26940, 1, 1, 1, 0.0, 0.0, GridBagConstraints.BOTH);26952696getRootPane().registerKeyboardAction(cancelListener, escKey, JComponent.WHEN_IN_FOCUSED_WINDOW);26972698pack();2699setLocationRelativeTo(tw);2700setVisible(true);2701} else {2702// just do the original request (QUIT, NEW, or OPEN)2703userSaveContinue(tool, tw, this, select);2704}2705}27062707/**2708* when the user sees the 'YES', 'NO', 'CANCEL' buttons on the2709* displayUserSave dialog, and the click on one of them,2710* we need to continue the originally requested action2711* (either QUITting, opening NEW policy file, or OPENing an existing2712* policy file. do that now.2713*/2714@SuppressWarnings("fallthrough")2715void userSaveContinue(PolicyTool tool, ToolWindow tw,2716ToolDialog us, int select) {27172718// now either QUIT, open a NEW policy file, or OPEN an existing policy2719switch(select) {2720case ToolDialog.QUIT:27212722tw.setVisible(false);2723tw.dispose();2724System.exit(0);27252726case ToolDialog.NEW:27272728try {2729tool.openPolicy(null);2730} catch (Exception ee) {2731tool.modified = false;2732tw.displayErrorDialog(null, ee);2733}27342735// display the policy entries via the policy list textarea2736JList list = new JList(new DefaultListModel());2737list.setVisibleRowCount(15);2738list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);2739list.addMouseListener(new PolicyListListener(tool, tw));2740tw.replacePolicyList(list);27412742// display null policy filename and keystore2743JTextField newFilename = (JTextField)tw.getComponent(2744ToolWindow.MW_FILENAME_TEXTFIELD);2745newFilename.setText("");2746tw.setVisible(true);2747break;27482749case ToolDialog.OPEN:27502751// pop up a dialog box for the user to enter a filename.2752FileDialog fd = new FileDialog2753(tw, PolicyTool.getMessage("Open"), FileDialog.LOAD);2754fd.addWindowListener(new WindowAdapter() {2755public void windowClosing(WindowEvent e) {2756e.getWindow().setVisible(false);2757}2758});2759fd.setVisible(true);27602761// see if the user hit 'cancel'2762if (fd.getFile() == null ||2763fd.getFile().equals(""))2764return;27652766// get the entered filename2767String policyFile = new File(fd.getDirectory(), fd.getFile()).getPath();27682769try {2770// open the policy file2771tool.openPolicy(policyFile);27722773// display the policy entries via the policy list textarea2774DefaultListModel listModel = new DefaultListModel();2775list = new JList(listModel);2776list.setVisibleRowCount(15);2777list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);2778list.addMouseListener(new PolicyListListener(tool, tw));2779PolicyEntry entries[] = tool.getEntry();2780if (entries != null) {2781for (int i = 0; i < entries.length; i++) {2782listModel.addElement(entries[i].headerToString());2783}2784}2785tw.replacePolicyList(list);2786tool.modified = false;27872788// display the new policy filename2789newFilename = (JTextField)tw.getComponent(2790ToolWindow.MW_FILENAME_TEXTFIELD);2791newFilename.setText(policyFile);2792tw.setVisible(true);27932794// inform user of warnings2795if (tool.newWarning == true) {2796tw.displayStatusDialog(null, PolicyTool.getMessage2797("Errors.have.occurred.while.opening.the.policy.configuration.View.the.Warning.Log.for.more.information."));2798}27992800} catch (Exception e) {2801// add blank policy listing2802list = new JList(new DefaultListModel());2803list.setVisibleRowCount(15);2804list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);2805list.addMouseListener(new PolicyListListener(tool, tw));2806tw.replacePolicyList(list);2807tool.setPolicyFileName(null);2808tool.modified = false;28092810// display a null policy filename2811newFilename = (JTextField)tw.getComponent(2812ToolWindow.MW_FILENAME_TEXTFIELD);2813newFilename.setText("");2814tw.setVisible(true);28152816// display the error2817MessageFormat form = new MessageFormat(PolicyTool.getMessage2818("Could.not.open.policy.file.policyFile.e.toString."));2819Object[] source = {policyFile, e.toString()};2820tw.displayErrorDialog(null, form.format(source));2821}2822break;2823}2824}28252826/**2827* Return a Menu list of names for a given permission2828*2829* If inputPerm's TARGETS are null, then this means TARGETS are2830* not allowed to be entered (and the TextField is set to be2831* non-editable).2832*2833* If TARGETS are valid but there are no standard ones2834* (user must enter them by hand) then the TARGETS array may be empty2835* (and of course non-null).2836*/2837void setPermissionNames(Perm inputPerm, JComboBox names, JTextField field) {2838names.removeAllItems();2839names.addItem(PERM_NAME);28402841if (inputPerm == null) {2842// custom permission2843field.setEditable(true);2844} else if (inputPerm.TARGETS == null) {2845// standard permission with no targets2846field.setEditable(false);2847} else {2848// standard permission with standard targets2849field.setEditable(true);2850for (int i = 0; i < inputPerm.TARGETS.length; i++) {2851names.addItem(inputPerm.TARGETS[i]);2852}2853}2854}28552856/**2857* Return a Menu list of actions for a given permission2858*2859* If inputPerm's ACTIONS are null, then this means ACTIONS are2860* not allowed to be entered (and the TextField is set to be2861* non-editable). This is typically true for BasicPermissions.2862*2863* If ACTIONS are valid but there are no standard ones2864* (user must enter them by hand) then the ACTIONS array may be empty2865* (and of course non-null).2866*/2867void setPermissionActions(Perm inputPerm, JComboBox actions, JTextField field) {2868actions.removeAllItems();2869actions.addItem(PERM_ACTIONS);28702871if (inputPerm == null) {2872// custom permission2873field.setEditable(true);2874} else if (inputPerm.ACTIONS == null) {2875// standard permission with no actions2876field.setEditable(false);2877} else {2878// standard permission with standard actions2879field.setEditable(true);2880for (int i = 0; i < inputPerm.ACTIONS.length; i++) {2881actions.addItem(inputPerm.ACTIONS[i]);2882}2883}2884}28852886static String PermissionEntryToUserFriendlyString(PolicyParser.PermissionEntry pppe) {2887String result = pppe.permission;2888if (pppe.name != null) {2889result += " " + pppe.name;2890}2891if (pppe.action != null) {2892result += ", \"" + pppe.action + "\"";2893}2894if (pppe.signedBy != null) {2895result += ", signedBy " + pppe.signedBy;2896}2897return result;2898}28992900static String PrincipalEntryToUserFriendlyString(PolicyParser.PrincipalEntry pppe) {2901StringWriter sw = new StringWriter();2902PrintWriter pw = new PrintWriter(sw);2903pppe.write(pw);2904return sw.toString();2905}2906}29072908/**2909* Event handler for the PolicyTool window2910*/2911class ToolWindowListener implements WindowListener {29122913private PolicyTool tool;2914private ToolWindow tw;29152916ToolWindowListener(PolicyTool tool, ToolWindow tw) {2917this.tool = tool;2918this.tw = tw;2919}29202921public void windowOpened(WindowEvent we) {2922}29232924public void windowClosing(WindowEvent we) {2925// Closing the window acts the same as choosing Menu->Exit.29262927// ask user if they want to save changes2928ToolDialog td = new ToolDialog(PolicyTool.getMessage("Save.Changes"), tool, tw, true);2929td.displayUserSave(ToolDialog.QUIT);29302931// the above method will perform the QUIT as long as the2932// user does not CANCEL the request2933}29342935public void windowClosed(WindowEvent we) {2936System.exit(0);2937}29382939public void windowIconified(WindowEvent we) {2940}29412942public void windowDeiconified(WindowEvent we) {2943}29442945public void windowActivated(WindowEvent we) {2946}29472948public void windowDeactivated(WindowEvent we) {2949}2950}29512952/**2953* Event handler for the Policy List2954*/2955class PolicyListListener extends MouseAdapter implements ActionListener {29562957private PolicyTool tool;2958private ToolWindow tw;29592960PolicyListListener(PolicyTool tool, ToolWindow tw) {2961this.tool = tool;2962this.tw = tw;29632964}29652966public void actionPerformed(ActionEvent e) {29672968// display the permission list for a policy entry2969ToolDialog td = new ToolDialog2970(PolicyTool.getMessage("Policy.Entry"), tool, tw, true);2971td.displayPolicyEntryDialog(true);2972}29732974public void mouseClicked(MouseEvent evt) {2975if (evt.getClickCount() == 2) {2976actionPerformed(null);2977}2978}2979}29802981/**2982* Event handler for the File Menu2983*/2984class FileMenuListener implements ActionListener {29852986private PolicyTool tool;2987private ToolWindow tw;29882989FileMenuListener(PolicyTool tool, ToolWindow tw) {2990this.tool = tool;2991this.tw = tw;2992}29932994public void actionPerformed(ActionEvent e) {29952996if (PolicyTool.collator.compare(e.getActionCommand(),2997ToolWindow.QUIT) == 0) {29982999// ask user if they want to save changes3000ToolDialog td = new ToolDialog3001(PolicyTool.getMessage("Save.Changes"), tool, tw, true);3002td.displayUserSave(ToolDialog.QUIT);30033004// the above method will perform the QUIT as long as the3005// user does not CANCEL the request30063007} else if (PolicyTool.collator.compare(e.getActionCommand(),3008ToolWindow.NEW_POLICY_FILE) == 0) {30093010// ask user if they want to save changes3011ToolDialog td = new ToolDialog3012(PolicyTool.getMessage("Save.Changes"), tool, tw, true);3013td.displayUserSave(ToolDialog.NEW);30143015// the above method will perform the NEW as long as the3016// user does not CANCEL the request30173018} else if (PolicyTool.collator.compare(e.getActionCommand(),3019ToolWindow.OPEN_POLICY_FILE) == 0) {30203021// ask user if they want to save changes3022ToolDialog td = new ToolDialog3023(PolicyTool.getMessage("Save.Changes"), tool, tw, true);3024td.displayUserSave(ToolDialog.OPEN);30253026// the above method will perform the OPEN as long as the3027// user does not CANCEL the request30283029} else if (PolicyTool.collator.compare(e.getActionCommand(),3030ToolWindow.SAVE_POLICY_FILE) == 0) {30313032// get the previously entered filename3033String filename = ((JTextField)tw.getComponent(3034ToolWindow.MW_FILENAME_TEXTFIELD)).getText();30353036// if there is no filename, do a SAVE_AS3037if (filename == null || filename.length() == 0) {3038// user wants to SAVE AS3039ToolDialog td = new ToolDialog3040(PolicyTool.getMessage("Save.As"), tool, tw, true);3041td.displaySaveAsDialog(ToolDialog.NOACTION);3042} else {3043try {3044// save the policy entries to a file3045tool.savePolicy(filename);30463047// display status3048MessageFormat form = new MessageFormat3049(PolicyTool.getMessage3050("Policy.successfully.written.to.filename"));3051Object[] source = {filename};3052tw.displayStatusDialog(null, form.format(source));3053} catch (FileNotFoundException fnfe) {3054if (filename == null || filename.equals("")) {3055tw.displayErrorDialog(null, new FileNotFoundException3056(PolicyTool.getMessage("null.filename")));3057} else {3058tw.displayErrorDialog(null, fnfe);3059}3060} catch (Exception ee) {3061tw.displayErrorDialog(null, ee);3062}3063}3064} else if (PolicyTool.collator.compare(e.getActionCommand(),3065ToolWindow.SAVE_AS_POLICY_FILE) == 0) {30663067// user wants to SAVE AS3068ToolDialog td = new ToolDialog3069(PolicyTool.getMessage("Save.As"), tool, tw, true);3070td.displaySaveAsDialog(ToolDialog.NOACTION);30713072} else if (PolicyTool.collator.compare(e.getActionCommand(),3073ToolWindow.VIEW_WARNINGS) == 0) {3074tw.displayWarningLog(null);3075}3076}3077}30783079/**3080* Event handler for the main window buttons and Edit Menu3081*/3082class MainWindowListener implements ActionListener {30833084private PolicyTool tool;3085private ToolWindow tw;30863087MainWindowListener(PolicyTool tool, ToolWindow tw) {3088this.tool = tool;3089this.tw = tw;3090}30913092public void actionPerformed(ActionEvent e) {30933094if (PolicyTool.collator.compare(e.getActionCommand(),3095ToolWindow.ADD_POLICY_ENTRY) == 0) {30963097// display a dialog box for the user to enter policy info3098ToolDialog td = new ToolDialog3099(PolicyTool.getMessage("Policy.Entry"), tool, tw, true);3100td.displayPolicyEntryDialog(false);31013102} else if (PolicyTool.collator.compare(e.getActionCommand(),3103ToolWindow.REMOVE_POLICY_ENTRY) == 0) {31043105// get the selected entry3106JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);3107int index = list.getSelectedIndex();3108if (index < 0) {3109tw.displayErrorDialog(null, new Exception3110(PolicyTool.getMessage("No.Policy.Entry.selected")));3111return;3112}31133114// ask the user if they really want to remove the policy entry3115ToolDialog td = new ToolDialog(PolicyTool.getMessage3116("Remove.Policy.Entry"), tool, tw, true);3117td.displayConfirmRemovePolicyEntry();31183119} else if (PolicyTool.collator.compare(e.getActionCommand(),3120ToolWindow.EDIT_POLICY_ENTRY) == 0) {31213122// get the selected entry3123JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);3124int index = list.getSelectedIndex();3125if (index < 0) {3126tw.displayErrorDialog(null, new Exception3127(PolicyTool.getMessage("No.Policy.Entry.selected")));3128return;3129}31303131// display the permission list for a policy entry3132ToolDialog td = new ToolDialog3133(PolicyTool.getMessage("Policy.Entry"), tool, tw, true);3134td.displayPolicyEntryDialog(true);31353136} else if (PolicyTool.collator.compare(e.getActionCommand(),3137ToolWindow.EDIT_KEYSTORE) == 0) {31383139// display a dialog box for the user to enter keystore info3140ToolDialog td = new ToolDialog3141(PolicyTool.getMessage("KeyStore"), tool, tw, true);3142td.keyStoreDialog(ToolDialog.EDIT_KEYSTORE);3143}3144}3145}31463147/**3148* Event handler for AddEntryDoneButton button3149*3150* -- if edit is TRUE, then we are EDITing an existing PolicyEntry3151* and we need to update both the policy and the GUI listing.3152* if edit is FALSE, then we are ADDing a new PolicyEntry,3153* so we only need to update the GUI listing.3154*/3155class AddEntryDoneButtonListener implements ActionListener {31563157private PolicyTool tool;3158private ToolWindow tw;3159private ToolDialog td;3160private boolean edit;31613162AddEntryDoneButtonListener(PolicyTool tool, ToolWindow tw,3163ToolDialog td, boolean edit) {3164this.tool = tool;3165this.tw = tw;3166this.td = td;3167this.edit = edit;3168}31693170public void actionPerformed(ActionEvent e) {31713172try {3173// get a PolicyEntry object from the dialog policy info3174PolicyEntry newEntry = td.getPolicyEntryFromDialog();3175PolicyParser.GrantEntry newGe = newEntry.getGrantEntry();31763177// see if all the signers have public keys3178if (newGe.signedBy != null) {3179String signers[] = tool.parseSigners(newGe.signedBy);3180for (int i = 0; i < signers.length; i++) {3181PublicKey pubKey = tool.getPublicKeyAlias(signers[i]);3182if (pubKey == null) {3183MessageFormat form = new MessageFormat3184(PolicyTool.getMessage3185("Warning.A.public.key.for.alias.signers.i.does.not.exist.Make.sure.a.KeyStore.is.properly.configured."));3186Object[] source = {signers[i]};3187tool.warnings.addElement(form.format(source));3188tw.displayStatusDialog(td, form.format(source));3189}3190}3191}31923193// add the entry3194JList policyList = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);3195if (edit) {3196int listIndex = policyList.getSelectedIndex();3197tool.addEntry(newEntry, listIndex);3198String newCodeBaseStr = newEntry.headerToString();3199if (PolicyTool.collator.compare3200(newCodeBaseStr, policyList.getModel().getElementAt(listIndex)) != 0)3201tool.modified = true;3202((DefaultListModel)policyList.getModel()).set(listIndex, newCodeBaseStr);3203} else {3204tool.addEntry(newEntry, -1);3205((DefaultListModel)policyList.getModel()).addElement(newEntry.headerToString());3206tool.modified = true;3207}3208td.setVisible(false);3209td.dispose();32103211} catch (Exception eee) {3212tw.displayErrorDialog(td, eee);3213}3214}3215}32163217/**3218* Event handler for ChangeKeyStoreOKButton button3219*/3220class ChangeKeyStoreOKButtonListener implements ActionListener {32213222private PolicyTool tool;3223private ToolWindow tw;3224private ToolDialog td;32253226ChangeKeyStoreOKButtonListener(PolicyTool tool, ToolWindow tw,3227ToolDialog td) {3228this.tool = tool;3229this.tw = tw;3230this.td = td;3231}32323233public void actionPerformed(ActionEvent e) {32343235String URLString = ((JTextField)td.getComponent(3236ToolDialog.KSD_NAME_TEXTFIELD)).getText().trim();3237String type = ((JTextField)td.getComponent(3238ToolDialog.KSD_TYPE_TEXTFIELD)).getText().trim();3239String provider = ((JTextField)td.getComponent(3240ToolDialog.KSD_PROVIDER_TEXTFIELD)).getText().trim();3241String pwdURL = ((JTextField)td.getComponent(3242ToolDialog.KSD_PWD_URL_TEXTFIELD)).getText().trim();32433244try {3245tool.openKeyStore3246((URLString.length() == 0 ? null : URLString),3247(type.length() == 0 ? null : type),3248(provider.length() == 0 ? null : provider),3249(pwdURL.length() == 0 ? null : pwdURL));3250tool.modified = true;3251} catch (Exception ex) {3252MessageFormat form = new MessageFormat(PolicyTool.getMessage3253("Unable.to.open.KeyStore.ex.toString."));3254Object[] source = {ex.toString()};3255tw.displayErrorDialog(td, form.format(source));3256return;3257}32583259td.dispose();3260}3261}32623263/**3264* Event handler for AddPrinButton button3265*/3266class AddPrinButtonListener implements ActionListener {32673268private PolicyTool tool;3269private ToolWindow tw;3270private ToolDialog td;3271private boolean editPolicyEntry;32723273AddPrinButtonListener(PolicyTool tool, ToolWindow tw,3274ToolDialog td, boolean editPolicyEntry) {3275this.tool = tool;3276this.tw = tw;3277this.td = td;3278this.editPolicyEntry = editPolicyEntry;3279}32803281public void actionPerformed(ActionEvent e) {32823283// display a dialog box for the user to enter principal info3284td.displayPrincipalDialog(editPolicyEntry, false);3285}3286}32873288/**3289* Event handler for AddPermButton button3290*/3291class AddPermButtonListener implements ActionListener {32923293private PolicyTool tool;3294private ToolWindow tw;3295private ToolDialog td;3296private boolean editPolicyEntry;32973298AddPermButtonListener(PolicyTool tool, ToolWindow tw,3299ToolDialog td, boolean editPolicyEntry) {3300this.tool = tool;3301this.tw = tw;3302this.td = td;3303this.editPolicyEntry = editPolicyEntry;3304}33053306public void actionPerformed(ActionEvent e) {33073308// display a dialog box for the user to enter permission info3309td.displayPermissionDialog(editPolicyEntry, false);3310}3311}33123313/**3314* Event handler for AddPrinOKButton button3315*/3316class NewPolicyPrinOKButtonListener implements ActionListener {33173318private PolicyTool tool;3319private ToolWindow tw;3320private ToolDialog listDialog;3321private ToolDialog infoDialog;3322private boolean edit;33233324NewPolicyPrinOKButtonListener(PolicyTool tool,3325ToolWindow tw,3326ToolDialog listDialog,3327ToolDialog infoDialog,3328boolean edit) {3329this.tool = tool;3330this.tw = tw;3331this.listDialog = listDialog;3332this.infoDialog = infoDialog;3333this.edit = edit;3334}33353336public void actionPerformed(ActionEvent e) {33373338try {3339// read in the new principal info from Dialog Box3340PolicyParser.PrincipalEntry pppe =3341infoDialog.getPrinFromDialog();3342if (pppe != null) {3343try {3344tool.verifyPrincipal(pppe.getPrincipalClass(),3345pppe.getPrincipalName());3346} catch (ClassNotFoundException cnfe) {3347MessageFormat form = new MessageFormat3348(PolicyTool.getMessage3349("Warning.Class.not.found.class"));3350Object[] source = {pppe.getPrincipalClass()};3351tool.warnings.addElement(form.format(source));3352tw.displayStatusDialog(infoDialog, form.format(source));3353}33543355// add the principal to the GUI principal list3356TaggedList prinList =3357(TaggedList)listDialog.getComponent(ToolDialog.PE_PRIN_LIST);33583359String prinString = ToolDialog.PrincipalEntryToUserFriendlyString(pppe);3360if (edit) {3361// if editing, replace the original principal3362int index = prinList.getSelectedIndex();3363prinList.replaceTaggedItem(prinString, pppe, index);3364} else {3365// if adding, just add it to the end3366prinList.addTaggedItem(prinString, pppe);3367}3368}3369infoDialog.dispose();3370} catch (Exception ee) {3371tw.displayErrorDialog(infoDialog, ee);3372}3373}3374}33753376/**3377* Event handler for AddPermOKButton button3378*/3379class NewPolicyPermOKButtonListener implements ActionListener {33803381private PolicyTool tool;3382private ToolWindow tw;3383private ToolDialog listDialog;3384private ToolDialog infoDialog;3385private boolean edit;33863387NewPolicyPermOKButtonListener(PolicyTool tool,3388ToolWindow tw,3389ToolDialog listDialog,3390ToolDialog infoDialog,3391boolean edit) {3392this.tool = tool;3393this.tw = tw;3394this.listDialog = listDialog;3395this.infoDialog = infoDialog;3396this.edit = edit;3397}33983399public void actionPerformed(ActionEvent e) {34003401try {3402// read in the new permission info from Dialog Box3403PolicyParser.PermissionEntry pppe =3404infoDialog.getPermFromDialog();34053406try {3407tool.verifyPermission(pppe.permission, pppe.name, pppe.action);3408} catch (ClassNotFoundException cnfe) {3409MessageFormat form = new MessageFormat(PolicyTool.getMessage3410("Warning.Class.not.found.class"));3411Object[] source = {pppe.permission};3412tool.warnings.addElement(form.format(source));3413tw.displayStatusDialog(infoDialog, form.format(source));3414}34153416// add the permission to the GUI permission list3417TaggedList permList =3418(TaggedList)listDialog.getComponent(ToolDialog.PE_PERM_LIST);34193420String permString = ToolDialog.PermissionEntryToUserFriendlyString(pppe);3421if (edit) {3422// if editing, replace the original permission3423int which = permList.getSelectedIndex();3424permList.replaceTaggedItem(permString, pppe, which);3425} else {3426// if adding, just add it to the end3427permList.addTaggedItem(permString, pppe);3428}3429infoDialog.dispose();34303431} catch (InvocationTargetException ite) {3432tw.displayErrorDialog(infoDialog, ite.getTargetException());3433} catch (Exception ee) {3434tw.displayErrorDialog(infoDialog, ee);3435}3436}3437}34383439/**3440* Event handler for RemovePrinButton button3441*/3442class RemovePrinButtonListener implements ActionListener {34433444private PolicyTool tool;3445private ToolWindow tw;3446private ToolDialog td;3447private boolean edit;34483449RemovePrinButtonListener(PolicyTool tool, ToolWindow tw,3450ToolDialog td, boolean edit) {3451this.tool = tool;3452this.tw = tw;3453this.td = td;3454this.edit = edit;3455}34563457public void actionPerformed(ActionEvent e) {34583459// get the Principal selected from the Principal List3460TaggedList prinList = (TaggedList)td.getComponent(3461ToolDialog.PE_PRIN_LIST);3462int prinIndex = prinList.getSelectedIndex();34633464if (prinIndex < 0) {3465tw.displayErrorDialog(td, new Exception3466(PolicyTool.getMessage("No.principal.selected")));3467return;3468}3469// remove the principal from the display3470prinList.removeTaggedItem(prinIndex);3471}3472}34733474/**3475* Event handler for RemovePermButton button3476*/3477class RemovePermButtonListener implements ActionListener {34783479private PolicyTool tool;3480private ToolWindow tw;3481private ToolDialog td;3482private boolean edit;34833484RemovePermButtonListener(PolicyTool tool, ToolWindow tw,3485ToolDialog td, boolean edit) {3486this.tool = tool;3487this.tw = tw;3488this.td = td;3489this.edit = edit;3490}34913492public void actionPerformed(ActionEvent e) {34933494// get the Permission selected from the Permission List3495TaggedList permList = (TaggedList)td.getComponent(3496ToolDialog.PE_PERM_LIST);3497int permIndex = permList.getSelectedIndex();34983499if (permIndex < 0) {3500tw.displayErrorDialog(td, new Exception3501(PolicyTool.getMessage("No.permission.selected")));3502return;3503}3504// remove the permission from the display3505permList.removeTaggedItem(permIndex);35063507}3508}35093510/**3511* Event handler for Edit Principal button3512*3513* We need the editPolicyEntry boolean to tell us if the user is3514* adding a new PolicyEntry at this time, or editing an existing entry.3515* If the user is adding a new PolicyEntry, we ONLY update the3516* GUI listing. If the user is editing an existing PolicyEntry, we3517* update both the GUI listing and the actual PolicyEntry.3518*/3519class EditPrinButtonListener extends MouseAdapter implements ActionListener {35203521private PolicyTool tool;3522private ToolWindow tw;3523private ToolDialog td;3524private boolean editPolicyEntry;35253526EditPrinButtonListener(PolicyTool tool, ToolWindow tw,3527ToolDialog td, boolean editPolicyEntry) {3528this.tool = tool;3529this.tw = tw;3530this.td = td;3531this.editPolicyEntry = editPolicyEntry;3532}35333534public void actionPerformed(ActionEvent e) {35353536// get the Principal selected from the Principal List3537TaggedList list = (TaggedList)td.getComponent(3538ToolDialog.PE_PRIN_LIST);3539int prinIndex = list.getSelectedIndex();35403541if (prinIndex < 0) {3542tw.displayErrorDialog(td, new Exception3543(PolicyTool.getMessage("No.principal.selected")));3544return;3545}3546td.displayPrincipalDialog(editPolicyEntry, true);3547}35483549public void mouseClicked(MouseEvent evt) {3550if (evt.getClickCount() == 2) {3551actionPerformed(null);3552}3553}3554}35553556/**3557* Event handler for Edit Permission button3558*3559* We need the editPolicyEntry boolean to tell us if the user is3560* adding a new PolicyEntry at this time, or editing an existing entry.3561* If the user is adding a new PolicyEntry, we ONLY update the3562* GUI listing. If the user is editing an existing PolicyEntry, we3563* update both the GUI listing and the actual PolicyEntry.3564*/3565class EditPermButtonListener extends MouseAdapter implements ActionListener {35663567private PolicyTool tool;3568private ToolWindow tw;3569private ToolDialog td;3570private boolean editPolicyEntry;35713572EditPermButtonListener(PolicyTool tool, ToolWindow tw,3573ToolDialog td, boolean editPolicyEntry) {3574this.tool = tool;3575this.tw = tw;3576this.td = td;3577this.editPolicyEntry = editPolicyEntry;3578}35793580public void actionPerformed(ActionEvent e) {35813582// get the Permission selected from the Permission List3583JList list = (JList)td.getComponent(ToolDialog.PE_PERM_LIST);3584int permIndex = list.getSelectedIndex();35853586if (permIndex < 0) {3587tw.displayErrorDialog(td, new Exception3588(PolicyTool.getMessage("No.permission.selected")));3589return;3590}3591td.displayPermissionDialog(editPolicyEntry, true);3592}35933594public void mouseClicked(MouseEvent evt) {3595if (evt.getClickCount() == 2) {3596actionPerformed(null);3597}3598}3599}36003601/**3602* Event handler for Principal Popup Menu3603*/3604class PrincipalTypeMenuListener implements ItemListener {36053606private ToolDialog td;36073608PrincipalTypeMenuListener(ToolDialog td) {3609this.td = td;3610}36113612public void itemStateChanged(ItemEvent e) {3613if (e.getStateChange() == ItemEvent.DESELECTED) {3614// We're only interested in SELECTED events3615return;3616}36173618JComboBox prin = (JComboBox)td.getComponent(ToolDialog.PRD_PRIN_CHOICE);3619JTextField prinField = (JTextField)td.getComponent(3620ToolDialog.PRD_PRIN_TEXTFIELD);3621JTextField nameField = (JTextField)td.getComponent(3622ToolDialog.PRD_NAME_TEXTFIELD);36233624prin.getAccessibleContext().setAccessibleName(3625PolicyTool.splitToWords((String)e.getItem()));3626if (((String)e.getItem()).equals(ToolDialog.PRIN_TYPE)) {3627// ignore if they choose "Principal Type:" item3628if (prinField.getText() != null &&3629prinField.getText().length() > 0) {3630Prin inputPrin = ToolDialog.getPrin(prinField.getText(), true);3631prin.setSelectedItem(inputPrin.CLASS);3632}3633return;3634}36353636// if you change the principal, clear the name3637if (prinField.getText().indexOf((String)e.getItem()) == -1) {3638nameField.setText("");3639}36403641// set the text in the textfield and also modify the3642// pull-down choice menus to reflect the correct possible3643// set of names and actions3644Prin inputPrin = ToolDialog.getPrin((String)e.getItem(), false);3645if (inputPrin != null) {3646prinField.setText(inputPrin.FULL_CLASS);3647}3648}3649}36503651/**3652* Event handler for Permission Popup Menu3653*/3654class PermissionMenuListener implements ItemListener {36553656private ToolDialog td;36573658PermissionMenuListener(ToolDialog td) {3659this.td = td;3660}36613662public void itemStateChanged(ItemEvent e) {3663if (e.getStateChange() == ItemEvent.DESELECTED) {3664// We're only interested in SELECTED events3665return;3666}36673668JComboBox perms = (JComboBox)td.getComponent(3669ToolDialog.PD_PERM_CHOICE);3670JComboBox names = (JComboBox)td.getComponent(3671ToolDialog.PD_NAME_CHOICE);3672JComboBox actions = (JComboBox)td.getComponent(3673ToolDialog.PD_ACTIONS_CHOICE);3674JTextField nameField = (JTextField)td.getComponent(3675ToolDialog.PD_NAME_TEXTFIELD);3676JTextField actionsField = (JTextField)td.getComponent(3677ToolDialog.PD_ACTIONS_TEXTFIELD);3678JTextField permField = (JTextField)td.getComponent(3679ToolDialog.PD_PERM_TEXTFIELD);3680JTextField signedbyField = (JTextField)td.getComponent(3681ToolDialog.PD_SIGNEDBY_TEXTFIELD);36823683perms.getAccessibleContext().setAccessibleName(3684PolicyTool.splitToWords((String)e.getItem()));36853686// ignore if they choose the 'Permission:' item3687if (PolicyTool.collator.compare((String)e.getItem(),3688ToolDialog.PERM) == 0) {3689if (permField.getText() != null &&3690permField.getText().length() > 0) {36913692Perm inputPerm = ToolDialog.getPerm(permField.getText(), true);3693if (inputPerm != null) {3694perms.setSelectedItem(inputPerm.CLASS);3695}3696}3697return;3698}36993700// if you change the permission, clear the name, actions, and signedBy3701if (permField.getText().indexOf((String)e.getItem()) == -1) {3702nameField.setText("");3703actionsField.setText("");3704signedbyField.setText("");3705}37063707// set the text in the textfield and also modify the3708// pull-down choice menus to reflect the correct possible3709// set of names and actions37103711Perm inputPerm = ToolDialog.getPerm((String)e.getItem(), false);3712if (inputPerm == null) {3713permField.setText("");3714} else {3715permField.setText(inputPerm.FULL_CLASS);3716}3717td.setPermissionNames(inputPerm, names, nameField);3718td.setPermissionActions(inputPerm, actions, actionsField);3719}3720}37213722/**3723* Event handler for Permission Name Popup Menu3724*/3725class PermissionNameMenuListener implements ItemListener {37263727private ToolDialog td;37283729PermissionNameMenuListener(ToolDialog td) {3730this.td = td;3731}37323733public void itemStateChanged(ItemEvent e) {3734if (e.getStateChange() == ItemEvent.DESELECTED) {3735// We're only interested in SELECTED events3736return;3737}37383739JComboBox names = (JComboBox)td.getComponent(ToolDialog.PD_NAME_CHOICE);3740names.getAccessibleContext().setAccessibleName(3741PolicyTool.splitToWords((String)e.getItem()));37423743if (((String)e.getItem()).indexOf(ToolDialog.PERM_NAME) != -1)3744return;37453746JTextField tf = (JTextField)td.getComponent(ToolDialog.PD_NAME_TEXTFIELD);3747tf.setText((String)e.getItem());3748}3749}37503751/**3752* Event handler for Permission Actions Popup Menu3753*/3754class PermissionActionsMenuListener implements ItemListener {37553756private ToolDialog td;37573758PermissionActionsMenuListener(ToolDialog td) {3759this.td = td;3760}37613762public void itemStateChanged(ItemEvent e) {3763if (e.getStateChange() == ItemEvent.DESELECTED) {3764// We're only interested in SELECTED events3765return;3766}37673768JComboBox actions = (JComboBox)td.getComponent(3769ToolDialog.PD_ACTIONS_CHOICE);3770actions.getAccessibleContext().setAccessibleName((String)e.getItem());37713772if (((String)e.getItem()).indexOf(ToolDialog.PERM_ACTIONS) != -1)3773return;37743775JTextField tf = (JTextField)td.getComponent(3776ToolDialog.PD_ACTIONS_TEXTFIELD);3777if (tf.getText() == null || tf.getText().equals("")) {3778tf.setText((String)e.getItem());3779} else {3780if (tf.getText().indexOf((String)e.getItem()) == -1)3781tf.setText(tf.getText() + ", " + (String)e.getItem());3782}3783}3784}37853786/**3787* Event handler for all the children dialogs/windows3788*/3789class ChildWindowListener implements WindowListener {37903791private ToolDialog td;37923793ChildWindowListener(ToolDialog td) {3794this.td = td;3795}37963797public void windowOpened(WindowEvent we) {3798}37993800public void windowClosing(WindowEvent we) {3801// same as pressing the "cancel" button3802td.setVisible(false);3803td.dispose();3804}38053806public void windowClosed(WindowEvent we) {3807}38083809public void windowIconified(WindowEvent we) {3810}38113812public void windowDeiconified(WindowEvent we) {3813}38143815public void windowActivated(WindowEvent we) {3816}38173818public void windowDeactivated(WindowEvent we) {3819}3820}38213822/**3823* Event handler for CancelButton button3824*/3825class CancelButtonListener implements ActionListener {38263827private ToolDialog td;38283829CancelButtonListener(ToolDialog td) {3830this.td = td;3831}38323833public void actionPerformed(ActionEvent e) {3834td.setVisible(false);3835td.dispose();3836}3837}38383839/**3840* Event handler for ErrorOKButton button3841*/3842class ErrorOKButtonListener implements ActionListener {38433844private ToolDialog ed;38453846ErrorOKButtonListener(ToolDialog ed) {3847this.ed = ed;3848}38493850public void actionPerformed(ActionEvent e) {3851ed.setVisible(false);3852ed.dispose();3853}3854}38553856/**3857* Event handler for StatusOKButton button3858*/3859class StatusOKButtonListener implements ActionListener {38603861private ToolDialog sd;38623863StatusOKButtonListener(ToolDialog sd) {3864this.sd = sd;3865}38663867public void actionPerformed(ActionEvent e) {3868sd.setVisible(false);3869sd.dispose();3870}3871}38723873/**3874* Event handler for UserSaveYes button3875*/3876class UserSaveYesButtonListener implements ActionListener {38773878private ToolDialog us;3879private PolicyTool tool;3880private ToolWindow tw;3881private int select;38823883UserSaveYesButtonListener(ToolDialog us, PolicyTool tool,3884ToolWindow tw, int select) {3885this.us = us;3886this.tool = tool;3887this.tw = tw;3888this.select = select;3889}38903891public void actionPerformed(ActionEvent e) {38923893// first get rid of the window3894us.setVisible(false);3895us.dispose();38963897try {3898String filename = ((JTextField)tw.getComponent(3899ToolWindow.MW_FILENAME_TEXTFIELD)).getText();3900if (filename == null || filename.equals("")) {3901us.displaySaveAsDialog(select);39023903// the above dialog will continue with the originally3904// requested command if necessary3905} else {3906// save the policy entries to a file3907tool.savePolicy(filename);39083909// display status3910MessageFormat form = new MessageFormat3911(PolicyTool.getMessage3912("Policy.successfully.written.to.filename"));3913Object[] source = {filename};3914tw.displayStatusDialog(null, form.format(source));39153916// now continue with the originally requested command3917// (QUIT, NEW, or OPEN)3918us.userSaveContinue(tool, tw, us, select);3919}3920} catch (Exception ee) {3921// error -- just report it and bail3922tw.displayErrorDialog(null, ee);3923}3924}3925}39263927/**3928* Event handler for UserSaveNoButton3929*/3930class UserSaveNoButtonListener implements ActionListener {39313932private PolicyTool tool;3933private ToolWindow tw;3934private ToolDialog us;3935private int select;39363937UserSaveNoButtonListener(ToolDialog us, PolicyTool tool,3938ToolWindow tw, int select) {3939this.us = us;3940this.tool = tool;3941this.tw = tw;3942this.select = select;3943}39443945public void actionPerformed(ActionEvent e) {3946us.setVisible(false);3947us.dispose();39483949// now continue with the originally requested command3950// (QUIT, NEW, or OPEN)3951us.userSaveContinue(tool, tw, us, select);3952}3953}39543955/**3956* Event handler for UserSaveCancelButton3957*/3958class UserSaveCancelButtonListener implements ActionListener {39593960private ToolDialog us;39613962UserSaveCancelButtonListener(ToolDialog us) {3963this.us = us;3964}39653966public void actionPerformed(ActionEvent e) {3967us.setVisible(false);3968us.dispose();39693970// do NOT continue with the originally requested command3971// (QUIT, NEW, or OPEN)3972}3973}39743975/**3976* Event handler for ConfirmRemovePolicyEntryOKButtonListener3977*/3978class ConfirmRemovePolicyEntryOKButtonListener implements ActionListener {39793980private PolicyTool tool;3981private ToolWindow tw;3982private ToolDialog us;39833984ConfirmRemovePolicyEntryOKButtonListener(PolicyTool tool,3985ToolWindow tw, ToolDialog us) {3986this.tool = tool;3987this.tw = tw;3988this.us = us;3989}39903991public void actionPerformed(ActionEvent e) {3992// remove the entry3993JList list = (JList)tw.getComponent(ToolWindow.MW_POLICY_LIST);3994int index = list.getSelectedIndex();3995PolicyEntry entries[] = tool.getEntry();3996tool.removeEntry(entries[index]);39973998// redraw the window listing3999DefaultListModel listModel = new DefaultListModel();4000list = new JList(listModel);4001list.setVisibleRowCount(15);4002list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);4003list.addMouseListener(new PolicyListListener(tool, tw));4004entries = tool.getEntry();4005if (entries != null) {4006for (int i = 0; i < entries.length; i++) {4007listModel.addElement(entries[i].headerToString());4008}4009}4010tw.replacePolicyList(list);4011us.setVisible(false);4012us.dispose();4013}4014}40154016/**4017* Just a special name, so that the codes dealing with this exception knows4018* it's special, and does not pop out a warning box.4019*/4020class NoDisplayException extends RuntimeException {4021private static final long serialVersionUID = -4611761427108719794L;4022}40234024/**4025* This is a java.awt.List that bind an Object to each String it holds.4026*/4027class TaggedList extends JList {4028private static final long serialVersionUID = -5676238110427785853L;40294030private java.util.List<Object> data = new LinkedList<>();4031public TaggedList(int i, boolean b) {4032super(new DefaultListModel());4033setVisibleRowCount(i);4034setSelectionMode(b ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION : ListSelectionModel.SINGLE_SELECTION);4035}40364037public Object getObject(int index) {4038return data.get(index);4039}40404041public void addTaggedItem(String string, Object object) {4042((DefaultListModel)getModel()).addElement(string);4043data.add(object);4044}40454046public void replaceTaggedItem(String string, Object object, int index) {4047((DefaultListModel)getModel()).set(index, string);4048data.set(index, object);4049}40504051public void removeTaggedItem(int index) {4052((DefaultListModel)getModel()).remove(index);4053data.remove(index);4054}4055}40564057/**4058* Convenience Principal Classes4059*/40604061class Prin {4062public final String CLASS;4063public final String FULL_CLASS;40644065public Prin(String clazz, String fullClass) {4066this.CLASS = clazz;4067this.FULL_CLASS = fullClass;4068}4069}40704071class KrbPrin extends Prin {4072public KrbPrin() {4073super("KerberosPrincipal",4074"javax.security.auth.kerberos.KerberosPrincipal");4075}4076}40774078class X500Prin extends Prin {4079public X500Prin() {4080super("X500Principal",4081"javax.security.auth.x500.X500Principal");4082}4083}40844085/**4086* Convenience Permission Classes4087*/40884089class Perm {4090public final String CLASS;4091public final String FULL_CLASS;4092public final String[] TARGETS;4093public final String[] ACTIONS;40944095public Perm(String clazz, String fullClass,4096String[] targets, String[] actions) {40974098this.CLASS = clazz;4099this.FULL_CLASS = fullClass;4100this.TARGETS = targets;4101this.ACTIONS = actions;4102}4103}41044105class AllPerm extends Perm {4106public AllPerm() {4107super("AllPermission", "java.security.AllPermission", null, null);4108}4109}41104111class AudioPerm extends Perm {4112public AudioPerm() {4113super("AudioPermission",4114"javax.sound.sampled.AudioPermission",4115new String[] {4116"play",4117"record"4118},4119null);4120}4121}41224123class AuthPerm extends Perm {4124public AuthPerm() {4125super("AuthPermission",4126"javax.security.auth.AuthPermission",4127new String[] {4128"doAs",4129"doAsPrivileged",4130"getSubject",4131"getSubjectFromDomainCombiner",4132"setReadOnly",4133"modifyPrincipals",4134"modifyPublicCredentials",4135"modifyPrivateCredentials",4136"refreshCredential",4137"destroyCredential",4138"createLoginContext.<" + PolicyTool.getMessage("name") + ">",4139"getLoginConfiguration",4140"setLoginConfiguration",4141"createLoginConfiguration.<" +4142PolicyTool.getMessage("configuration.type") + ">",4143"refreshLoginConfiguration"4144},4145null);4146}4147}41484149class AWTPerm extends Perm {4150public AWTPerm() {4151super("AWTPermission",4152"java.awt.AWTPermission",4153new String[] {4154"accessClipboard",4155"accessEventQueue",4156"accessSystemTray",4157"createRobot",4158"fullScreenExclusive",4159"listenToAllAWTEvents",4160"readDisplayPixels",4161"replaceKeyboardFocusManager",4162"setAppletStub",4163"setWindowAlwaysOnTop",4164"showWindowWithoutWarningBanner",4165"toolkitModality",4166"watchMousePointer"4167},4168null);4169}4170}41714172class DelegationPerm extends Perm {4173public DelegationPerm() {4174super("DelegationPermission",4175"javax.security.auth.kerberos.DelegationPermission",4176new String[] {4177// allow user input4178},4179null);4180}4181}41824183class FilePerm extends Perm {4184public FilePerm() {4185super("FilePermission",4186"java.io.FilePermission",4187new String[] {4188"<<ALL FILES>>"4189},4190new String[] {4191"read",4192"write",4193"delete",4194"execute"4195});4196}4197}41984199class URLPerm extends Perm {4200public URLPerm() {4201super("URLPermission",4202"java.net.URLPermission",4203new String[] {4204"<"+ PolicyTool.getMessage("url") + ">",4205},4206new String[] {4207"<" + PolicyTool.getMessage("method.list") + ">:<"4208+ PolicyTool.getMessage("request.headers.list") + ">",4209});4210}4211}42124213class InqSecContextPerm extends Perm {4214public InqSecContextPerm() {4215super("InquireSecContextPermission",4216"com.sun.security.jgss.InquireSecContextPermission",4217new String[] {4218"KRB5_GET_SESSION_KEY",4219"KRB5_GET_TKT_FLAGS",4220"KRB5_GET_AUTHZ_DATA",4221"KRB5_GET_AUTHTIME"4222},4223null);4224}4225}42264227class LogPerm extends Perm {4228public LogPerm() {4229super("LoggingPermission",4230"java.util.logging.LoggingPermission",4231new String[] {4232"control"4233},4234null);4235}4236}42374238class MgmtPerm extends Perm {4239public MgmtPerm() {4240super("ManagementPermission",4241"java.lang.management.ManagementPermission",4242new String[] {4243"control",4244"monitor"4245},4246null);4247}4248}42494250class MBeanPerm extends Perm {4251public MBeanPerm() {4252super("MBeanPermission",4253"javax.management.MBeanPermission",4254new String[] {4255// allow user input4256},4257new String[] {4258"addNotificationListener",4259"getAttribute",4260"getClassLoader",4261"getClassLoaderFor",4262"getClassLoaderRepository",4263"getDomains",4264"getMBeanInfo",4265"getObjectInstance",4266"instantiate",4267"invoke",4268"isInstanceOf",4269"queryMBeans",4270"queryNames",4271"registerMBean",4272"removeNotificationListener",4273"setAttribute",4274"unregisterMBean"4275});4276}4277}42784279class MBeanSvrPerm extends Perm {4280public MBeanSvrPerm() {4281super("MBeanServerPermission",4282"javax.management.MBeanServerPermission",4283new String[] {4284"createMBeanServer",4285"findMBeanServer",4286"newMBeanServer",4287"releaseMBeanServer"4288},4289null);4290}4291}42924293class MBeanTrustPerm extends Perm {4294public MBeanTrustPerm() {4295super("MBeanTrustPermission",4296"javax.management.MBeanTrustPermission",4297new String[] {4298"register"4299},4300null);4301}4302}43034304class NetPerm extends Perm {4305public NetPerm() {4306super("NetPermission",4307"java.net.NetPermission",4308new String[] {4309"setDefaultAuthenticator",4310"requestPasswordAuthentication",4311"specifyStreamHandler",4312"setProxySelector",4313"getProxySelector",4314"setCookieHandler",4315"getCookieHandler",4316"setResponseCache",4317"getResponseCache"4318},4319null);4320}4321}43224323class PrivCredPerm extends Perm {4324public PrivCredPerm() {4325super("PrivateCredentialPermission",4326"javax.security.auth.PrivateCredentialPermission",4327new String[] {4328// allow user input4329},4330new String[] {4331"read"4332});4333}4334}43354336class PropPerm extends Perm {4337public PropPerm() {4338super("PropertyPermission",4339"java.util.PropertyPermission",4340new String[] {4341// allow user input4342},4343new String[] {4344"read",4345"write"4346});4347}4348}43494350class ReflectPerm extends Perm {4351public ReflectPerm() {4352super("ReflectPermission",4353"java.lang.reflect.ReflectPermission",4354new String[] {4355"suppressAccessChecks"4356},4357null);4358}4359}43604361class RuntimePerm extends Perm {4362public RuntimePerm() {4363super("RuntimePermission",4364"java.lang.RuntimePermission",4365new String[] {4366"createClassLoader",4367"getClassLoader",4368"setContextClassLoader",4369"enableContextClassLoaderOverride",4370"setSecurityManager",4371"createSecurityManager",4372"getenv.<" +4373PolicyTool.getMessage("environment.variable.name") + ">",4374"exitVM",4375"shutdownHooks",4376"setFactory",4377"setIO",4378"modifyThread",4379"stopThread",4380"modifyThreadGroup",4381"getProtectionDomain",4382"readFileDescriptor",4383"writeFileDescriptor",4384"loadLibrary.<" +4385PolicyTool.getMessage("library.name") + ">",4386"accessClassInPackage.<" +4387PolicyTool.getMessage("package.name")+">",4388"defineClassInPackage.<" +4389PolicyTool.getMessage("package.name")+">",4390"accessDeclaredMembers",4391"queuePrintJob",4392"getStackTrace",4393"setDefaultUncaughtExceptionHandler",4394"preferences",4395"usePolicy",4396// "inheritedChannel"4397},4398null);4399}4400}44014402class SecurityPerm extends Perm {4403public SecurityPerm() {4404super("SecurityPermission",4405"java.security.SecurityPermission",4406new String[] {4407"createAccessControlContext",4408"getDomainCombiner",4409"getPolicy",4410"setPolicy",4411"createPolicy.<" +4412PolicyTool.getMessage("policy.type") + ">",4413"getProperty.<" +4414PolicyTool.getMessage("property.name") + ">",4415"setProperty.<" +4416PolicyTool.getMessage("property.name") + ">",4417"insertProvider.<" +4418PolicyTool.getMessage("provider.name") + ">",4419"removeProvider.<" +4420PolicyTool.getMessage("provider.name") + ">",4421//"setSystemScope",4422//"setIdentityPublicKey",4423//"setIdentityInfo",4424//"addIdentityCertificate",4425//"removeIdentityCertificate",4426//"printIdentity",4427"clearProviderProperties.<" +4428PolicyTool.getMessage("provider.name") + ">",4429"putProviderProperty.<" +4430PolicyTool.getMessage("provider.name") + ">",4431"removeProviderProperty.<" +4432PolicyTool.getMessage("provider.name") + ">",4433//"getSignerPrivateKey",4434//"setSignerKeyPair"4435},4436null);4437}4438}44394440class SerialPerm extends Perm {4441public SerialPerm() {4442super("SerializablePermission",4443"java.io.SerializablePermission",4444new String[] {4445"enableSubclassImplementation",4446"enableSubstitution"4447},4448null);4449}4450}44514452class ServicePerm extends Perm {4453public ServicePerm() {4454super("ServicePermission",4455"javax.security.auth.kerberos.ServicePermission",4456new String[] {4457// allow user input4458},4459new String[] {4460"initiate",4461"accept"4462});4463}4464}44654466class SocketPerm extends Perm {4467public SocketPerm() {4468super("SocketPermission",4469"java.net.SocketPermission",4470new String[] {4471// allow user input4472},4473new String[] {4474"accept",4475"connect",4476"listen",4477"resolve"4478});4479}4480}44814482class SQLPerm extends Perm {4483public SQLPerm() {4484super("SQLPermission",4485"java.sql.SQLPermission",4486new String[] {4487"setLog",4488"callAbort",4489"setSyncFactory",4490"setNetworkTimeout",4491},4492null);4493}4494}44954496class SSLPerm extends Perm {4497public SSLPerm() {4498super("SSLPermission",4499"javax.net.ssl.SSLPermission",4500new String[] {4501"setHostnameVerifier",4502"getSSLSessionContext"4503},4504null);4505}4506}45074508class SubjDelegPerm extends Perm {4509public SubjDelegPerm() {4510super("SubjectDelegationPermission",4511"javax.management.remote.SubjectDelegationPermission",4512new String[] {4513// allow user input4514},4515null);4516}4517}451845194520