JSP 中的自动完成程序无法使用 NTLM 代码

发布于 2024-10-27 04:16:08 字数 2416 浏览 0 评论 0原文

当应用程序通过 NTLM 进行身份验证时,我在 JSP 中的自动完成程序方面遇到了一个奇怪的问题。 NTLM 身份验证代码通过并重定向到 JSP 页面后,我的自动完成器根本不起作用。我正在使用以下自动完成器 Ajax.Autocompleter("emp","autocomp","getajaxdata.jsp");
供参考

如果我从应用程序中删除 NTLM 身份验证代码,则自动完成程序会起作用的。 我该如何解决这个问题?奇怪的是这个问题只出现在IE中,在firefox中却正常。

任何帮助都是非常值得赞赏的。

代码

我在 servlet 中用于 NTLM 身份验证的

 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.setStatus(response.SC_UNAUTHORIZED);
        response.setHeader("WWW-Authenticate", "NTLM");
        response.flushBuffer();
        return;
        }
        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());
        response.sendError(response.SC_UNAUTHORIZED);
        return;
        }
        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)
          {
          }
          else
          {
              char temp=username.charAt(i);
              windname=windname+temp;
          }
          i++;
        }

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.

Any help is highly appreciable.

Regards

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.setStatus(response.SC_UNAUTHORIZED);
        response.setHeader("WWW-Authenticate", "NTLM");
        response.flushBuffer();
        return;
        }
        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());
        response.sendError(response.SC_UNAUTHORIZED);
        return;
        }
        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)
          {
          }
          else
          {
              char temp=username.charAt(i);
              windname=windname+temp;
          }
          i++;
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-11-03 04:16:08

我遇到了类似的问题,我发现了这个:

发布了空数据(零星)

如果您四处搜索... NTLM 做了一些有趣的事情:

有关 NTLM 的更多信息

I am having similar problems and I found this:

posted with empty data (sporadical)

If you do searching around... NTLM does some funny things:

Some more info on NTLM

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文