1. /*
  2. * @(#)SolarisNumericGroupPrincipal.java 1.17 04/05/18
  3. *
  4. * Copyright 2004 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.security.Principal;
  9. /**
  10. * <p> This class implements the <code>Principal</code> interface
  11. * and represents a user's Solaris group identification number (GID).
  12. *
  13. * <p> Principals such as this <code>SolarisNumericGroupPrincipal</code>
  14. * may be associated with a particular <code>Subject</code>
  15. * to augment that <code>Subject</code> with an additional
  16. * identity. Refer to the <code>Subject</code> class for more information
  17. * on how to achieve this. Authorization decisions can then be based upon
  18. * the Principals associated with a <code>Subject</code>.
  19. * @deprecated As of JDK 1.4, replaced by
  20. * {@link UnixNumericGroupPrincipal}.
  21. * This class is entirely deprecated.
  22. *
  23. * @version 1.17, 05/18/04
  24. * @see java.security.Principal
  25. * @see javax.security.auth.Subject
  26. */
  27. @Deprecated
  28. public class SolarisNumericGroupPrincipal implements
  29. Principal,
  30. java.io.Serializable {
  31. private static final long serialVersionUID = 2345199581042573224L;
  32. private static final java.util.ResourceBundle rb =
  33. (java.util.ResourceBundle)java.security.AccessController.doPrivileged
  34. (new java.security.PrivilegedAction() {
  35. public Object run() {
  36. return (java.util.ResourceBundle.getBundle
  37. ("sun.security.util.AuthResources"));
  38. }
  39. });
  40. /**
  41. * @serial
  42. */
  43. private String name;
  44. /**
  45. * @serial
  46. */
  47. private boolean primaryGroup;
  48. /**
  49. * Create a <code>SolarisNumericGroupPrincipal</code> using a
  50. * <code>String</code> representation of the user's
  51. * group identification number (GID).
  52. *
  53. * <p>
  54. *
  55. * @param name the user's group identification number (GID)
  56. * for this user. <p>
  57. *
  58. * @param primaryGroup true if the specified GID represents the
  59. * primary group to which this user belongs.
  60. *
  61. * @exception NullPointerException if the <code>name</code>
  62. * is <code>null</code>.
  63. */
  64. public SolarisNumericGroupPrincipal(String name, boolean primaryGroup) {
  65. if (name == null)
  66. throw new NullPointerException(rb.getString("provided null name"));
  67. this.name = name;
  68. this.primaryGroup = primaryGroup;
  69. }
  70. /**
  71. * Create a <code>SolarisNumericGroupPrincipal</code> using a
  72. * long representation of the user's group identification number (GID).
  73. *
  74. * <p>
  75. *
  76. * @param name the user's group identification number (GID) for this user
  77. * represented as a long. <p>
  78. *
  79. * @param primaryGroup true if the specified GID represents the
  80. * primary group to which this user belongs.
  81. *
  82. */
  83. public SolarisNumericGroupPrincipal(long name, boolean primaryGroup) {
  84. this.name = (new Long(name)).toString();
  85. this.primaryGroup = primaryGroup;
  86. }
  87. /**
  88. * Return the user's group identification number (GID) for this
  89. * <code>SolarisNumericGroupPrincipal</code>.
  90. *
  91. * <p>
  92. *
  93. * @return the user's group identification number (GID) for this
  94. * <code>SolarisNumericGroupPrincipal</code>
  95. */
  96. public String getName() {
  97. return name;
  98. }
  99. /**
  100. * Return the user's group identification number (GID) for this
  101. * <code>SolarisNumericGroupPrincipal</code> as a long.
  102. *
  103. * <p>
  104. *
  105. * @return the user's group identification number (GID) for this
  106. * <code>SolarisNumericGroupPrincipal</code> as a long.
  107. */
  108. public long longValue() {
  109. return ((new Long(name)).longValue());
  110. }
  111. /**
  112. * Return whether this group identification number (GID) represents
  113. * the primary group to which this user belongs.
  114. *
  115. * <p>
  116. *
  117. * @return true if this group identification number (GID) represents
  118. * the primary group to which this user belongs,
  119. * or false otherwise.
  120. */
  121. public boolean isPrimaryGroup() {
  122. return primaryGroup;
  123. }
  124. /**
  125. * Return a string representation of this
  126. * <code>SolarisNumericGroupPrincipal</code>.
  127. *
  128. * <p>
  129. *
  130. * @return a string representation of this
  131. * <code>SolarisNumericGroupPrincipal</code>.
  132. */
  133. public String toString() {
  134. return((primaryGroup ?
  135. rb.getString
  136. ("SolarisNumericGroupPrincipal [Primary Group]: ") + name :
  137. rb.getString
  138. ("SolarisNumericGroupPrincipal [Supplementary Group]: ") + name));
  139. }
  140. /**
  141. * Compares the specified Object with this
  142. * <code>SolarisNumericGroupPrincipal</code>
  143. * for equality. Returns true if the given object is also a
  144. * <code>SolarisNumericGroupPrincipal</code> and the two
  145. * SolarisNumericGroupPrincipals
  146. * have the same group identification number (GID).
  147. *
  148. * <p>
  149. *
  150. * @param o Object to be compared for equality with this
  151. * <code>SolarisNumericGroupPrincipal</code>.
  152. *
  153. * @return true if the specified Object is equal equal to this
  154. * <code>SolarisNumericGroupPrincipal</code>.
  155. */
  156. public boolean equals(Object o) {
  157. if (o == null)
  158. return false;
  159. if (this == o)
  160. return true;
  161. if (!(o instanceof SolarisNumericGroupPrincipal))
  162. return false;
  163. SolarisNumericGroupPrincipal that = (SolarisNumericGroupPrincipal)o;
  164. if (this.getName().equals(that.getName()) &&
  165. this.isPrimaryGroup() == that.isPrimaryGroup())
  166. return true;
  167. return false;
  168. }
  169. /**
  170. * Return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
  171. *
  172. * <p>
  173. *
  174. * @return a hash code for this <code>SolarisNumericGroupPrincipal</code>.
  175. */
  176. public int hashCode() {
  177. return toString().hashCode();
  178. }
  179. }