1. /*
  2. * $Header: /home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTCredentials.java,v 1.10 2004/04/18 23:51:35 jsdever Exp $
  3. * $Revision: 1.10 $
  4. * $Date: 2004/04/18 23:51:35 $
  5. *
  6. * ====================================================================
  7. *
  8. * Copyright 2002-2004 The Apache Software Foundation
  9. *
  10. * Licensed under the Apache License, Version 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. *
  14. * http://www.apache.org/licenses/LICENSE-2.0
  15. *
  16. * Unless required by applicable law or agreed to in writing, software
  17. * distributed under the License is distributed on an "AS IS" BASIS,
  18. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  19. * See the License for the specific language governing permissions and
  20. * limitations under the License.
  21. * ====================================================================
  22. *
  23. * This software consists of voluntary contributions made by many
  24. * individuals on behalf of the Apache Software Foundation. For more
  25. * information on the Apache Software Foundation, please see
  26. * <http://www.apache.org/>.
  27. *
  28. */
  29. package org.apache.commons.httpclient;
  30. /** {@link Credentials} for use with the NTLM authentication scheme which requires additional
  31. * information.
  32. *
  33. * @author <a href="mailto:adrian@ephox.com">Adrian Sutton</a>
  34. * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
  35. *
  36. * @version $Revision: 1.10 $ $Date: 2004/04/18 23:51:35 $
  37. *
  38. * @since 2.0
  39. */
  40. public class NTCredentials extends UsernamePasswordCredentials {
  41. // ----------------------------------------------------- Instance Variables
  42. /** The Domain to authenticate with. */
  43. private String domain;
  44. /** The host the authentication request is originating from. */
  45. private String host;
  46. // ----------------------------------------------------------- Constructors
  47. /**
  48. * Default constructor.
  49. *
  50. * @deprecated Do not use. Null user name, domain & host no longer allowed
  51. */
  52. public NTCredentials() {
  53. super();
  54. }
  55. /**
  56. * Constructor.
  57. * @param userName The user name. This should not include the domain to authenticate with.
  58. * For example: "user" is correct whereas "DOMAIN\\user" is not.
  59. * @param password The password.
  60. * @param host The host the authentication request is originating from. Essentially, the
  61. * computer name for this machine.
  62. * @param domain The domain to authenticate within.
  63. */
  64. public NTCredentials(String userName, String password, String host,
  65. String domain) {
  66. super(userName, password);
  67. if (domain == null) {
  68. throw new IllegalArgumentException("Domain may not be null");
  69. }
  70. this.domain = domain;
  71. if (host == null) {
  72. throw new IllegalArgumentException("Host may not be null");
  73. }
  74. this.host = host;
  75. }
  76. // ------------------------------------------------------- Instance Methods
  77. /**
  78. * Sets the domain to authenticate with. The domain may not be null.
  79. *
  80. * @param domain the NT domain to authenticate in.
  81. *
  82. * @see #getDomain()
  83. *
  84. * @deprecated Do not use. The NTCredentials objects should be immutable
  85. */
  86. public void setDomain(String domain) {
  87. if (domain == null) {
  88. throw new IllegalArgumentException("Domain may not be null");
  89. }
  90. this.domain = domain;
  91. }
  92. /**
  93. * Retrieves the name to authenticate with.
  94. *
  95. * @return String the domain these credentials are intended to authenticate with.
  96. *
  97. * @see #setDomain(String)
  98. *
  99. */
  100. public String getDomain() {
  101. return domain;
  102. }
  103. /**
  104. * Sets the host name of the computer originating the request. The host name may
  105. * not be null.
  106. *
  107. * @param host the Host the user is logged into.
  108. *
  109. * @deprecated Do not use. The NTCredentials objects should be immutable
  110. */
  111. public void setHost(String host) {
  112. if (host == null) {
  113. throw new IllegalArgumentException("Host may not be null");
  114. }
  115. this.host = host;
  116. }
  117. /**
  118. * Retrieves the host name of the computer originating the request.
  119. *
  120. * @return String the host the user is logged into.
  121. */
  122. public String getHost() {
  123. return this.host;
  124. }
  125. /**
  126. * Return a string representation of this object.
  127. * @return A string represenation of this object.
  128. */
  129. public String toString() {
  130. final StringBuffer sbResult = new StringBuffer(super.toString());
  131. sbResult.append("@");
  132. sbResult.append(this.host);
  133. sbResult.append(".");
  134. sbResult.append(this.domain);
  135. return sbResult.toString();
  136. }
  137. }