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