1. /*
  2. * @(#)NTSystem.java 1.9 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.module;
  8. import javax.security.auth.login.LoginException;
  9. /**
  10. * <p> This class implementation retrieves and makes available NT
  11. * security information for the current user.
  12. *
  13. * @version 1.9, 12/19/03
  14. */
  15. public class NTSystem {
  16. private native void getCurrent(boolean debug);
  17. private String userName;
  18. private String domain;
  19. private String domainSID;
  20. private String userSID;
  21. private String groupIDs[];
  22. private String primaryGroupID;
  23. private long impersonationToken;
  24. static boolean loadedLibrary = false;
  25. /**
  26. * Instantiate an <code>NTSystem</code> and load
  27. * the native library to access the underlying system information.
  28. */
  29. public NTSystem() {
  30. this(false);
  31. }
  32. /**
  33. * Instantiate an <code>NTSystem</code> and load
  34. * the native library to access the underlying system information.
  35. */
  36. NTSystem(boolean debug) {
  37. if (!loadedLibrary) {
  38. loadNative();
  39. loadedLibrary = true;
  40. }
  41. getCurrent(debug);
  42. }
  43. /**
  44. * Get the username for the current NT user.
  45. *
  46. * <p>
  47. *
  48. * @return the username for the current NT user.
  49. */
  50. public String getName() {
  51. return userName;
  52. }
  53. /**
  54. * Get the domain for the current NT user.
  55. *
  56. * <p>
  57. *
  58. * @return the domain for the current NT user.
  59. */
  60. public String getDomain() {
  61. return domain;
  62. }
  63. /**
  64. * Get a printable SID for the current NT user's domain.
  65. *
  66. * <p>
  67. *
  68. * @return a printable SID for the current NT user's domain.
  69. */
  70. public String getDomainSID() {
  71. return domainSID;
  72. }
  73. /**
  74. * Get a printable SID for the current NT user.
  75. *
  76. * <p>
  77. *
  78. * @return a printable SID for the current NT user.
  79. */
  80. public String getUserSID() {
  81. return userSID;
  82. }
  83. /**
  84. * Get a printable primary group SID for the current NT user.
  85. *
  86. * <p>
  87. *
  88. * @return the primary group SID for the current NT user.
  89. */
  90. public String getPrimaryGroupID() {
  91. return primaryGroupID;
  92. }
  93. /**
  94. * Get the printable group SIDs for the current NT user.
  95. *
  96. * <p>
  97. *
  98. * @return the group SIDs for the current NT user.
  99. */
  100. public String[] getGroupIDs() {
  101. return groupIDs;
  102. }
  103. /**
  104. * Get an impersonation token for the current NT user.
  105. *
  106. * <p>
  107. *
  108. * @return an impersonation token for the current NT user.
  109. */
  110. public long getImpersonationToken() {
  111. return impersonationToken;
  112. }
  113. private void loadNative() {
  114. System.loadLibrary("jaas_nt");
  115. }
  116. }