IdentityScope.java 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /* IdentityScope.java --- IdentityScope Class
  2. Copyright (C) 1999, 2003, 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., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 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. * <code>IdentityScope</code> represents a scope of an identity.
  35. * <code>IdentityScope</code> is also an {@link Identity} and can have a name
  36. * and scope along with the other qualitites identities possess.
  37. *
  38. * <p>An <code>IdentityScope</code> contains other {@link Identity} objects.
  39. * All {@link Identity} objects are manipulated in the scope the same way. The
  40. * scope is supposed to apply different scope to different type of
  41. * Identities.</p>
  42. *
  43. * <p>No identity within the same scope can have the same public key.</p>
  44. *
  45. * @author Mark Benvenuto
  46. * @see Identity
  47. * @see Signer
  48. * @see Principal
  49. * @see Key
  50. * @deprecated Use java.security.KeyStore, the java.security.cert package, and
  51. * java.security.Principal.
  52. */
  53. public abstract class IdentityScope extends Identity
  54. {
  55. private static final long serialVersionUID = -2337346281189773310L;
  56. private static IdentityScope systemScope;
  57. /** Constructor for serialization purposes. */
  58. protected IdentityScope()
  59. {
  60. super();
  61. }
  62. /**
  63. * Constructs a new instance of <code>IdentityScope</code> with the
  64. * specified name and no scope.
  65. *
  66. * @param name
  67. * the name to use.
  68. */
  69. public IdentityScope(String name)
  70. {
  71. super(name);
  72. }
  73. /**
  74. * Constructs a new instance of <code>IdentityScope</code> with the
  75. * specified name and {@link IdentityScope}.
  76. *
  77. * @param name
  78. * the name to use.
  79. * @param scope
  80. * the scope to use.
  81. * @throws KeyManagementException
  82. * if the identity scope is already present.
  83. */
  84. public IdentityScope(String name, IdentityScope scope)
  85. throws KeyManagementException
  86. {
  87. super(name, scope);
  88. }
  89. /**
  90. * Returns the system's Scope.
  91. *
  92. * @return the system's Scope.
  93. */
  94. public static IdentityScope getSystemScope()
  95. {
  96. if (systemScope == null)
  97. {
  98. //Load it
  99. //systemScope;
  100. }
  101. return systemScope;
  102. }
  103. /**
  104. * Sets the scope of the system.
  105. *
  106. * @param scope
  107. * the new system scope.
  108. * @throws SecurityException
  109. * if a {@link SecurityManager} is installed which disallows this
  110. * operation.
  111. */
  112. protected static void setSystemScope(IdentityScope scope)
  113. {
  114. SecurityManager sm = System.getSecurityManager();
  115. if (sm != null)
  116. sm.checkSecurityAccess("setSystemScope");
  117. systemScope = scope;
  118. }
  119. /**
  120. * Returns the number of entries within this <code>IdentityScope</code>.
  121. *
  122. * @return the number of entries within this <code>IdentityScope</code>.
  123. */
  124. public abstract int size();
  125. /**
  126. * Returns the specified {@link Identity}, by name, within this scope.
  127. *
  128. * @param name
  129. * name of {@link Identity} to get.
  130. * @return an {@link Identity} representing the name or <code>null</code> if
  131. * it cannot be found.
  132. */
  133. public abstract Identity getIdentity(String name);
  134. /**
  135. * Returns the specified {@link Identity}, by {@link Principal}, within this
  136. * scope.
  137. *
  138. * @param principal
  139. * the {@link Principal} to use.
  140. * @return an identity representing the {@link Principal} or <code>null</code>
  141. * if it cannot be found.
  142. */
  143. public Identity getIdentity(Principal principal)
  144. {
  145. return getIdentity(principal.getName());
  146. }
  147. /**
  148. * Returns the specified {@link Identity}, by public key, within this scope.
  149. *
  150. * @param key
  151. * the {@link PublicKey} to use.
  152. * @return an identity representing the public key or <code>null</code> if
  153. * it cannot be found.
  154. */
  155. public abstract Identity getIdentity(PublicKey key);
  156. /**
  157. * Adds an identity to his scope.
  158. *
  159. * @param identity
  160. * the {@link Identity} to add.
  161. * @throws KeyManagementException
  162. * if it is an invalid identity, an identity with the same key
  163. * exists, or if another error occurs.
  164. */
  165. public abstract void addIdentity(Identity identity)
  166. throws KeyManagementException;
  167. /**
  168. * Removes an identity in this scope.
  169. *
  170. * @param identity
  171. * the {@link Identity} to remove.
  172. * @throws KeyManagementException
  173. * if it is a missing identity, or if another error occurs.
  174. */
  175. public abstract void removeIdentity(Identity identity)
  176. throws KeyManagementException;
  177. /**
  178. * Returns an {@link Enumeration} of identities in this scope.
  179. *
  180. * @return an {@link Enumeration} of the identities in this scope.
  181. */
  182. public abstract Enumeration<Identity> identities();
  183. /**
  184. * Returns a string representing this instance. It includes the name, the
  185. * scope name, and number of identities.
  186. *
  187. * @return a string representation of this instance.
  188. */
  189. public String toString()
  190. {
  191. return (super.getName() + " " + super.getScope().getName() + " " + size());
  192. }
  193. }