1. /*
  2. * @(#)NTNumericCredential.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. /**
  9. * <p> This class abstracts an NT security token
  10. * and provides a mechanism to do same-process security impersonation.
  11. *
  12. * @version 1.14, 12/19/03
  13. */
  14. public class NTNumericCredential {
  15. private long impersonationToken;
  16. /**
  17. * Create an <code>NTNumericCredential</code> with an integer value.
  18. *
  19. * <p>
  20. *
  21. * @param token the Windows NT security token for this user. <p>
  22. *
  23. */
  24. public NTNumericCredential(long token) {
  25. this.impersonationToken = token;
  26. }
  27. /**
  28. * Return an integer representation of this
  29. * <code>NTNumericCredential</code>.
  30. *
  31. * <p>
  32. *
  33. * @return an integer representation of this
  34. * <code>NTNumericCredential</code>.
  35. */
  36. public long getToken() {
  37. return impersonationToken;
  38. }
  39. /**
  40. * Return a string representation of this <code>NTNumericCredential</code>.
  41. *
  42. * <p>
  43. *
  44. * @return a string representation of this <code>NTNumericCredential</code>.
  45. */
  46. public String toString() {
  47. java.text.MessageFormat form = new java.text.MessageFormat
  48. (sun.security.util.ResourcesMgr.getString
  49. ("NTNumericCredential: name",
  50. "sun.security.util.AuthResources"));
  51. Object[] source = {Long.toString(impersonationToken)};
  52. return form.format(source);
  53. }
  54. /**
  55. * Compares the specified Object with this <code>NTNumericCredential</code>
  56. * for equality. Returns true if the given object is also a
  57. * <code>NTNumericCredential</code> and the two NTNumericCredentials
  58. * represent the same NT security token.
  59. *
  60. * <p>
  61. *
  62. * @param o Object to be compared for equality with this
  63. * <code>NTNumericCredential</code>.
  64. *
  65. * @return true if the specified Object is equal equal to this
  66. * <code>NTNumericCredential</code>.
  67. */
  68. public boolean equals(Object o) {
  69. if (o == null)
  70. return false;
  71. if (this == o)
  72. return true;
  73. if (!(o instanceof NTNumericCredential))
  74. return false;
  75. NTNumericCredential that = (NTNumericCredential)o;
  76. if (impersonationToken == that.getToken())
  77. return true;
  78. return false;
  79. }
  80. /**
  81. * Return a hash code for this <code>NTNumericCredential</code>.
  82. *
  83. * <p>
  84. *
  85. * @return a hash code for this <code>NTNumericCredential</code>.
  86. */
  87. public int hashCode() {
  88. return (int)this.impersonationToken;
  89. }
  90. }