1. /*
  2. * @(#)NTDomainPrincipal.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 com.sun.security.auth;
  8. import java.security.Principal;
  9. /**
  10. * <p> This class implements the <code>Principal</code> interface
  11. * and represents the name of the Windows NT domain into which the
  12. * user authenticated. This will be a domain name if the user logged
  13. * into a Windows NT domain, a workgroup name if the user logged into
  14. * a workgroup, or a machine name if the user logged into a standalone
  15. * configuration.
  16. *
  17. * <p> Principals such as this <code>NTDomainPrincipal</code>
  18. * may be associated with a particular <code>Subject</code>
  19. * to augment that <code>Subject</code> with an additional
  20. * identity. Refer to the <code>Subject</code> class for more information
  21. * on how to achieve this. Authorization decisions can then be based upon
  22. * the Principals associated with a <code>Subject</code>.
  23. *
  24. * @version 1.14, 12/19/03
  25. * @see java.security.Principal
  26. * @see javax.security.auth.Subject
  27. */
  28. public class NTDomainPrincipal implements Principal, java.io.Serializable {
  29. private static final long serialVersionUID = -4408637351440771220L;
  30. /**
  31. * @serial
  32. */
  33. private String name;
  34. /**
  35. * Create an <code>NTDomainPrincipal</code> with a Windows NT domain name.
  36. *
  37. * <p>
  38. *
  39. * @param name the Windows NT domain name for this user. <p>
  40. *
  41. * @exception NullPointerException if the <code>name</code>
  42. * is <code>null</code>.
  43. */
  44. public NTDomainPrincipal(String name) {
  45. if (name == null) {
  46. java.text.MessageFormat form = new java.text.MessageFormat
  47. (sun.security.util.ResourcesMgr.getString
  48. ("invalid null input: value",
  49. "sun.security.util.AuthResources"));
  50. Object[] source = {"name"};
  51. throw new NullPointerException(form.format(source));
  52. }
  53. this.name = name;
  54. }
  55. /**
  56. * Return the Windows NT domain name for this
  57. * <code>NTDomainPrincipal</code>.
  58. *
  59. * <p>
  60. *
  61. * @return the Windows NT domain name for this
  62. * <code>NTDomainPrincipal</code>
  63. */
  64. public String getName() {
  65. return name;
  66. }
  67. /**
  68. * Return a string representation of this <code>NTDomainPrincipal</code>.
  69. *
  70. * <p>
  71. *
  72. * @return a string representation of this <code>NTDomainPrincipal</code>.
  73. */
  74. public String toString() {
  75. java.text.MessageFormat form = new java.text.MessageFormat
  76. (sun.security.util.ResourcesMgr.getString
  77. ("NTDomainPrincipal: name",
  78. "sun.security.util.AuthResources"));
  79. Object[] source = {name};
  80. return form.format(source);
  81. }
  82. /**
  83. * Compares the specified Object with this <code>NTDomainPrincipal</code>
  84. * for equality. Returns true if the given object is also a
  85. * <code>NTDomainPrincipal</code> and the two NTDomainPrincipals
  86. * have the same name.
  87. *
  88. * <p>
  89. *
  90. * @param o Object to be compared for equality with this
  91. * <code>NTDomainPrincipal</code>.
  92. *
  93. * @return true if the specified Object is equal equal to this
  94. * <code>NTDomainPrincipal</code>.
  95. */
  96. public boolean equals(Object o) {
  97. if (o == null)
  98. return false;
  99. if (this == o)
  100. return true;
  101. if (!(o instanceof NTDomainPrincipal))
  102. return false;
  103. NTDomainPrincipal that = (NTDomainPrincipal)o;
  104. if (name.equals(that.getName()))
  105. return true;
  106. return false;
  107. }
  108. /**
  109. * Return a hash code for this <code>NTDomainPrincipal</code>.
  110. *
  111. * <p>
  112. *
  113. * @return a hash code for this <code>NTDomainPrincipal</code>.
  114. */
  115. public int hashCode() {
  116. return this.getName().hashCode();
  117. }
  118. }