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