1. /*
  2. * @(#)SolarisNumericUserPrincipal.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 identification number (UID).
  12. *
  13. * <p> Principals such as this <code>SolarisNumericUserPrincipal</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 UnixNumericUserPrincipal}.
  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 SolarisNumericUserPrincipal implements
  29. Principal,
  30. java.io.Serializable {
  31. private static final long serialVersionUID = -3178578484679887104L;
  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. * Create a <code>SolarisNumericUserPrincipal</code> using a
  46. * <code>String</code> representation of the
  47. * user's identification number (UID).
  48. *
  49. * <p>
  50. *
  51. * @param name the user identification number (UID) for this user.
  52. *
  53. * @exception NullPointerException if the <code>name</code>
  54. * is <code>null</code>.
  55. */
  56. public SolarisNumericUserPrincipal(String name) {
  57. if (name == null)
  58. throw new NullPointerException(rb.getString("provided null name"));
  59. this.name = name;
  60. }
  61. /**
  62. * Create a <code>SolarisNumericUserPrincipal</code> using a
  63. * long representation of the user's identification number (UID).
  64. *
  65. * <p>
  66. *
  67. * @param name the user identification number (UID) for this user
  68. * represented as a long.
  69. */
  70. public SolarisNumericUserPrincipal(long name) {
  71. this.name = (new Long(name)).toString();
  72. }
  73. /**
  74. * Return the user identification number (UID) for this
  75. * <code>SolarisNumericUserPrincipal</code>.
  76. *
  77. * <p>
  78. *
  79. * @return the user identification number (UID) for this
  80. * <code>SolarisNumericUserPrincipal</code>
  81. */
  82. public String getName() {
  83. return name;
  84. }
  85. /**
  86. * Return the user identification number (UID) for this
  87. * <code>SolarisNumericUserPrincipal</code> as a long.
  88. *
  89. * <p>
  90. *
  91. * @return the user identification number (UID) for this
  92. * <code>SolarisNumericUserPrincipal</code> as a long.
  93. */
  94. public long longValue() {
  95. return ((new Long(name)).longValue());
  96. }
  97. /**
  98. * Return a string representation of this
  99. * <code>SolarisNumericUserPrincipal</code>.
  100. *
  101. * <p>
  102. *
  103. * @return a string representation of this
  104. * <code>SolarisNumericUserPrincipal</code>.
  105. */
  106. public String toString() {
  107. return(rb.getString("SolarisNumericUserPrincipal: ") + name);
  108. }
  109. /**
  110. * Compares the specified Object with this
  111. * <code>SolarisNumericUserPrincipal</code>
  112. * for equality. Returns true if the given object is also a
  113. * <code>SolarisNumericUserPrincipal</code> and the two
  114. * SolarisNumericUserPrincipals
  115. * have the same user identification number (UID).
  116. *
  117. * <p>
  118. *
  119. * @param o Object to be compared for equality with this
  120. * <code>SolarisNumericUserPrincipal</code>.
  121. *
  122. * @return true if the specified Object is equal equal to this
  123. * <code>SolarisNumericUserPrincipal</code>.
  124. */
  125. public boolean equals(Object o) {
  126. if (o == null)
  127. return false;
  128. if (this == o)
  129. return true;
  130. if (!(o instanceof SolarisNumericUserPrincipal))
  131. return false;
  132. SolarisNumericUserPrincipal that = (SolarisNumericUserPrincipal)o;
  133. if (this.getName().equals(that.getName()))
  134. return true;
  135. return false;
  136. }
  137. /**
  138. * Return a hash code for this <code>SolarisNumericUserPrincipal</code>.
  139. *
  140. * <p>
  141. *
  142. * @return a hash code for this <code>SolarisNumericUserPrincipal</code>.
  143. */
  144. public int hashCode() {
  145. return name.hashCode();
  146. }
  147. }