1. /*
  2. * @(#)NTSid.java 1.17 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 information about a Windows NT user, group or realm.
  12. *
  13. * <p> Windows NT chooses to represent users, groups and realms (or domains)
  14. * with not only common names, but also relatively unique numbers. These
  15. * numbers are called Security IDentifiers, or SIDs. Windows NT
  16. * also provides services that render these SIDs into string forms.
  17. * This class represents these string forms.
  18. *
  19. * <p> Principals such as this <code>NTSid</code>
  20. * may be associated with a particular <code>Subject</code>
  21. * to augment that <code>Subject</code> with an additional
  22. * identity. Refer to the <code>Subject</code> class for more information
  23. * on how to achieve this. Authorization decisions can then be based upon
  24. * the Principals associated with a <code>Subject</code>.
  25. *
  26. * @version 1.17, 12/19/03
  27. * @see java.security.Principal
  28. * @see javax.security.auth.Subject
  29. */
  30. public class NTSid implements Principal, java.io.Serializable {
  31. private static final long serialVersionUID = 4412290580770249885L;
  32. /**
  33. * @serial
  34. */
  35. private String sid;
  36. /**
  37. * Create an <code>NTSid</code> with a Windows NT SID.
  38. *
  39. * <p>
  40. *
  41. * @param stringSid the Windows NT SID. <p>
  42. *
  43. * @exception NullPointerException if the <code>String</code>
  44. * is <code>null</code>.
  45. *
  46. * @exception IllegalArgumentException if the <code>String</code>
  47. * has zero length.
  48. */
  49. public NTSid (String stringSid) {
  50. if (stringSid == null) {
  51. java.text.MessageFormat form = new java.text.MessageFormat
  52. (sun.security.util.ResourcesMgr.getString
  53. ("invalid null input: value",
  54. "sun.security.util.AuthResources"));
  55. Object[] source = {"stringSid"};
  56. throw new NullPointerException(form.format(source));
  57. }
  58. if (stringSid.length() == 0) {
  59. throw new IllegalArgumentException
  60. (sun.security.util.ResourcesMgr.getString
  61. ("Invalid NTSid value",
  62. "sun.security.util.AuthResources"));
  63. }
  64. sid = new String(stringSid);
  65. }
  66. /**
  67. * Return a string version of this <code>NTSid</code>.
  68. *
  69. * <p>
  70. *
  71. * @return a string version of this <code>NTSid</code>
  72. */
  73. public String getName() {
  74. return sid;
  75. }
  76. /**
  77. * Return a string representation of this <code>NTSid</code>.
  78. *
  79. * <p>
  80. *
  81. * @return a string representation of this <code>NTSid</code>.
  82. */
  83. public String toString() {
  84. java.text.MessageFormat form = new java.text.MessageFormat
  85. (sun.security.util.ResourcesMgr.getString
  86. ("NTSid: name",
  87. "sun.security.util.AuthResources"));
  88. Object[] source = {sid};
  89. return form.format(source);
  90. }
  91. /**
  92. * Compares the specified Object with this <code>NTSid</code>
  93. * for equality. Returns true if the given object is also a
  94. * <code>NTSid</code> and the two NTSids have the same String
  95. * representation.
  96. *
  97. * <p>
  98. *
  99. * @param o Object to be compared for equality with this
  100. * <code>NTSid</code>.
  101. *
  102. * @return true if the specified Object is equal to this
  103. * <code>NTSid</code>.
  104. */
  105. public boolean equals(Object o) {
  106. if (o == null)
  107. return false;
  108. if (this == o)
  109. return true;
  110. if (!(o instanceof NTSid))
  111. return false;
  112. NTSid that = (NTSid)o;
  113. if (sid.equals(that.sid)) {
  114. return true;
  115. }
  116. return false;
  117. }
  118. /**
  119. * Return a hash code for this <code>NTSid</code>.
  120. *
  121. * <p>
  122. *
  123. * @return a hash code for this <code>NTSid</code>.
  124. */
  125. public int hashCode() {
  126. return sid.hashCode();
  127. }
  128. }