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