STRUTS & Active Directory Query

Discussion in 'Java' started by JavaNinna72, Dec 14, 2004.

  1. JavaNinna72

    JavaNinna72 Guest

    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;
    }
    JavaNinna72, Dec 14, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marty Underwood

    Active Directory using LDAP query

    Marty Underwood, Nov 27, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    618
    Marty Underwood
    Nov 27, 2003
  2. Jim Adams
    Replies:
    1
    Views:
    3,700
    Tim Heuer
    Jan 7, 2004
  3. Andrew Connell

    Query Active Directory from ASP.NET

    Andrew Connell, Jan 16, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    700
    Andrew Connell
    Jan 16, 2004
  4. Arvind P Rangan

    Active Directory Query

    Arvind P Rangan, Feb 24, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    476
    Martin Dechev
    Feb 24, 2004
  5. =?Utf-8?B?VGFzaA==?=

    active directory query using directorysearcher

    =?Utf-8?B?VGFzaA==?=, Jul 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    716
    =?Utf-8?B?RWx0b24gVw==?=
    Jul 19, 2005
Loading...

Share This Page