1. /*
  2. * @(#)ProtectionDomain.java 1.26 00/02/02
  3. *
  4. * Copyright 1997-2000 Sun Microsystems, Inc. All Rights Reserved.
  5. *
  6. * This software is the proprietary information of Sun Microsystems, Inc.
  7. * Use is subject to license terms.
  8. *
  9. */
  10. package java.security;
  11. /**
  12. *
  13. * <p> This ProtectionDomain class encapulates the characteristics of
  14. * a domain, which encloses a set of classes whose instances
  15. * are granted the same set of permissions.
  16. *
  17. * <p>In addition to a set of permissions, a domain is comprised of a
  18. * CodeSource, which is a set of PublicKeys together with a codebase (in
  19. * the form of a URL). Thus, classes signed by the same keys and
  20. * from the same URL are placed in the same domain.
  21. * Classes that have the same permissions but are from different code
  22. * sources belong to different domains.
  23. *
  24. * <p> A class belongs to one and only one ProtectionDomain.
  25. *
  26. * @version 1.26, 02/02/00
  27. * @author Li Gong
  28. * @author Roland Schemers
  29. */
  30. public class ProtectionDomain {
  31. /* CodeSource */
  32. private CodeSource codesource ;
  33. /* the rights this protection domain is granted */
  34. private PermissionCollection permissions;
  35. /**
  36. * Creates a new ProtectionDomain with the given CodeSource and
  37. * Permissions. If the permissions object is not null, then
  38. * <code>setReadOnly()</code> will be called on the passed in
  39. * Permissions object.
  40. *
  41. * @param codesource the codesource associated with this domain
  42. * @param permissions the permissions granted to this domain
  43. */
  44. public ProtectionDomain(CodeSource codesource,
  45. PermissionCollection permissions) {
  46. this.codesource = codesource;
  47. if (permissions != null) {
  48. this.permissions = permissions;
  49. this.permissions.setReadOnly();
  50. }
  51. }
  52. /**
  53. * Returns the CodeSource of this domain.
  54. * @return the CodeSource of this domain.
  55. */
  56. public final CodeSource getCodeSource() {
  57. return this.codesource;
  58. }
  59. /**
  60. * Returns the permissions of this domain.
  61. * @return the permissions of this domain.
  62. */
  63. public final PermissionCollection getPermissions() {
  64. return this.permissions;
  65. }
  66. /**
  67. * Check and see if this ProtectionDomain implies the permissions
  68. * expressed in the Permission object.
  69. *
  70. * @param permission the Permission object to check.
  71. *
  72. * @return true if "permission" is a proper subset of a permission in
  73. * this ProtectionDomain, false if not.
  74. */
  75. public boolean implies(Permission permission) {
  76. if (permissions != null) {
  77. return permissions.implies(permission);
  78. } else {
  79. return false;
  80. }
  81. }
  82. /**
  83. * Convert a ProtectionDomain to a String.
  84. */
  85. public String toString() {
  86. return "ProtectionDomain "+codesource+"\n"+permissions+"\n";
  87. }
  88. }