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