1. /*
  2. * @(#)PolicyFile.java 1.30 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package com.sun.security.auth;
  8. import java.io.*;
  9. import java.lang.RuntimePermission;
  10. import java.lang.reflect.*;
  11. import java.net.MalformedURLException;
  12. import java.net.URL;
  13. import java.util.*;
  14. import java.security.AccessController;
  15. import java.security.CodeSource;
  16. import java.security.Identity;
  17. import java.security.IdentityScope;
  18. import java.security.KeyStore;
  19. import java.security.KeyStoreException;
  20. import java.security.Permission;
  21. import java.security.Permissions;
  22. import java.security.PermissionCollection;
  23. import java.security.Principal;
  24. import java.security.UnresolvedPermission;
  25. import java.security.Security;
  26. import java.security.cert.Certificate;
  27. import java.security.cert.X509Certificate;
  28. import javax.security.auth.Subject;
  29. import javax.security.auth.PrivateCredentialPermission;
  30. import sun.security.util.PropertyExpander;
  31. /**
  32. * This class represents a default implementation for
  33. * <code>javax.security.auth.Policy</code>.
  34. *
  35. * <p> This object stores the policy for entire Java runtime,
  36. * and is the amalgamation of multiple static policy
  37. * configurations that resides in files.
  38. * The algorithm for locating the policy file(s) and reading their
  39. * information into this <code>Policy</code> object is:
  40. *
  41. * <ol>
  42. * <li>
  43. * Loop through the <code>java.security.Security</code> properties,
  44. * <i>auth.policy.url.1</i>, <i>auth.policy.url.2</i>, ...,
  45. * <i>auth.policy.url.X</i>". These properties are set
  46. * in the Java security properties file, which is located in the file named
  47. * <JAVA_HOME>/lib/security/java.security, where <JAVA_HOME>
  48. * refers to the directory where the JDK was installed.
  49. * Each property value specifies a <code>URL</code> pointing to a
  50. * policy file to be loaded. Read in and load each policy.
  51. *
  52. * <li>
  53. * The <code>java.lang.System</code> property <i>java.security.auth.policy</i>
  54. * may also be set to a <code>URL</code> pointing to another policy file
  55. * (which is the case when a user uses the -D switch at runtime).
  56. * If this property is defined, and its use is allowed by the
  57. * security property file (the Security property,
  58. * <i>policy.allowSystemProperty</i> is set to <i>true</i>),
  59. * also load that policy.
  60. *
  61. * <li>
  62. * If the <i>java.security.auth.policy</i> property is defined using
  63. * "==" (rather than "="), then ignore all other specified
  64. * policies and only load this policy.
  65. * </ol>
  66. *
  67. * Each policy file consists of one or more grant entries, each of
  68. * which consists of a number of permission entries.
  69. *
  70. * <pre>
  71. * grant signedBy "<b>alias</b>", codeBase "<b>URL</b>",
  72. * principal <b>principalClass</b> "<b>principalName</b>",
  73. * principal <b>principalClass</b> "<b>principalName</b>",
  74. * ... {
  75. *
  76. * permission <b>Type</b> "<b>name</b> "<b>action</b>",
  77. * signedBy "<b>alias</b>";
  78. * permission <b>Type</b> "<b>name</b> "<b>action</b>",
  79. * signedBy "<b>alias</b>";
  80. * ....
  81. * };
  82. * </pre>
  83. *
  84. * All non-bold items above must appear as is (although case
  85. * doesn't matter and some are optional, as noted below).
  86. * Italicized items represent variable values.
  87. *
  88. * <p> A grant entry must begin with the word <code>grant</code>.
  89. * The <code>signedBy</code> and <code>codeBase</code>
  90. * name/value pairs are optional.
  91. * If they are not present, then any signer (including unsigned code)
  92. * will match, and any codeBase will match. Note that the
  93. * <code>principal</code> name/value pair is not optional.
  94. * This <code>Policy</code> implementation only permits
  95. * Principal-based grant entries. Note that the <i>principalClass</i>
  96. * may be set to the wildcard value, *, which allows it to match
  97. * any <code>Principal</code> class. In addition, the <i>principalName</i>
  98. * may also be set to the wildcard value, *, allowing it to match
  99. * any <code>Principal</code> name. When setting the <i>principalName</i>
  100. * to the *, do not surround the * with quotes.
  101. *
  102. * <p> A permission entry must begin with the word <code>permission</code>.
  103. * The word <code><i>Type</i></code> in the template above is
  104. * a specific permission type, such as <code>java.io.FilePermission</code>
  105. * or <code>java.lang.RuntimePermission</code>.
  106. *
  107. * <p> The "<i>action</i>" is required for
  108. * many permission types, such as <code>java.io.FilePermission</code>
  109. * (where it specifies what type of file access that is permitted).
  110. * It is not required for categories such as
  111. * <code>java.lang.RuntimePermission</code>
  112. * where it is not necessary - you either have the
  113. * permission specified by the <code>"<i>name</i>"</code>
  114. * value following the type name or you don't.
  115. *
  116. * <p> The <code>signedBy</code> name/value pair for a permission entry
  117. * is optional. If present, it indicates a signed permission. That is,
  118. * the permission class itself must be signed by the given alias in
  119. * order for it to be granted. For example,
  120. * suppose you have the following grant entry:
  121. *
  122. * <pre>
  123. * grant principal foo.com.Principal "Duke" {
  124. * permission Foo "foobar", signedBy "FooSoft";
  125. * }
  126. * </pre>
  127. *
  128. * <p> Then this permission of type <i>Foo</i> is granted if the
  129. * <code>Foo.class</code> permission has been signed by the
  130. * "FooSoft" alias, or if <code>Foo.class</code> is a
  131. * system class (i.e., is found on the CLASSPATH).
  132. *
  133. * <p> Items that appear in an entry must appear in the specified order
  134. * (<code>permission</code>, <i>Type</i>, "<i>name</i>", and
  135. * "<i>action</i>"). An entry is terminated with a semicolon.
  136. *
  137. * <p> Case is unimportant for the identifiers (<code>permission</code>,
  138. * <code>signedBy</code>, <code>codeBase</code>, etc.) but is
  139. * significant for the <i>Type</i>
  140. * or for any string that is passed in as a value. <p>
  141. *
  142. * <p> An example of two entries in a policy configuration file is
  143. * <pre>
  144. * // if the code is comes from "foo.com" and is running as "Duke",
  145. * // grant it read/write to all files in /tmp.
  146. *
  147. * grant codeBase "foo.com", principal foo.com.Principal "Duke" {
  148. * permission java.io.FilePermission "/tmp/*", "read,write";
  149. * };
  150. *
  151. * // grant any code running as "Duke" permission to read
  152. * // the "java.vendor" Property.
  153. *
  154. * grant principal foo.com.Principal "Duke" {
  155. * permission java.util.PropertyPermission "java.vendor";
  156. * </pre>
  157. *
  158. * <p> This <code>Policy</code> implementation supports
  159. * special handling for PrivateCredentialPermissions.
  160. * If a grant entry is configured with a
  161. * <code>PrivateCredentialPermission</code>,
  162. * and the "Principal Class/Principal Name" for that
  163. * <code>PrivateCredentialPermission</code> is "self",
  164. * then the entry grants the specified <code>Subject</code> permission to
  165. * access its own private Credential. For example,
  166. * the following grants the <code>Subject</code> "Duke"
  167. * access to its own a.b.Credential.
  168. *
  169. * <pre>
  170. * grant principal foo.com.Principal "Duke" {
  171. * permission javax.security.auth.PrivateCredentialPermission
  172. * "a.b.Credential self",
  173. * "read";
  174. * };
  175. * </pre>
  176. *
  177. * The following grants the <code>Subject</code> "Duke"
  178. * access to all of its own private Credentials:
  179. *
  180. * <pre>
  181. * grant principal foo.com.Principal "Duke" {
  182. * permission javax.security.auth.PrivateCredentialPermission
  183. * "* self",
  184. * "read";
  185. * };
  186. * </pre>
  187. *
  188. * The following grants all Subjects authenticated as a
  189. * <code>SolarisPrincipal</code> (regardless of their respective names)
  190. * permission to access their own private Credentials:
  191. *
  192. * <pre>
  193. * grant principal com.sun.security.auth.SolarisPrincipal * {
  194. * permission javax.security.auth.PrivateCredentialPermission
  195. * "* self",
  196. * "read";
  197. * };
  198. * </pre>
  199. *
  200. * The following grants all Subjects permission to access their own
  201. * private Credentials:
  202. *
  203. * <pre>
  204. * grant principal * * {
  205. * permission javax.security.auth.PrivateCredentialPermission
  206. * "* self",
  207. * "read";
  208. * };
  209. * </pre>
  210. * @deprecated As of JDK 1.4, replaced by
  211. * {@link sun.security.provider.PolicyFile}.
  212. * This class is entirely deprecated.
  213. *
  214. * @version 1.22, 01/25/00
  215. * @see java.security.CodeSource
  216. * @see java.security.Permissions
  217. * @see java.security.ProtectionDomain
  218. */
  219. public class PolicyFile extends javax.security.auth.Policy {
  220. static final java.util.ResourceBundle rb =
  221. (java.util.ResourceBundle)java.security.AccessController.doPrivileged
  222. (new java.security.PrivilegedAction() {
  223. public Object run() {
  224. return (java.util.ResourceBundle.getBundle
  225. ("sun.security.util.AuthResources"));
  226. }
  227. });
  228. // needs to be package private
  229. private static final sun.security.util.Debug debug =
  230. sun.security.util.Debug.getInstance("policy", "\t[Auth Policy]");
  231. private static final String AUTH_POLICY = "java.security.auth.policy";
  232. private static final String SECURITY_MANAGER = "java.security.manager";
  233. private static final String AUTH_POLICY_URL = "auth.policy.url.";
  234. private Vector policyEntries;
  235. private Hashtable aliasMapping;
  236. private boolean initialized = false;
  237. private boolean expandProperties = true;
  238. private boolean ignoreIdentityScope = false;
  239. // for use with the reflection API
  240. private static final Class[] PARAMS = { String.class, String.class};
  241. /**
  242. * Initializes the Policy object and reads the default policy
  243. * configuration file(s) into the Policy object.
  244. */
  245. public PolicyFile() {
  246. // initialize Policy if either the AUTH_POLICY or
  247. // SECURITY_MANAGER properties are set
  248. String prop = System.getProperty(AUTH_POLICY);
  249. if (prop == null) {
  250. prop = System.getProperty(SECURITY_MANAGER);
  251. }
  252. if (prop != null)
  253. init();
  254. }
  255. private synchronized void init() {
  256. if (initialized)
  257. return;
  258. policyEntries = new Vector();
  259. aliasMapping = new Hashtable(11);
  260. initPolicyFile();
  261. initialized = true;
  262. }
  263. /**
  264. * Refreshes the policy object by re-reading all the policy files.
  265. *
  266. * <p>
  267. *
  268. * @exception SecurityException if the caller doesn't have permission
  269. * to refresh the <code>Policy</code>.
  270. */
  271. public synchronized void refresh()
  272. {
  273. java.lang.SecurityManager sm = System.getSecurityManager();
  274. if (sm != null) {
  275. sm.checkPermission(new javax.security.auth.AuthPermission
  276. ("refreshPolicy"));
  277. }
  278. // XXX
  279. //
  280. // 1) if code instantiates PolicyFile directly, then it will need
  281. // all the permissions required for the PolicyFile initialization
  282. // 2) if code calls Policy.getPolicy, then it simply needs
  283. // AuthPermission(getPolicy), and the javax.security.auth.Policy
  284. // implementation instantiates PolicyFile in a doPrivileged block
  285. // 3) if after instantiating a Policy (either via #1 or #2),
  286. // code calls refresh, it simply needs
  287. // AuthPermission(refreshPolicy). then PolicyFile wraps
  288. // the refresh in a doPrivileged block.
  289. initialized = false;
  290. java.security.AccessController.doPrivileged
  291. (new java.security.PrivilegedAction() {
  292. public Object run() {
  293. init();
  294. return null;
  295. }
  296. });
  297. }
  298. private KeyStore initKeyStore(URL policyUrl, String keyStoreName,
  299. String keyStoreType) {
  300. if (keyStoreName != null) {
  301. try {
  302. /*
  303. * location of keystore is specified as absolute URL in policy
  304. * file, or is relative to URL of policy file
  305. */
  306. URL keyStoreUrl = null;
  307. try {
  308. keyStoreUrl = new URL(keyStoreName);
  309. // absolute URL
  310. } catch (java.net.MalformedURLException e) {
  311. // relative URL
  312. keyStoreUrl = new URL(policyUrl, keyStoreName);
  313. }
  314. if (debug != null) {
  315. debug.println("reading keystore"+keyStoreUrl);
  316. }
  317. InputStream inStream =
  318. new BufferedInputStream(getInputStream(keyStoreUrl));
  319. KeyStore ks;
  320. if (keyStoreType != null)
  321. ks = KeyStore.getInstance(keyStoreType);
  322. else
  323. ks = KeyStore.getInstance(KeyStore.getDefaultType());
  324. ks.load(inStream, null);
  325. inStream.close();
  326. return ks;
  327. } catch (Exception e) {
  328. // ignore, treat it like we have no keystore
  329. if (debug != null) {
  330. e.printStackTrace();
  331. }
  332. return null;
  333. }
  334. }
  335. return null;
  336. }
  337. private void initPolicyFile() {
  338. String prop = Security.getProperty("policy.expandProperties");
  339. if (prop != null) expandProperties = prop.equalsIgnoreCase("true");
  340. String iscp = Security.getProperty("policy.ignoreIdentityScope");
  341. if (iscp != null) ignoreIdentityScope = iscp.equalsIgnoreCase("true");
  342. String allowSys = Security.getProperty("policy.allowSystemProperty");
  343. if ((allowSys!=null) && allowSys.equalsIgnoreCase("true")) {
  344. String extra_policy = System.getProperty(AUTH_POLICY);
  345. if (extra_policy != null) {
  346. boolean overrideAll = false;
  347. if (extra_policy.startsWith("=")) {
  348. overrideAll = true;
  349. extra_policy = extra_policy.substring(1);
  350. }
  351. try {
  352. extra_policy = PropertyExpander.expand(extra_policy);
  353. URL policyURL;;
  354. File policyFile = new File(extra_policy);
  355. if (policyFile.exists()) {
  356. policyURL =
  357. new URL("file:" + policyFile.getCanonicalPath());
  358. } else {
  359. policyURL = new URL(extra_policy);
  360. }
  361. if (debug != null)
  362. debug.println("reading "+policyURL);
  363. init(policyURL);
  364. } catch (Exception e) {
  365. // ignore.
  366. if (debug != null) {
  367. debug.println("caught exception: "+e);
  368. }
  369. }
  370. if (overrideAll) {
  371. if (debug != null) {
  372. debug.println("overriding other policies!");
  373. }
  374. return;
  375. }
  376. }
  377. }
  378. int n = 1;
  379. boolean loaded_one = false;
  380. String policy_url;
  381. while ((policy_url = Security.getProperty(AUTH_POLICY_URL+n)) != null) {
  382. try {
  383. policy_url = PropertyExpander.expand(policy_url).replace
  384. (File.separatorChar, '/');
  385. if (debug != null)
  386. debug.println("reading "+policy_url);
  387. init(new URL(policy_url));
  388. loaded_one = true;
  389. } catch (Exception e) {
  390. if (debug != null) {
  391. debug.println("error reading policy "+e);
  392. e.printStackTrace();
  393. }
  394. // ignore that policy
  395. }
  396. n++;
  397. }
  398. if (loaded_one == false) {
  399. // do not load a static policy
  400. }
  401. }
  402. /** the scope to check */
  403. private static IdentityScope scope = null;
  404. /**
  405. * Checks public key. If it is marked as trusted in
  406. * the identity database, add it to the policy
  407. * with the AllPermission.
  408. */
  409. private boolean checkForTrustedIdentity(final Certificate cert) {
  410. // XXX JAAS has no way to access the SUN package.
  411. // we'll add this back in when JAAS goes into core.
  412. return false;
  413. }
  414. /**
  415. * Reads a policy configuration into the Policy object using a
  416. * Reader object.
  417. *
  418. * @param policyFile the policy Reader object.
  419. */
  420. private void init(URL policy) {
  421. PolicyParser pp = new PolicyParser(expandProperties);
  422. try {
  423. InputStreamReader isr
  424. = new InputStreamReader(getInputStream(policy));
  425. pp.read(isr);
  426. isr.close();
  427. KeyStore keyStore = initKeyStore(policy, pp.getKeyStoreUrl(),
  428. pp.getKeyStoreType());
  429. Enumeration enum = pp.grantElements();
  430. while (enum.hasMoreElements()) {
  431. PolicyParser.GrantEntry ge =
  432. (PolicyParser.GrantEntry) enum.nextElement();
  433. addGrantEntry(ge, keyStore);
  434. }
  435. } catch (PolicyParser.ParsingException pe) {
  436. System.err.println(AUTH_POLICY +
  437. rb.getString(": error parsing ") + policy);
  438. System.err.println(AUTH_POLICY +
  439. rb.getString(": ") +
  440. pe.getMessage());
  441. if (debug != null)
  442. pe.printStackTrace();
  443. } catch (Exception e) {
  444. if (debug != null) {
  445. debug.println("error parsing "+policy);
  446. debug.println(e.toString());
  447. e.printStackTrace();
  448. }
  449. }
  450. }
  451. /*
  452. * Fast path reading from file urls in order to avoid calling
  453. * FileURLConnection.connect() which can be quite slow the first time
  454. * it is called. We really should clean up FileURLConnection so that
  455. * this is not a problem but in the meantime this fix helps reduce
  456. * start up time noticeably for the new launcher. -- DAC
  457. */
  458. private InputStream getInputStream(URL url) throws IOException {
  459. if ("file".equals(url.getProtocol())) {
  460. String path = url.getFile().replace('/', File.separatorChar);
  461. return new FileInputStream(path);
  462. } else {
  463. return url.openStream();
  464. }
  465. }
  466. /**
  467. * Given a PermissionEntry, create a codeSource.
  468. *
  469. * @return null if signedBy alias is not recognized
  470. */
  471. CodeSource getCodeSource(PolicyParser.GrantEntry ge, KeyStore keyStore)
  472. throws java.net.MalformedURLException
  473. {
  474. Certificate[] certs = null;
  475. if (ge.signedBy != null) {
  476. certs = getCertificates(keyStore, ge.signedBy);
  477. if (certs == null) {
  478. // we don't have a key for this alias,
  479. // just return
  480. if (debug != null) {
  481. debug.println(" no certs for alias " +
  482. ge.signedBy + ", ignoring.");
  483. }
  484. return null;
  485. }
  486. }
  487. URL location;
  488. if (ge.codeBase != null)
  489. location = new URL(ge.codeBase);
  490. else
  491. location = null;
  492. if (ge.principals == null || ge.principals.size() == 0) {
  493. return (canonicalizeCodebase
  494. (new CodeSource(location, certs),
  495. false));
  496. } else {
  497. return (canonicalizeCodebase
  498. (new SubjectCodeSource(null, ge.principals, location, certs),
  499. false));
  500. }
  501. }
  502. /**
  503. * Add one policy entry to the vector.
  504. */
  505. private void addGrantEntry(PolicyParser.GrantEntry ge,
  506. KeyStore keyStore) {
  507. if (debug != null) {
  508. debug.println("Adding policy entry: ");
  509. debug.println(" signedBy " + ge.signedBy);
  510. debug.println(" codeBase " + ge.codeBase);
  511. if (ge.principals != null && ge.principals.size() > 0) {
  512. ListIterator li = ge.principals.listIterator();
  513. while (li.hasNext()) {
  514. PolicyParser.PrincipalEntry pppe =
  515. (PolicyParser.PrincipalEntry)li.next();
  516. debug.println(" " + pppe.principalClass +
  517. " " + pppe.principalName);
  518. }
  519. }
  520. debug.println();
  521. }
  522. try {
  523. CodeSource codesource = getCodeSource(ge, keyStore);
  524. // skip if signedBy alias was unknown...
  525. if (codesource == null) return;
  526. PolicyEntry entry = new PolicyEntry(codesource);
  527. Enumeration enum = ge.permissionElements();
  528. while (enum.hasMoreElements()) {
  529. PolicyParser.PermissionEntry pe =
  530. (PolicyParser.PermissionEntry) enum.nextElement();
  531. try {
  532. // XXX special case PrivateCredentialPermission-SELF
  533. Permission perm;
  534. if (pe.permission.equals
  535. ("javax.security.auth.PrivateCredentialPermission") &&
  536. pe.name.endsWith(" self")) {
  537. perm = getInstance(pe.permission,
  538. pe.name + " \"self\"",
  539. pe.action);
  540. } else {
  541. perm = getInstance(pe.permission,
  542. pe.name,
  543. pe.action);
  544. }
  545. entry.add(perm);
  546. if (debug != null) {
  547. debug.println(" "+perm);
  548. }
  549. } catch (ClassNotFoundException cnfe) {
  550. Certificate certs[];
  551. if (pe.signedBy != null)
  552. certs = getCertificates(keyStore, pe.signedBy);
  553. else
  554. certs = null;
  555. // only add if we had no signer or we had a
  556. // a signer and found the keys for it.
  557. if (certs != null || pe.signedBy == null) {
  558. Permission perm = new UnresolvedPermission(
  559. pe.permission,
  560. pe.name,
  561. pe.action,
  562. certs);
  563. entry.add(perm);
  564. if (debug != null) {
  565. debug.println(" "+perm);
  566. }
  567. }
  568. } catch (java.lang.reflect.InvocationTargetException ite) {
  569. System.err.println
  570. (AUTH_POLICY +
  571. rb.getString(": error adding Permission ") +
  572. pe.permission +
  573. rb.getString(" ") +
  574. ite.getTargetException());
  575. } catch (Exception e) {
  576. System.err.println
  577. (AUTH_POLICY +
  578. rb.getString(": error adding Permission ") +
  579. pe.permission +
  580. rb.getString(" ") +
  581. e);
  582. }
  583. }
  584. policyEntries.addElement(entry);
  585. } catch (Exception e) {
  586. System.err.println
  587. (AUTH_POLICY +
  588. rb.getString(": error adding Entry ") +
  589. ge +
  590. rb.getString(" ") +
  591. e);
  592. }
  593. if (debug != null)
  594. debug.println();
  595. }
  596. /**
  597. * Returns a new Permission object of the given Type. The Permission is
  598. * created by getting the
  599. * Class object using the <code>Class.forName</code> method, and using
  600. * the reflection API to invoke the (String name, String actions)
  601. * constructor on the
  602. * object.
  603. *
  604. * @param type the type of Permission being created.
  605. * @param name the name of the Permission being created.
  606. * @param actions the actions of the Permission being created.
  607. *
  608. * @exception ClassNotFoundException if the particular Permission
  609. * class could not be found.
  610. *
  611. * @exception IllegalAccessException if the class or initializer is
  612. * not accessible.
  613. *
  614. * @exception InstantiationException if getInstance tries to
  615. * instantiate an abstract class or an interface, or if the
  616. * instantiation fails for some other reason.
  617. *
  618. * @exception NoSuchMethodException if the (String, String) constructor
  619. * is not found.
  620. *
  621. * @exception InvocationTargetException if the underlying Permission
  622. * constructor throws an exception.
  623. *
  624. */
  625. private static final Permission getInstance(String type,
  626. String name,
  627. String actions)
  628. throws ClassNotFoundException,
  629. InstantiationException,
  630. IllegalAccessException,
  631. NoSuchMethodException,
  632. InvocationTargetException
  633. {
  634. //XXX we might want to keep a hash of created factories...
  635. Class pc = Class.forName(type);
  636. Constructor c = pc.getConstructor(PARAMS);
  637. return (Permission) c.newInstance(new Object[] { name, actions });
  638. }
  639. /**
  640. * Fetch all certs associated with this alias.
  641. */
  642. Certificate[] getCertificates(
  643. KeyStore keyStore, String aliases) {
  644. Vector vcerts = null;
  645. StringTokenizer st = new StringTokenizer(aliases, ",");
  646. int n = 0;
  647. while (st.hasMoreTokens()) {
  648. String alias = st.nextToken().trim();
  649. n++;
  650. Certificate cert = null;
  651. //See if this alias's cert has already been cached
  652. cert = (Certificate) aliasMapping.get(alias);
  653. if (cert == null && keyStore != null) {
  654. try {
  655. cert = keyStore.getCertificate(alias);
  656. } catch (KeyStoreException kse) {
  657. // never happens, because keystore has already been loaded
  658. // when we call this
  659. }
  660. if (cert != null) {
  661. aliasMapping.put(alias, cert);
  662. aliasMapping.put(cert, alias);
  663. }
  664. }
  665. if (cert != null) {
  666. if (vcerts == null)
  667. vcerts = new Vector();
  668. vcerts.addElement(cert);
  669. }
  670. }
  671. // make sure n == vcerts.size, since we are doing a logical *and*
  672. if (vcerts != null && n == vcerts.size()) {
  673. Certificate[] certs = new Certificate[vcerts.size()];
  674. vcerts.copyInto(certs);
  675. return certs;
  676. } else {
  677. return null;
  678. }
  679. }
  680. /**
  681. * Enumerate all the entries in the global policy object.
  682. * This method is used by policy admin tools. The tools
  683. * should use the Enumeration methods on the returned object
  684. * to fetch the elements sequentially.
  685. */
  686. private final synchronized Enumeration elements(){
  687. return policyEntries.elements();
  688. }
  689. /**
  690. * Examines this <code>Policy</code> and returns the Permissions granted
  691. * to the specified <code>Subject</code> and <code>CodeSource</code>.
  692. *
  693. * <p> Permissions for a particular <i>grant</i> entry are returned
  694. * if the <code>CodeSource</code> constructed using the codebase and
  695. * signedby values specified in the entry <code>implies</code>
  696. * the <code>CodeSource</code> provided to this method, and if the
  697. * <code>Subject</code> provided to this method contains all of the
  698. * Principals specified in the entry.
  699. *
  700. * <p> The <code>Subject</code> provided to this method contains all
  701. * of the Principals specified in the entry if, for each
  702. * <code>Principal</code>, "P1", specified in the <i>grant</i> entry
  703. * one of the following two conditions is met:
  704. *
  705. * <p>
  706. * <ol>
  707. * <li> the <code>Subject</code> has a
  708. * <code>Principal</code>, "P2", where
  709. * <code>P2.getClass().getName()</code> equals the
  710. * P1's class name, and where
  711. * <code>P2.getName()</code> equals the P1's name.
  712. *
  713. * <li> P1 implements
  714. * <code>com.sun.security.auth.PrincipalComparator</code>,
  715. * and <code>P1.implies</code> the provided <code>Subject</code>.
  716. * </ol>
  717. *
  718. * <p> Note that this <code>Policy</code> implementation has
  719. * special handling for PrivateCredentialPermissions.
  720. * When this method encounters a <code>PrivateCredentialPermission</code>
  721. * which specifies "self" as the <code>Principal</code> class and name,
  722. * it does not add that <code>Permission</code> to the returned
  723. * <code>PermissionCollection</code>. Instead, it builds
  724. * a new <code>PrivateCredentialPermission</code>
  725. * for each <code>Principal</code> associated with the provided
  726. * <code>Subject</code>. Each new <code>PrivateCredentialPermission</code>
  727. * contains the same Credential class as specified in the
  728. * originally granted permission, as well as the Class and name
  729. * for the respective <code>Principal</code>.
  730. *
  731. * <p>
  732. *
  733. * @param subject the Permissions granted to this <code>Subject</code>
  734. * and the additionally provided <code>CodeSource</code>
  735. * are returned. <p>
  736. *
  737. * @param codesource the Permissions granted to this <code>CodeSource</code>
  738. * and the additionally provided <code>Subject</code>
  739. * are returned.
  740. *
  741. * @return the Permissions granted to the provided <code>Subject</code>
  742. * <code>CodeSource</code>.
  743. */
  744. public PermissionCollection getPermissions(final Subject subject,
  745. final CodeSource codesource) {
  746. // XXX when JAAS goes into the JDK core,
  747. // we can remove this method and simply
  748. // rely on the getPermissions variant that takes a codesource,
  749. // which no one can use at this point in time.
  750. // at that time, we can also make SubjectCodeSource a public
  751. // class.
  752. // XXX
  753. //
  754. // 1) if code instantiates PolicyFile directly, then it will need
  755. // all the permissions required for the PolicyFile initialization
  756. // 2) if code calls Policy.getPolicy, then it simply needs
  757. // AuthPermission(getPolicy), and the javax.security.auth.Policy
  758. // implementation instantiates PolicyFile in a doPrivileged block
  759. // 3) if after instantiating a Policy (either via #1 or #2),
  760. // code calls getPermissions, PolicyFile wraps the call
  761. // in a doPrivileged block.
  762. return (PermissionCollection)java.security.AccessController.doPrivileged
  763. (new java.security.PrivilegedAction() {
  764. public Object run() {
  765. SubjectCodeSource scs = new SubjectCodeSource
  766. (subject,
  767. null,
  768. codesource == null ? null : codesource.getLocation(),
  769. codesource == null ? null : codesource.getCertificates());
  770. if (initialized)
  771. return getPermissions(new Permissions(), scs);
  772. else
  773. return new PolicyPermissions(PolicyFile.this, scs);
  774. }
  775. });
  776. }
  777. /**
  778. * Examines the global policy for the specified CodeSource, and
  779. * creates a PermissionCollection object with
  780. * the set of permissions for that principal's protection domain.
  781. *
  782. * @param CodeSource the codesource associated with the caller.
  783. * This encapsulates the original location of the code (where the code
  784. * came from) and the public key(s) of its signer.
  785. *
  786. * @return the set of permissions according to the policy.
  787. */
  788. PermissionCollection getPermissions(CodeSource codesource) {
  789. if (initialized)
  790. return getPermissions(new Permissions(), codesource);
  791. else
  792. return new PolicyPermissions(this, codesource);
  793. }
  794. /**
  795. * Examines the global policy for the specified CodeSource, and
  796. * creates a PermissionCollection object with
  797. * the set of permissions for that principal's protection domain.
  798. *
  799. * @param permissions the permissions to populate
  800. * @param codesource the codesource associated with the caller.
  801. * This encapsulates the original location of the code (where the code
  802. * came from) and the public key(s) of its signer.
  803. *
  804. * @return the set of permissions according to the policy.
  805. */
  806. Permissions getPermissions(final Permissions perms,
  807. final CodeSource cs)
  808. {
  809. if (!initialized) {
  810. init();
  811. }
  812. final CodeSource codesource[] = {null};
  813. codesource[0] = canonicalizeCodebase(cs, true);
  814. if (debug != null) {
  815. debug.println("evaluate("+codesource[0]+")\n");
  816. }
  817. // needs to be in a begin/endPrivileged block because
  818. // codesource.implies calls URL.equals which does an
  819. // InetAddress lookup
  820. for (int i = 0; i < policyEntries.size(); i++) {
  821. PolicyEntry entry = (PolicyEntry)policyEntries.elementAt(i);
  822. if (debug != null) {
  823. debug.println("PolicyFile CodeSource implies: " +
  824. entry.codesource.toString() + "\n\n" +
  825. "\t" + codesource[0].toString() + "\n\n");
  826. }
  827. if (entry.codesource.implies(codesource[0])) {
  828. for (int j = 0; j < entry.permissions.size(); j++) {
  829. Permission p =
  830. (Permission) entry.permissions.elementAt(j);
  831. if (debug != null) {
  832. debug.println(" granting " + p);
  833. }
  834. if (!addSelfPermissions(p, entry.codesource,
  835. codesource[0], perms)) {
  836. // we could check for duplicates
  837. // before adding new permissions,
  838. // but the SubjectDomainCombiner
  839. // already checks for duplicates later
  840. perms.add(p);
  841. }
  842. }
  843. }
  844. }
  845. // now see if any of the keys are trusted ids.
  846. if (!ignoreIdentityScope) {
  847. Certificate certs[] = codesource[0].getCertificates();
  848. if (certs != null) {
  849. for (int k=0; k < certs.length; k++) {
  850. if ((aliasMapping.get(certs[k]) == null) &&
  851. checkForTrustedIdentity(certs[k])) {
  852. // checkForTrustedIdentity added it
  853. // to the policy for us. next time
  854. // around we'll find it. This time
  855. // around we need to add it.
  856. perms.add(new java.security.AllPermission());
  857. }
  858. }
  859. }
  860. }
  861. return perms;
  862. }
  863. /**
  864. * Returns true if 'Self' permissions were added to the provided
  865. * 'perms', and false otherwise.
  866. *
  867. * <p>
  868. *
  869. * @param p check to see if this Permission is a "SELF"
  870. * PrivateCredentialPermission. <p>
  871. *
  872. * @param entryCs the codesource for the Policy entry.
  873. *
  874. * @param accCs the codesource for from the current AccessControlContext.
  875. *
  876. * @param perms the PermissionCollection where the individual
  877. * PrivateCredentialPermissions will be added.
  878. */
  879. private boolean addSelfPermissions(final Permission p,
  880. CodeSource entryCs,
  881. CodeSource accCs,
  882. Permissions perms) {
  883. if (!(p instanceof PrivateCredentialPermission))
  884. return false;
  885. if (!(entryCs instanceof SubjectCodeSource))
  886. return false;
  887. PrivateCredentialPermission pcp = (PrivateCredentialPermission)p;
  888. SubjectCodeSource scs = (SubjectCodeSource)entryCs;
  889. // see if it is a SELF permission
  890. String[][] pPrincipals = pcp.getPrincipals();
  891. if (pPrincipals.length <= 0 ||
  892. !pPrincipals[0][0].equalsIgnoreCase("self") ||
  893. !pPrincipals[0][1].equalsIgnoreCase("self")) {
  894. // regular PrivateCredentialPermission
  895. return false;
  896. } else {
  897. // granted a SELF permission - create a
  898. // PrivateCredentialPermission for each
  899. // of the Policy entry's CodeSource Principals
  900. if (scs.getPrincipals() == null) {
  901. // XXX SubjectCodeSource has no Subject???
  902. return true;
  903. }
  904. ListIterator pli = scs.getPrincipals().listIterator();
  905. while (pli.hasNext()) {
  906. PolicyParser.PrincipalEntry principal =
  907. (PolicyParser.PrincipalEntry)pli.next();
  908. // XXX
  909. // if the Policy entry's Principal does not contain a
  910. // WILDCARD for the Principal name, then a
  911. // new PrivateCredentialPermission is created
  912. // for the Principal listed in the Policy entry.
  913. // if the Policy entry's Principal contains a WILDCARD
  914. // for the Principal name, then a new
  915. // PrivateCredentialPermission is created
  916. // for each Principal associated with the Subject
  917. // in the current ACC.
  918. String[][] principalInfo = getPrincipalInfo
  919. (principal, accCs);
  920. for (int i = 0; i < principalInfo.length; i++) {
  921. // here's the new PrivateCredentialPermission
  922. PrivateCredentialPermission newPcp =
  923. new PrivateCredentialPermission
  924. (pcp.getCredentialClass() +
  925. " " +
  926. principalInfo[i][0] +
  927. " " +
  928. "\"" + principalInfo[i][1] + "\"",
  929. "read");
  930. if (debug != null) {
  931. debug.println("adding SELF permission: " +
  932. newPcp.toString());
  933. }
  934. perms.add(newPcp);
  935. }
  936. }
  937. }
  938. return true;
  939. }
  940. /**
  941. * return the principal class/name pair in the 2D array.
  942. * array[x][y]: x corresponds to the array length.
  943. * if (y == 0), it's the principal class.
  944. * if (y == 1), it's the principal name.
  945. */
  946. private String[][] getPrincipalInfo
  947. (PolicyParser.PrincipalEntry principal,
  948. final CodeSource accCs) {
  949. // there are 3 possibilities:
  950. // 1) the entry's Principal class and name are not wildcarded
  951. // 2) the entry's Principal name is wildcarded only
  952. // 3) the entry's Principal class and name are wildcarded
  953. if (!principal.principalClass.equals
  954. (PolicyParser.PrincipalEntry.WILDCARD_CLASS) &&
  955. !principal.principalName.equals
  956. (PolicyParser.PrincipalEntry.WILDCARD_NAME)) {
  957. // build a PrivateCredentialPermission for the principal
  958. // from the Policy entry
  959. String[][] info = new String[1][2];
  960. info[0][0] = principal.principalClass;
  961. info[0][1] = principal.principalName;
  962. return info;
  963. } else if (!principal.principalClass.equals
  964. (PolicyParser.PrincipalEntry.WILDCARD_CLASS) &&
  965. principal.principalName.equals
  966. (PolicyParser.PrincipalEntry.WILDCARD_NAME)) {
  967. // build a PrivateCredentialPermission for all
  968. // the Subject's principals that are instances of principalClass
  969. // the accCs is guaranteed to be a SubjectCodeSource
  970. // because the earlier CodeSource.implies succeeded
  971. SubjectCodeSource scs = (SubjectCodeSource)accCs;
  972. Set principalSet = null;
  973. try {
  974. Class pClass = Class.forName(principal.principalClass, false,
  975. ClassLoader.getSystemClassLoader());
  976. principalSet = scs.getSubject().getPrincipals(pClass);
  977. } catch (Exception e) {
  978. if (debug != null) {
  979. debug.println("problem finding Principal Class " +
  980. "when expanding SELF permission: " +
  981. e.toString());
  982. }
  983. }
  984. if (principalSet == null) {
  985. // error
  986. return new String[0][0];
  987. }
  988. String[][] info = new String[principalSet.size()][2];
  989. java.util.Iterator pIterator = principalSet.iterator();
  990. int i = 0;
  991. while (pIterator.hasNext()) {
  992. Principal p = (Principal)pIterator.next();
  993. info[i][0] = p.getClass().getName();
  994. info[i][1] = p.getName();
  995. i++;
  996. }
  997. return info;
  998. } else {
  999. // build a PrivateCredentialPermission for every
  1000. // one of the current Subject's principals
  1001. // the accCs is guaranteed to be a SubjectCodeSource
  1002. // because the earlier CodeSource.implies succeeded
  1003. SubjectCodeSource scs = (SubjectCodeSource)accCs;
  1004. Set principalSet = scs.getSubject().getPrincipals();
  1005. String[][] info = new String[principalSet.size()][2];
  1006. java.util.Iterator pIterator = principalSet.iterator();
  1007. int i = 0;
  1008. while (pIterator.hasNext()) {
  1009. Principal p = (Principal)pIterator.next();
  1010. info[i][0] = p.getClass().getName();
  1011. info[i][1] = p.getName();
  1012. i++;
  1013. }
  1014. return info;
  1015. }
  1016. }
  1017. /*
  1018. * Returns the signer certificates from the list of certificates associated
  1019. * with the given code source.
  1020. *
  1021. * The signer certificates are those certificates that were used to verify
  1022. * signed code originating from the codesource location.
  1023. *
  1024. * This method assumes that in the given code source, each signer
  1025. * certificate is followed by its supporting certificate chain
  1026. * (which may be empty), and that the signer certificate and its
  1027. * supporting certificate chain are ordered bottom-to-top (i.e., with the
  1028. * signer certificate first and the (root) certificate authority last).
  1029. */
  1030. Certificate[] getSignerCertificates(CodeSource cs) {
  1031. Certificate[] certs = null;
  1032. if ((certs = cs.getCertificates()) == null)
  1033. return null;
  1034. for (int i=0; i<certs.length; i++) {
  1035. if (!(certs[i] instanceof X509Certificate))
  1036. return cs.getCertificates();
  1037. }
  1038. // Do we have to do anything?
  1039. int i = 0;
  1040. int count = 0;
  1041. while (i < certs.length) {
  1042. count++;
  1043. while (((i+1) < certs.length)
  1044. && ((X509Certificate)certs[i]).getIssuerDN().equals(
  1045. ((X509Certificate)certs[i+1]).getSubjectDN())) {
  1046. i++;
  1047. }
  1048. i++;
  1049. }
  1050. if (count == certs.length)
  1051. // Done
  1052. return certs;
  1053. ArrayList userCertList = new ArrayList();
  1054. i = 0;
  1055. while (i < certs.length) {
  1056. userCertList.add(certs[i]);
  1057. while (((i+1) < certs.length)
  1058. && ((X509Certificate)certs[i]).getIssuerDN().equals(
  1059. ((X509Certificate)certs[i+1]).getSubjectDN())) {
  1060. i++;
  1061. }
  1062. i++;
  1063. }
  1064. Certificate[] userCerts = new Certificate[userCertList.size()];
  1065. userCertList.toArray(userCerts);
  1066. return userCerts;
  1067. }
  1068. private CodeSource canonicalizeCodebase(CodeSource cs,
  1069. boolean extractSignerCerts) {
  1070. CodeSource canonCs = cs;
  1071. if (cs.getLocation() != null &&
  1072. cs.getLocation().getProtocol().equalsIgnoreCase("file")) {
  1073. try {
  1074. String path = cs.getLocation().getFile().replace
  1075. ('/',
  1076. File.separatorChar);
  1077. URL csUrl = null;
  1078. if (path.endsWith("*")) {
  1079. // remove trailing '*' because it causes canonicalization
  1080. // to fail on win32
  1081. path = path.substring(0, path.length()-1);
  1082. boolean appendFileSep = false;
  1083. if (path.endsWith(File.separator))
  1084. appendFileSep = true;
  1085. if (path.equals("")) {
  1086. path = System.getProperty("user.dir");
  1087. }
  1088. File f = new File(path);
  1089. path = f.getCanonicalPath();
  1090. StringBuffer sb = new StringBuffer(path);
  1091. // reappend '*' to canonicalized filename (note that
  1092. // canonicalization may have removed trailing file
  1093. // separator, so we have to check for that, too)
  1094. if (!path.endsWith(File.separator) &&
  1095. (appendFileSep || f.isDirectory()))
  1096. sb.append(File.separatorChar);
  1097. sb.append('*');
  1098. path = sb.toString();
  1099. } else {
  1100. path = new File(path).getCanonicalPath();
  1101. }
  1102. csUrl = new File(path).toURL();
  1103. if (cs instanceof SubjectCodeSource) {
  1104. SubjectCodeSource scs = (SubjectCodeSource)cs;
  1105. if (extractSignerCerts) {
  1106. canonCs = new SubjectCodeSource
  1107. (scs.getSubject(),
  1108. scs.getPrincipals(),
  1109. csUrl,
  1110. getSignerCertificates(scs));
  1111. } else {
  1112. canonCs = new SubjectCodeSource
  1113. (scs.getSubject(),
  1114. scs.getPrincipals(),
  1115. csUrl,
  1116. scs.getCertificates());
  1117. }
  1118. } else {
  1119. if (extractSignerCerts) {
  1120. canonCs = new CodeSource(csUrl,
  1121. getSignerCertificates(cs));
  1122. } else {
  1123. canonCs = new CodeSource(csUrl,
  1124. cs.getCertificates());
  1125. }
  1126. }
  1127. } catch (IOException ioe) {
  1128. // leave codesource as it is, unless we have to extract its
  1129. // signer certificates
  1130. if (extractSignerCerts) {
  1131. if (!(cs instanceof SubjectCodeSource)) {
  1132. canonCs = new CodeSource(cs.getLocation(),
  1133. getSignerCertificates(cs));
  1134. } else {
  1135. SubjectCodeSource scs = (SubjectCodeSource)cs;
  1136. canonCs = new SubjectCodeSource(scs.getSubject(),
  1137. scs.getPrincipals(),
  1138. scs.getLocation(),
  1139. getSignerCertificates(scs));
  1140. }
  1141. }
  1142. }
  1143. } else {
  1144. if (extractSignerCerts) {
  1145. if (!(cs instanceof SubjectCodeSource)) {
  1146. canonCs = new CodeSource(cs.getLocation(),
  1147. getSignerCertificates(cs));
  1148. } else {
  1149. SubjectCodeSource scs = (SubjectCodeSource)cs;
  1150. canonCs = new SubjectCodeSource(scs.getSubject(),
  1151. scs.getPrincipals(),
  1152. scs.getLocation(),
  1153. getSignerCertificates(scs));
  1154. }
  1155. }
  1156. }
  1157. return canonCs;
  1158. }
  1159. /**
  1160. * Each entry in the policy configuration file is represented by a
  1161. * PolicyEntry object. <p>
  1162. *
  1163. * A PolicyEntry is a (CodeSource,Permission) pair. The
  1164. * CodeSource contains the (URL, PublicKey) that together identify
  1165. * where the Java bytecodes come from and who (if anyone) signed
  1166. * them. The URL could refer to localhost. The URL could also be
  1167. * null, meaning that this policy entry is given to all comers, as
  1168. * long as they match the signer field. The signer could be null,
  1169. * meaning the code is not signed. <p>
  1170. *
  1171. * The Permission contains the (Type, Name, Action) triplet. <p>
  1172. *
  1173. * For now, the Policy object retrieves the public key from the
  1174. * X.509 certificate on disk that corresponds to the signedBy
  1175. * alias specified in the Policy config file. For reasons of
  1176. * efficiency, the Policy object keeps a hashtable of certs already
  1177. * read in. This could be replaced by a secure internal key
  1178. * store.
  1179. *
  1180. * <p>
  1181. * For example, the entry
  1182. * <pre>
  1183. * permission java.io.File "/tmp", "read,write",
  1184. * signedBy "Duke";
  1185. * </pre>
  1186. * is represented internally
  1187. * <pre>
  1188. *
  1189. * FilePermission f = new FilePermission("/tmp", "read,write");
  1190. * PublicKey p = publickeys.get("Duke");
  1191. * URL u = InetAddress.getLocalHost();
  1192. * CodeBase c = new CodeBase( p, u );
  1193. * pe = new PolicyEntry(f, c);
  1194. * </pre>
  1195. *
  1196. * @author Marianne Mueller
  1197. * @author Roland Schemers
  1198. * @version 1.6, 03/04/97
  1199. * @see java.security.CodeSource
  1200. * @see java.security.Policy
  1201. * @see java.security.Permissions
  1202. * @see java.security.ProtectionDomain
  1203. */
  1204. private static class PolicyEntry {
  1205. CodeSource codesource;
  1206. Vector permissions;
  1207. /**
  1208. * Given a Permission and a CodeSource, create a policy entry.
  1209. *
  1210. * XXX Decide if/how to add validity fields and "purpose" fields to
  1211. * XXX policy entries
  1212. *
  1213. * @param cs the CodeSource, which encapsulates the URL and the public
  1214. * key
  1215. * attributes from the policy config file. Validity checks are
  1216. * performed on the public key before PolicyEntry is called.
  1217. *
  1218. */
  1219. PolicyEntry(CodeSource cs)
  1220. {
  1221. this.codesource = cs;
  1222. this.permissions = new Vector();
  1223. }
  1224. /**
  1225. * add a Permission object to this entry.
  1226. */
  1227. void add(Permission p) {
  1228. permissions.addElement(p);
  1229. }
  1230. /**
  1231. * Return the CodeSource for this policy entry
  1232. */
  1233. CodeSource getCodeSource() {
  1234. return this.codesource;
  1235. }
  1236. public String toString(){
  1237. StringBuffer sb = new StringBuffer();
  1238. sb.append(rb.getString("("));
  1239. sb.append(getCodeSource());
  1240. sb.append("\n");
  1241. for (int j = 0; j < permissions.size(); j++) {
  1242. Permission p = (Permission) permissions.elementAt(j);
  1243. sb.append(rb.getString(" "));
  1244. sb.append(rb.getString(" "));
  1245. sb.append(p);
  1246. sb.append(rb.getString("\n"));
  1247. }
  1248. sb.append(rb.getString(")"));
  1249. sb.append(rb.getString("\n"));
  1250. return sb.toString();
  1251. }
  1252. }
  1253. }
  1254. class PolicyPermissions extends PermissionCollection {
  1255. private CodeSource codesource;
  1256. private Permissions perms;
  1257. private PolicyFile policy;
  1258. private boolean notInit; // have we pulled in the policy permissions yet?
  1259. private Vector additionalPerms;
  1260. PolicyPermissions(PolicyFile policy,
  1261. CodeSource codesource)
  1262. {
  1263. this.codesource = codesource;
  1264. this.policy = policy;
  1265. this.perms = null;
  1266. this.notInit = true;
  1267. this.additionalPerms = null;
  1268. }
  1269. public void add(Permission permission) {
  1270. if (isReadOnly())
  1271. throw new SecurityException
  1272. (PolicyFile.rb.getString
  1273. ("attempt to add a Permission to a readonly PermissionCollection"));
  1274. if (perms == null) {
  1275. if (additionalPerms == null)
  1276. additionalPerms = new Vector();
  1277. additionalPerms.add(permission);
  1278. } else {
  1279. perms.add(permission);
  1280. }
  1281. }
  1282. private synchronized void init() {
  1283. if (notInit) {
  1284. if (perms == null)
  1285. perms = new Permissions();
  1286. if (additionalPerms != null) {
  1287. Enumeration e = additionalPerms.elements();
  1288. while (e.hasMoreElements()) {
  1289. perms.add((Permission)e.nextElement());
  1290. }
  1291. additionalPerms = null;
  1292. }
  1293. policy.getPermissions(perms,codesource);
  1294. notInit=false;
  1295. }
  1296. }
  1297. public boolean implies(Permission permission) {
  1298. if (notInit)
  1299. init();
  1300. return perms.implies(permission);
  1301. }
  1302. public Enumeration elements() {
  1303. if (notInit)
  1304. init();
  1305. return perms.elements();
  1306. }
  1307. public String toString() {
  1308. if (notInit)
  1309. init();
  1310. return perms.toString();
  1311. }
  1312. }