PageRenderTime 80ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 2ms

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

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