Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > STRUTS & Active Directory Query

Reply
Thread Tools

STRUTS & Active Directory Query

 
 
JavaNinna72
Guest
Posts: n/a
 
      12-14-2004
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;
}

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
active directory query using directorysearcher =?Utf-8?B?VGFzaA==?= ASP .Net 1 07-19-2005 05:41 PM
Active Directory Query Arvind P Rangan ASP .Net 1 02-24-2004 09:27 AM
Query Active Directory from ASP.NET Andrew Connell ASP .Net 0 01-16-2004 08:11 PM
NTLM credentials -> query Active Directory -> email address Jim Adams ASP .Net 1 01-07-2004 09:48 PM
Active Directory using LDAP query Marty Underwood ASP .Net 0 11-27-2003 02:00 AM



Advertisments