jericho 2002/10/24 01:27:08
Modified: httpclient/src/java/org/apache/commons/httpclient
Authenticator.java NTLM.java
Log:
- add MT-Safe support
Patched by Adrian Sutton, adrian.sutton at ephox.com
Revision Changes Path
1.33 +11 -10
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java
Index: Authenticator.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/Authenticator.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- Authenticator.java 23 Oct 2002 16:27:19 -0000 1.32
+++ Authenticator.java 24 Oct 2002 08:27:08 -0000 1.33
@@ -388,7 +388,8 @@
+ "authentication.");
} else {
try {
- String response = "NTLM " + NTLM.getResponseFor(challenge,
+ NTLM ntlm = new NTLM();
+ String response = "NTLM " + ntlm.getResponseFor(challenge,
credentials.getUserName(), credentials.getPassword(),
credentials.getHost(), credentials.getDomain());
if (log.isDebugEnabled()) {
@@ -474,17 +475,17 @@
* @return a string containing the authorization header for digest
* @throws HttpException When a recoverable error occurs
*/
- private static String digest(UsernamePasswordCredentials cred,
+ private static String digest(UsernamePasswordCredentials credentials,
Map mapHeaders) throws HttpException {
log.trace("enter Authenticator.digest(UsernamePasswordCredentials, "
+ "Map)");
- String digest = createDigest(cred.getUserName(), cred.getPassword(),
- mapHeaders);
+ String digest = createDigest(credentials.getUserName(),
+ credentials.getPassword(), mapHeaders);
- return "Digest " + createDigestHeader(cred.getUserName(), mapHeaders,
- digest);
+ return "Digest " + createDigestHeader(credentials.getUserName(),
+ mapHeaders, digest);
}
1.5 +20 -25
jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTLM.java
Index: NTLM.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/httpclient/src/java/org/apache/commons/httpclient/NTLM.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- NTLM.java 29 Sep 2002 15:29:32 -0000 1.4
+++ NTLM.java 24 Oct 2002 08:27:08 -0000 1.5
@@ -88,8 +88,8 @@
*/
public final class NTLM {
- private static byte[] currResponse;
- private static int pos = 0;
+ private byte[] currResponse;
+ private int pos = 0;
/** Log object for this class. */
private static final Log log = LogFactory.getLog(NTLM.class);
@@ -119,11 +119,6 @@
}
}
- private NTLM()
- {
- // this constructor is intentionally private
- }
-
/**
* Returns the response for the given message.
*
@@ -135,7 +130,7 @@
* @throws UnsupportedEncodingException if ASCII encoding is not
* supported by the JVM.
*/
- public static final String getResponseFor(String message,
+ public final String getResponseFor(String message,
String username, String password, String host, String domain)
throws UnsupportedEncodingException, HttpException {
String response = null;
@@ -148,7 +143,7 @@
return response;
}
- private static Cipher getCipher(byte[] key) throws HttpException {
+ private Cipher getCipher(byte[] key) throws HttpException {
try {
Cipher ecipher = Cipher.getInstance("DES/ECB/NoPadding");
key = setupKey(key);
@@ -167,7 +162,7 @@
/**
* Adds parity bits to the key.
*/
- private static byte[] setupKey(byte[] key56) {
+ private byte[] setupKey(byte[] key56) {
byte[] key = new byte[8];
key[0] = (byte)((key56[0] >> 1) & 0xff);
key[1] = (byte)((((key56[0] & 0x01) << 6) |
@@ -190,7 +185,7 @@
return key;
}
- private static byte[] encrypt(byte[] key, byte[] bytes)
+ private byte[] encrypt(byte[] key, byte[] bytes)
throws HttpException {
Cipher ecipher = getCipher(key);
try {
@@ -208,7 +203,7 @@
* Prepares the object to create a response of the given length.
* @param length the length of the response to prepare.
*/
- private static void prepareResponse(int length) {
+ private void prepareResponse(int length) {
currResponse = new byte[length];
pos = 0;
}
@@ -217,7 +212,7 @@
* Adds the given byte to the response.
* @param b the byte to add.
*/
- private static void addByte(byte b) {
+ private void addByte(byte b) {
currResponse[pos] = b;
pos++;
}
@@ -226,7 +221,7 @@
* Adds the given bytes to the response.
* @param bytes the bytes to add.
*/
- private static void addBytes(byte[] bytes) {
+ private void addBytes(byte[] bytes) {
for (int i = 0; i < bytes.length; i++) {
currResponse[pos] = bytes[i];
pos++;
@@ -237,7 +232,7 @@
* Returns the response that has been generated after shrinking the
* array if required and base64 encodes the response.
*/
- private static String getResponse() throws UnsupportedEncodingException {
+ private String getResponse() throws UnsupportedEncodingException {
byte[] resp;
if (currResponse.length > pos) {
byte[] tmp = new byte[pos];
@@ -251,7 +246,7 @@
return new String(Base64.encode(resp), "ASCII");
}
- private static String getType1Message(String host, String domain)
+ private String getType1Message(String host, String domain)
throws UnsupportedEncodingException {
host = host.toUpperCase();
domain = domain.toUpperCase();
@@ -328,7 +323,7 @@
* @return an array of 8 bytes that the server sent to be used when
* hashing the password.
*/
- private static byte[] parseType2Message(String sMsg)
+ private byte[] parseType2Message(String sMsg)
throws UnsupportedEncodingException {
// Decode the message first.
byte[] msg = Base64.decode(sMsg.getBytes("ASCII"));
@@ -344,7 +339,7 @@
* Creates the type 3 message using the given server nonce.
* @param nonce the 8 byte array the server sent.
*/
- private static String getType3Message(String user, String password,
+ private String getType3Message(String user, String password,
String host, String domain, byte[] nonce)
throws UnsupportedEncodingException, HttpException {
@@ -441,7 +436,7 @@
* @param passw the password to create a hash for.
* @param nonce the nonce sent by the server.
*/
- private static byte[] hashPassword(String password, byte[] nonce)
+ private byte[] hashPassword(String password, byte[] nonce)
throws UnsupportedEncodingException, HttpException {
byte[] passw = password.toUpperCase().getBytes("ASCII");
byte[] lm_pw1 = new byte[7];
@@ -502,7 +497,7 @@
* byte plaintext is encrypted with each key and the resulting 24
* bytes are stored in teh results array.
*/
- private static void calc_resp(byte[] keys, byte[] plaintext, byte[] results)
+ private void calc_resp(byte[] keys, byte[] plaintext, byte[] results)
throws HttpException {
byte[] keys1 = new byte[7];
byte[] keys2 = new byte[7];
@@ -540,7 +535,7 @@
* order.
* @param num the number to convert.
*/
- private static byte[] convertShort(int num) {
+ private byte[] convertShort(int num) {
byte[] val = new byte[2];
String hex = Integer.toString(num, 16);
while (hex.length() < 4) {
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>