IdentityScope.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* IdentityScope.java --- IdentityScope Class
  2. Copyright (C) 1999 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.security;
  32. import java.util.Enumeration;
  33. /**
  34. IdentityScope represents a scope of an identity. IdentityScope
  35. is also an Identity and can have a name and scope along with
  36. the other qualitites identities posses.
  37. An IdentityScope contains other Identity objects. All Identity
  38. objects are manipulated in the scope the same way. The scope
  39. is suppose to apply different scope to different type of
  40. Identities.
  41. No identity within the same scope can have the same public key.
  42. @since JDK 1.1
  43. @deprecated Use java.security.KeyStore, the java.security.cert
  44. package, and java.security.Principal.
  45. @author Mark Benvenuto
  46. */
  47. public abstract class IdentityScope extends Identity
  48. {
  49. private static IdentityScope systemScope = null;
  50. /**
  51. Creates a new instance of IdentityScope from Serialized Data
  52. */
  53. protected IdentityScope()
  54. {
  55. super();
  56. }
  57. /**
  58. Creates a new instance of IdentityScope with the specified name
  59. and no scope.
  60. @param name the name to use
  61. */
  62. public IdentityScope(String name)
  63. {
  64. super(name);
  65. }
  66. /**
  67. Creates a new instance of IdentityScope with the specified name
  68. and IdentityScope.
  69. @param name the name to use
  70. @param scope the scope to use
  71. @throws KeyManagementException if the identity scope is already
  72. present
  73. */
  74. public IdentityScope(String name, IdentityScope scope)
  75. throws KeyManagementException
  76. {
  77. super(name, scope);
  78. }
  79. /**
  80. Gets the system's Scope.
  81. */
  82. public static IdentityScope getSystemScope()
  83. {
  84. if (systemScope == null)
  85. {
  86. //Load it
  87. //systemScope;
  88. }
  89. return systemScope;
  90. }
  91. /**
  92. Sets the scope of the system.
  93. This class checks the security manager with the call
  94. checkSecurityAccess with "setSystemScope".
  95. @param scope the new sustem scope
  96. @throws SecurityException - if the security manager denies
  97. access to "setSystemScope"
  98. */
  99. protected static void setSystemScope(IdentityScope scope)
  100. {
  101. SecurityManager sm = System.getSecurityManager();
  102. if (sm != null)
  103. sm.checkSecurityAccess("setSystemScope");
  104. systemScope = scope;
  105. }
  106. /**
  107. Gets the number of entries within this IdentityScope.
  108. @returns the number of entries
  109. */
  110. public abstract int size();
  111. /**
  112. Gets the specified Identity within this scope
  113. by specified name.
  114. @param name name of Identity to get
  115. @returns an identity representing the name or null if it
  116. cannot be found
  117. */
  118. public abstract Identity getIdentity(String name);
  119. /**
  120. Gets the specified Identity within this scope
  121. by the specified Principal.
  122. @param principal The Principal of the Identity to get
  123. @returns an identity representing the principal or null if it
  124. cannot be found
  125. */
  126. public Identity getIdentity(Principal principal)
  127. {
  128. return getIdentity(principal.getName());
  129. }
  130. /**
  131. Gets the specified Identity within this scope
  132. by the specified public key.
  133. @param key the PublicKey of the Identity to get
  134. @returns an identity representing the public key or null if it
  135. cannot be found
  136. */
  137. public abstract Identity getIdentity(PublicKey key);
  138. /**
  139. Adds an identity to his scope.
  140. @param identity the identity to add
  141. @throws KeyManagementException if it is an invalid identity,
  142. an identity with the same key exists, or another error
  143. occurs.
  144. */
  145. public abstract void addIdentity(Identity identity)
  146. throws KeyManagementException;
  147. /**
  148. Removes an identity to his scope.
  149. @param identity the identity to remove
  150. @throws KeyManagementException if it is a missing identity,
  151. or another error occurs.
  152. */
  153. public abstract void removeIdentity(Identity identity)
  154. throws KeyManagementException;
  155. /**
  156. Returns an Enumeration of identities.
  157. @returns an enumeration of the identities.
  158. */
  159. public abstract Enumeration identities();
  160. /**
  161. Returns a string representing this IdentityScope.
  162. It includes the name, the scope name, and number of identities.
  163. @returns a string representing this IdentityScope.
  164. */
  165. public String toString()
  166. {
  167. return (super.getName() + " " + super.getScope().getName()
  168. + " " + size());
  169. }
  170. }