PageRenderTime 91ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

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

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