PageRenderTime 76ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 1ms

/src/share/classes/sun/security/tools/policytool/PolicyTool.java

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