1. /*
  2. * @(#)SolarisPrincipal.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 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.14, 01/23/03
  24. * @see java.security.Principal
  25. * @see javax.security.auth.Subject
  26. */
  27. public class SolarisPrincipal implements Principal, java.io.Serializable {
  28. private static final java.util.ResourceBundle rb =
  29. (java.util.ResourceBundle)java.security.AccessController.doPrivileged
  30. (new java.security.PrivilegedAction() {
  31. public Object run() {
  32. return (java.util.ResourceBundle.getBundle
  33. ("sun.security.util.AuthResources"));
  34. }
  35. });
  36. /**
  37. * @serial
  38. */
  39. private String name;
  40. /**
  41. * Create a SolarisPrincipal with a Solaris username.
  42. *
  43. * <p>
  44. *
  45. * @param name the Unix username for this user.
  46. *
  47. * @exception NullPointerException if the <code>name</code>
  48. * is <code>null</code>.
  49. */
  50. public SolarisPrincipal(String name) {
  51. if (name == null)
  52. throw new NullPointerException(rb.getString("provided null name"));
  53. this.name = name;
  54. }
  55. /**
  56. * Return the Unix username for this <code>SolarisPrincipal</code>.
  57. *
  58. * <p>
  59. *
  60. * @return the Unix username for this <code>SolarisPrincipal</code>
  61. */
  62. public String getName() {
  63. return name;
  64. }
  65. /**
  66. * Return a string representation of this <code>SolarisPrincipal</code>.
  67. *
  68. * <p>
  69. *
  70. * @return a string representation of this <code>SolarisPrincipal</code>.
  71. */
  72. public String toString() {
  73. return(rb.getString("SolarisPrincipal: ") + name);
  74. }
  75. /**
  76. * Compares the specified Object with this <code>SolarisPrincipal</code>
  77. * for equality. Returns true if the given object is also a
  78. * <code>SolarisPrincipal</code> and the two SolarisPrincipals
  79. * have the same username.
  80. *
  81. * <p>
  82. *
  83. * @param o Object to be compared for equality with this
  84. * <code>SolarisPrincipal</code>.
  85. *
  86. * @return true if the specified Object is equal equal to this
  87. * <code>SolarisPrincipal</code>.
  88. */
  89. public boolean equals(Object o) {
  90. if (o == null)
  91. return false;
  92. if (this == o)
  93. return true;
  94. if (!(o instanceof SolarisPrincipal))
  95. return false;
  96. SolarisPrincipal that = (SolarisPrincipal)o;
  97. if (this.getName().equals(that.getName()))
  98. return true;
  99. return false;
  100. }
  101. /**
  102. * Return a hash code for this <code>SolarisPrincipal</code>.
  103. *
  104. * <p>
  105. *
  106. * @return a hash code for this <code>SolarisPrincipal</code>.
  107. */
  108. public int hashCode() {
  109. return name.hashCode();
  110. }
  111. }