1. /*
  2. * @(#)NTSid.java 1.15 03/01/27
  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 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.15, 01/27/03
  27. * @see java.security.Principal
  28. * @see javax.security.auth.Subject
  29. */
  30. public class NTSid implements Principal, java.io.Serializable {
  31. /**
  32. * @serial
  33. */
  34. private String sid;
  35. /**
  36. * Create an <code>NTSid</code> with a Windows NT SID.
  37. *
  38. * <p>
  39. *
  40. * @param stringSid the Windows NT SID. <p>
  41. *
  42. * @exception NullPointerException if the <code>String</code>
  43. * is <code>null</code>.
  44. *
  45. * @exception IllegalArgumentException if the <code>String</code>
  46. * has zero length.
  47. */
  48. public NTSid (String stringSid) {
  49. if (stringSid == null) {
  50. java.text.MessageFormat form = new java.text.MessageFormat
  51. (sun.security.util.ResourcesMgr.getString
  52. ("invalid null input: value",
  53. "sun.security.util.AuthResources"));
  54. Object[] source = {"stringSid"};
  55. throw new NullPointerException(form.format(source));
  56. }
  57. if (stringSid.length() == 0) {
  58. throw new IllegalArgumentException
  59. (sun.security.util.ResourcesMgr.getString
  60. ("Invalid NTSid value",
  61. "sun.security.util.AuthResources"));
  62. }
  63. sid = new String(stringSid);
  64. }
  65. /**
  66. * Return a string version of this <code>NTSid</code>.
  67. *
  68. * <p>
  69. *
  70. * @return a string version of this <code>NTSid</code>
  71. */
  72. public String getName() {
  73. return sid;
  74. }
  75. /**
  76. * Return a string representation of this <code>NTSid</code>.
  77. *
  78. * <p>
  79. *
  80. * @return a string representation of this <code>NTSid</code>.
  81. */
  82. public String toString() {
  83. java.text.MessageFormat form = new java.text.MessageFormat
  84. (sun.security.util.ResourcesMgr.getString
  85. ("NTSid: name",
  86. "sun.security.util.AuthResources"));
  87. Object[] source = {sid};
  88. return form.format(source);
  89. }
  90. /**
  91. * Compares the specified Object with this <code>NTSid</code>
  92. * for equality. Returns true if the given object is also a
  93. * <code>NTSid</code> and the two NTSids have the same String
  94. * representation.
  95. *
  96. * <p>
  97. *
  98. * @param o Object to be compared for equality with this
  99. * <code>NTSid</code>.
  100. *
  101. * @return true if the specified Object is equal to this
  102. * <code>NTSid</code>.
  103. */
  104. public boolean equals(Object o) {
  105. if (o == null)
  106. return false;
  107. if (this == o)
  108. return true;
  109. if (!(o instanceof NTSid))
  110. return false;
  111. NTSid that = (NTSid)o;
  112. if (sid.equals(that.sid)) {
  113. return true;
  114. }
  115. return false;
  116. }
  117. /**
  118. * Return a hash code for this <code>NTSid</code>.
  119. *
  120. * <p>
  121. *
  122. * @return a hash code for this <code>NTSid</code>.
  123. */
  124. public int hashCode() {
  125. return sid.hashCode();
  126. }
  127. }