我有一个使用 SSO 的站点,它使用 NTLM 身份验证,到目前为止它在 XP 和 win 7(32 位)上运行良好,但最近我的公司决定也使用 win 7(64 位)计算机。在这些PC上,握手在type 2消息后结束,tomcat返回401。我不知道如何调查,也许这里有人可以给我一些提示。
这是在 servlet 的 doPost 方法中:
try {
// NTLM Handshake
// 1: Client --> Server | GET ...
// 2: Client <-- Server | 401 Unauthorized/WWW-Authenticate: NTLM
String auth = request.getHeader("Authorization");
if (auth == null) {
response.setStatus(response.SC_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
response.flushBuffer();
return;
}
if (auth.startsWith("NTLM ")) {
byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth
.substring(5));
int off = 0, length, offset;
// 3: Client --> Server | GET .../Authorization: NTLM
// <base64-encoded type-1-message>
if (msg[8] == 1) {
// 4: Client <-- Server | 401 Unauthorized/WWW-Authenticate:
// NTLM <base64-encoded type-2-message>
byte z = 0;
byte[] msg1 = { (byte) 'N', (byte) 'T', (byte) 'L',
(byte) 'M', (byte) 'S', (byte) 'S', (byte) 'P', z,
(byte) 2, z, z, z, z, z, z, z, (byte) 40, z, z, z,
(byte) 1, (byte) 130, z, z, z, (byte) 2, (byte) 2,
(byte) 2, z, z, z, z, z, z, z, z, z, z, z, z };
response.setHeader("WWW-Authenticate", "NTLM "
+ new sun.misc.BASE64Encoder().encodeBuffer(msg1));
//response.sendError(response.SC_UNAUTHORIZED);
response.setStatus(response.SC_UNAUTHORIZED);
response.flushBuffer();
return;
}
// 5: Client --> Server | GET .../Authorization: NTLM
// <base64-encoded type-3-message>
else if (msg[8] == 3) {
off = 30;
length = msg[off + 17] * 256 + msg[off + 16];
offset = msg[off + 19] * 256 + msg[off + 18];
String remoteHost = new String(msg, offset, length);
length = msg[off + 1] * 256 + msg[off];
offset = msg[off + 3] * 256 + msg[off + 2];
String domain = new String(msg, offset, length);
for (int i = 0; i < domain.length(); i += 2)
loginDomain += domain.charAt(i);
length = msg[off + 9] * 256 + msg[off + 8];
offset = msg[off + 11] * 256 + msg[off + 10];
String username = new String(msg, offset, length);
for (int i = 0; i < username.length(); i += 2)
loginUser += username.charAt(i);
}
}
} catch (Exception se) {
log.error(loginUser + ", NTLM handshake exception:", se);
}