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