Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   STRUTS & Active Directory Query (http://www.velocityreviews.com/forums/t139242-struts-and-active-directory-query.html)

JavaNinna72 12-14-2004 04:20 PM

STRUTS & Active Directory Query
 
I'm having a strange problem. I'm executing the following code in a
utility class to extract the user's Active Directory Id from the
request object. However, when this is done - the beanUtils's
responsible for loading the FormBean cease to function on doPost
requests. I have noticed that anytime a header is changed in the
response object, the client re-sends the request.

Somehow, this is messing up the normal behavior of struts:

Any Ideas are appreciated :

private static String getLogonID(HttpServletResponse response,
HttpServletRequest request) {
String userID = null;
String auth = request.getHeader("Authorization");


if (auth == null) {
response.setStatus(HttpServletResponse.SC_UNAUTHOR IZED);
response.setHeader("WWW-Authenticate", "NTLM");
return userID;
}


if (auth.startsWith("NTLM ")) {
byte[] msg = null;

try {
msg = new
sun.misc.BASE64Decoder().decodeBuffer(auth.substri ng(
5));
} catch (IOException e) {

e.printStackTrace();
}

int off = 0;
int length;
int offset;
String s;

if (msg[8] == 1) { // first step of authentication
off = 18;
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, // this line is
'nonce'
z, z, z, z, z, z, z, z
};

// remove next lines if you want see the result of
first step

response.setStatus(HttpServletResponse.SC_UNAUTHOR IZED);
response.setHeader("WWW-Authenticate",
"NTLM " +
new
sun.misc.BASE64Encoder().encodeBuffer(msg1).trim() );

return userID;
} else if (msg[8] == 3) {
off = 30;
length = (msg[off + 17] * 256) + msg[off + 16];
offset = (msg[off + 19] * 256) + msg[off + 18];
s = new String(msg, offset, length);
} else {
return userID;
}

length = (msg[off + 1] * 256) + msg[off];
offset = (msg[off + 3] * 256) + msg[off + 2];
s = new String(msg, offset, length);

length = (msg[off + 9] * 256) + msg[off + 8];
offset = (msg[off + 11] * 256) + msg[off + 10];
s = new String(msg, offset, length);
char[] userName = s.toCharArray();
StringBuffer userNameBuffer = new StringBuffer();
for (int i = 0; i<userName.length;i++){
if(i%2==0 ){
userNameBuffer.append(userName[i]);
}
}
userID = userNameBuffer.toString();
}

return userID;
}



All times are GMT. The time now is 02:26 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.