1. /*
  2. * @(#)JMXPrincipal.java 1.14 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.remote;
  8. import java.io.Serializable;
  9. import java.security.Principal;
  10. /**
  11. * <p>The identity of a remote client of the JMX Remote API.</p>
  12. *
  13. * <p>Principals such as this <code>JMXPrincipal</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 {@link javax.security.auth.Subject}
  17. * class for more information on how to achieve this.
  18. * Authorization decisions can then be based upon
  19. * the Principals associated with a <code>Subject</code>.
  20. *
  21. * @see java.security.Principal
  22. * @see javax.security.auth.Subject
  23. * @since 1.5
  24. * @since.unbundled 1.0
  25. */
  26. public class JMXPrincipal implements Principal, Serializable {
  27. private static final long serialVersionUID = -4184480100214577411L;
  28. /**
  29. * @serial The JMX Remote API name for the identity represented by
  30. * this <code>JMXPrincipal</code> object.
  31. * @see #getName()
  32. */
  33. private String name;
  34. /**
  35. * <p>Creates a JMXPrincipal for a given identity.</p>
  36. *
  37. * @param name the JMX Remote API name for this identity.
  38. *
  39. * @exception NullPointerException if the <code>name</code> is
  40. * <code>null</code>.
  41. */
  42. public JMXPrincipal(String name) {
  43. if (name == null)
  44. throw new NullPointerException("illegal null input");
  45. this.name = name;
  46. }
  47. /**
  48. * Returns the name of this principal.
  49. *
  50. * <p>
  51. *
  52. * @return the name of this <code>JMXPrincipal</code>.
  53. */
  54. public String getName() {
  55. return name;
  56. }
  57. /**
  58. * Returns a string representation of this <code>JMXPrincipal</code>.
  59. *
  60. * <p>
  61. *
  62. * @return a string representation of this <code>JMXPrincipal</code>.
  63. */
  64. public String toString() {
  65. return("JMXPrincipal: " + name);
  66. }
  67. /**
  68. * Compares the specified Object with this <code>JMXPrincipal</code>
  69. * for equality. Returns true if the given object is also a
  70. * <code>JMXPrincipal</code> and the two JMXPrincipals
  71. * have the same name.
  72. *
  73. * <p>
  74. *
  75. * @param o Object to be compared for equality with this
  76. * <code>JMXPrincipal</code>.
  77. *
  78. * @return true if the specified Object is equal to this
  79. * <code>JMXPrincipal</code>.
  80. */
  81. public boolean equals(Object o) {
  82. if (o == null)
  83. return false;
  84. if (this == o)
  85. return true;
  86. if (!(o instanceof JMXPrincipal))
  87. return false;
  88. JMXPrincipal that = (JMXPrincipal)o;
  89. return (this.getName().equals(that.getName()));
  90. }
  91. /**
  92. * Returns a hash code for this <code>JMXPrincipal</code>.
  93. *
  94. * <p>
  95. *
  96. * @return a hash code for this <code>JMXPrincipal</code>.
  97. */
  98. public int hashCode() {
  99. return name.hashCode();
  100. }
  101. }