STRUTS & Active Directory Query

J

JavaNinna72

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_UNAUTHORIZED);
response.setHeader("WWW-Authenticate", "NTLM");
return userID;
}


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

try {
msg = new
sun.misc.BASE64Decoder().decodeBuffer(auth.substring(
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_UNAUTHORIZED);
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);
}
}
userID = userNameBuffer.toString();
}

return userID;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top