small medium large xlarge

08 Apr 2011, 07:27
Polappan (1 post)


I am having a strange issue with autocompleter in JSP when application is authenticated through NTLM. After NTLM authentication code is passed and re-directed to JSP page, my autocompleter doesn’t work at all. I am using the following for autocompleter Ajax.Autocompleter(“emp”,”autocomp”,”getajaxdata.jsp”); For reference

If I remove the NTLM authentication code from my application, then autocompleter would work. How can I resolve this issue? Strangely this issue only occurs in IE, in firefox it works fine.

If I remove the following line from NTLM authentication code, then issue doesn’t occur response.sendError(response.SC_UNAUTHORIZED); Why this line is causing the problem?

Any help is highly appreciable.


Code I used for NTLM authentication in servlet

public void service(HttpServletRequest request, 
                        HttpServletResponse response) throws ServletException, IOException {response.setContentType(CONTENT_TYPE);
        * Coding to find out the current logged in user name
        String username="";
        String auth = request.getHeader("Authorization");
        if (auth == null)
        response.setHeader("WWW-Authenticate", "NTLM");
        if (auth.startsWith("NTLM "))
        byte[] msg = new sun.misc.BASE64Decoder().decodeBuffer(auth.substring(5));
        int off = 0, length, offset;
        if (msg[8] == 1)
        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).trim());
        else if (msg[8] == 3)
        off = 30;

        length = msg[off+9]*256 + msg[off+8];
        offset = msg[off+11]*256 + msg[off+10];
        username = new String(msg, offset, length);
         * Coding for removing extra white spaces from the user name
        String windname="";
        String  windname1=username.replaceAll(" ",null  );
        int l=username.length();           
        int i=0;
        while (i<l)
          if (username.charAt(i)==0)
              char temp=username.charAt(i);