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