1. /*
  2. * @(#)SolarisPrincipal.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 Solaris user.
  12. *
  13. * <p> Principals such as this <code>SolarisPrincipal</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. *
  20. * @deprecated As of JDK 1.4, replaced by
  21. * {@link UnixPrincipal}.
  22. * This class is entirely deprecated.
  23. * @version 1.17, 05/18/04
  24. * @see java.security.Principal
  25. * @see javax.security.auth.Subject
  26. */
  27. @Deprecated
  28. public class SolarisPrincipal implements Principal, java.io.Serializable {
  29. private static final long serialVersionUID = -7840670002439379038L;
  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 SolarisPrincipal with a Solaris username.
  44. *
  45. * <p>
  46. *
  47. * @param name the Unix username for this user.
  48. *
  49. * @exception NullPointerException if the <code>name</code>
  50. * is <code>null</code>.
  51. */
  52. public SolarisPrincipal(String name) {
  53. if (name == null)
  54. throw new NullPointerException(rb.getString("provided null name"));
  55. this.name = name;
  56. }
  57. /**
  58. * Return the Unix username for this <code>SolarisPrincipal</code>.
  59. *
  60. * <p>
  61. *
  62. * @return the Unix username for this <code>SolarisPrincipal</code>
  63. */
  64. public String getName() {
  65. return name;
  66. }
  67. /**
  68. * Return a string representation of this <code>SolarisPrincipal</code>.
  69. *
  70. * <p>
  71. *
  72. * @return a string representation of this <code>SolarisPrincipal</code>.
  73. */
  74. public String toString() {
  75. return(rb.getString("SolarisPrincipal: ") + name);
  76. }
  77. /**
  78. * Compares the specified Object with this <code>SolarisPrincipal</code>
  79. * for equality. Returns true if the given object is also a
  80. * <code>SolarisPrincipal</code> and the two SolarisPrincipals
  81. * have the same username.
  82. *
  83. * <p>
  84. *
  85. * @param o Object to be compared for equality with this
  86. * <code>SolarisPrincipal</code>.
  87. *
  88. * @return true if the specified Object is equal equal to this
  89. * <code>SolarisPrincipal</code>.
  90. */
  91. public boolean equals(Object o) {
  92. if (o == null)
  93. return false;
  94. if (this == o)
  95. return true;
  96. if (!(o instanceof SolarisPrincipal))
  97. return false;
  98. SolarisPrincipal that = (SolarisPrincipal)o;
  99. if (this.getName().equals(that.getName()))
  100. return true;
  101. return false;
  102. }
  103. /**
  104. * Return a hash code for this <code>SolarisPrincipal</code>.
  105. *
  106. * <p>
  107. *
  108. * @return a hash code for this <code>SolarisPrincipal</code>.
  109. */
  110. public int hashCode() {
  111. return name.hashCode();
  112. }
  113. }