代码之家  ›  专栏  ›  技术社区  ›  Marcel Stör

验证器#getPasswordAuthentication在Weblogic中返回basic而不是ntlm

  •  0
  • Marcel Stör  · 技术社区  · 8 年前

    除了Weblogic Server之外,我们在所有环境中都可以使用Java对MS Sharepoint进行NTLM身份验证。

    在WLS中我们可以看到 Authenticator#getPasswordAuthentication

    相关代码如下:

    NtlmAuthenticator authenticator = new NtlmAuthenticator(configParameters.getNtlmUsername(),
        configParameters.getNtlmPassword(), configParameters.getNtlmDomain());
    
    log.info("JVM running with security manager enabled: {}", System.getSecurityManager() != null);
    // requires NetPermission 'setDefaultAuthenticator' if security manager enabled
    Authenticator.setDefault(authenticator);
    
    
    public class NtlmAuthenticator extends Authenticator {
    
      private char[] password;
      private String userAuthentication;
    
      public NtlmAuthenticator(String username, String password, String domain) {
        userAuthentication = username;
        if (StringUtils.isNotBlank(domain)) {
          // According to
          // https://msdn.microsoft.com/en-us/library/windows/desktop/aa380525(v=vs.85).aspx
          userAuthentication = domain + "\\" + username;
        }
        this.password = password.toCharArray();
      }
    
      @Override
      public PasswordAuthentication getPasswordAuthentication() {
        log.debug("Scheme: '{}'", getRequestingScheme());
        return new PasswordAuthentication(userAuthentication, password);
      }
    }
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   Marcel Stör    8 年前

    简短回答1

    使用Apache httpclient的修补版本: https://issues.apache.org/jira/browse/HTTPCLIENT-1881

    简短回答2

    设置 -DUseSunHttpHandler=true 启动WebLogic Server时。一些参考文献: https://docs.oracle.com/en/cloud/paas/javase-cloud/csjsu/you-should-now-set-sun-http-handlers-property-value-true-when-making-outbound-http-s-calls.html , Impact/Risk on enable -DuseSunHttpHandler on Weblogic10.3.0 & https://stackoverflow.com/a/27931816/131929 (都有点老)。

    在(远程)调试过程中,我注意到我没有 java.net.http.* weblogic .net.http.* . WTF我想。。。是的,WLS确实取代了标准的Sun网络堆栈 默认情况下