在JAVA中禁用默认NTLM身份验证

在JAVA中禁用默认NTLM身份验证,java,exchangewebservices,ntlm,tibco-business-works,ntlm-authentication,Java,Exchangewebservices,Ntlm,Tibco Business Works,Ntlm Authentication,我使用下面的代码作为NTLM的代理。但是,在生产代码中,要么使用登录使用的计算机,要么使用exchange服务端的计算机名称,而不是代码中指定的用户。 请有人帮助禁用默认NTLM身份验证,让代码只传递通过NTLM代码传递的内容。 由于产品限制,我只能使用下面的身份验证类,有没有办法禁用默认身份验证并只发送代码中指定的NTLM import java.io.IOException; import java.io.InputStream; import java.io.InputStre

我使用下面的代码作为NTLM的代理。但是,在生产代码中,要么使用登录使用的计算机,要么使用exchange服务端的计算机名称,而不是代码中指定的用户。 请有人帮助禁用默认NTLM身份验证,让代码只传递通过NTLM代码传递的内容。 由于产品限制,我只能使用下面的身份验证类,有没有办法禁用默认身份验证并只发送代码中指定的NTLM

  import java.io.IOException;
  import java.io.InputStream;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  import java.net.Authenticator;
  import java.net.CookieHandler;
  import java.net.CookieManager;
  import java.net.CookiePolicy;
  import java.net.MalformedURLException;
  import java.net.PasswordAuthentication;
  import java.net.URL;
  import java.net.URLConnection  
  
  public class DoNTLMDo_NTLM{

   protected String stringURL = "";
   protected String SoapAction = "";
   protected String SOAPxml = "";
   protected String UserName = "";
   protected String Password = "";
   protected String Domain = "";
   protected String ContentType = "";
   protected String charset = "";
   protected String Reply_SOAPxml = "";
   public String getstringURL() {
       return stringURL;
   }
   public void setstringURL(String val) {
       stringURL = val;
   }
   public String getSoapAction() {
       return SoapAction;
   }
   public void setSoapAction(String val) {
       SoapAction = val;
   }
   public String getSOAPxml() {
       return SOAPxml;
   }
   public void setSOAPxml(String val) {
       SOAPxml = val;
   }
   public String getUserName() {
       return UserName;
   }
   public void setUserName(String val) {
       UserName = val;
   }
   public String getPassword() {
       return Password;
   }
   public void setPassword(String val) {
       Password = val;
   }
   public String getDomain() {
       return Domain;
   }
   public void setDomain(String val) {
       Domain = val;
   }
   public String getContentType() {
       return ContentType;
   }
   public void setContentType(String val) {
       ContentType = val;
   }
   public String getcharset() {
       return charset;
   }
   public void setcharset(String val) {
       charset = val;
   }
   public String getReply_SOAPxml() {
       return Reply_SOAPxml;
   }
   public void setReply_SOAPxml(String val) {
       Reply_SOAPxml = val;
   }
  
   public ProxyDoNTLMDo_NTLM() {
   }
   public void invoke() throws Exception {
      CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
      Authenticator.setDefault(new MyAuthenticator(getDomain()+"\\"+  getUserName(),  getPassword()));
   try {
       URL url = new URL( getstringURL());     
       URLConnection connection = url.openConnection();
          connection.setDoInput(true);
          connection.setDoOutput(true);
               
          connection.setReadTimeout(50000);
          connection.setConnectTimeout(50000);
               
          connection.setUseCaches(false);
          connection.setDefaultUseCaches(false);
               
          connection.setRequestProperty("Content-Type", getContentType());
          connection.setRequestProperty("SOAPAction", getSoapAction());
               
          OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
          writer.write(getSOAPxml());
          writer.flush();
          writer.close();
               
          InputStream is = connection.getInputStream();
          InputStreamReader isr = new InputStreamReader(is, getcharset());
          BufferedReader br = new BufferedReader(isr);
          while (true) {
              String s = br.readLine();
              if (s == null)
                  break;
                  setReply_SOAPxml(s); //System.out.println(s);
          }
              // System.out.println("Done");
       } catch (MalformedURLException e) {
           // TODO Auto-generated catch block
           //e.printStackTrace();
       } catch (IOException e) {
           // TODO Auto-generated catch block
           //e.printStackTrace();
       }
   }   
  
  class MyAuthenticator extends Authenticator {
      private String httpUsername;
      private String httpPassword;
  
      public MyAuthenticator(String httpUsername, String httpPassword) {
          this.httpUsername = httpUsername;
          this.httpPassword = httpPassword;
      }
  
      @Override
      protected PasswordAuthentication getPasswordAuthentication() {
          return new PasswordAuthentication(httpUsername, httpPassword.toCharArray());
      }
  }
  
  }