weblogic 12c response.flushBuffer()问题

时间:2014-08-11 07:05:52

标签: ntlm weblogic12c

我在weblogic 12c上部署的Web应用程序中有一个ntlm过滤器,用于检索已记录的用户客户端名称,以便自动对其进行身份验证。

我的过滤器类如下。

问题在于weblogic response.flushBuffer()什么也没做。 浏览器的状态页面为401。

此代码适用于Jetty Http Server。

有关如何解决这个问题的想法吗?

谢谢!

package com.asf.ntlm.filter;  


import java.io.IOException;  


import javax.servlet.FilterChain;  
import javax.servlet.FilterConfig;  
import javax.servlet.ServletException;  
import javax.servlet.ServletRequest;  
import javax.servlet.ServletResponse;  
import javax.servlet.http.HttpServletRequest;  
import javax.servlet.http.HttpServletResponse;  


import jcifs.ntlmssp.Type3Message;  


public class AsfNtlmFilter implements javax.servlet.Filter {  


  private FilterConfig filterConfig = null;  


  public void init(FilterConfig filterConfig) throws ServletException {  
  this.filterConfig = filterConfig;  
  }  


  @Override  
  public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {  
  HttpServletRequest request = (HttpServletRequest) req;  
  HttpServletResponse response = (HttpServletResponse) res;  


  System.out.println("Ntlm filter!!!");  


  String username = null;  
  // first, get the user agent  
  String useragent = request.getHeader("user-agent");  
  // if you're using IE, you can continue  
  // Always do the ntlm check (for IE POST back)  
  try {  
  String auth = request.getHeader("Authorization");  
  if (auth == null) {  
  response.setHeader("WWW-Authenticate", "NTLM");  
  response.setStatus(response.SC_UNAUTHORIZED);  
  response.setContentLength(0);  
  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));  
  response.setStatus(response.SC_UNAUTHORIZED);  
  response.setContentLength(0);  
  response.flushBuffer();  
  return;  
  } else if (msg[8] == 3) {  
  // Did Authentication Succeed? All this is always  
  // printed.  


  Type3Message type3 = new Type3Message(msg);  


  System.out.println("osUser: " + type3.getUser());  
  System.out.println("osRemoteHost: + " + type3.getWorkstation());  
  System.out.println("osDomain: " + type3.getDomain());  


  }  
  }  
  } catch (Exception e) {  
  System.out.println(e);  
  }  
  // System.out.println("Suc);  


  try {  
  chain.doFilter(req, res);  
  } catch (IOException e) {  
  System.out.println(e);  
  } catch (ServletException e) {  
  System.out.println(e);  
  }  
  }  


  @Override  
  public void destroy() {  
  filterConfig = null;  
  }  


}  

1 个答案:

答案 0 :(得分:0)

这是Weblogic的一个问题。

我重新安装它,现在效果很好。