【问题标题】:401 Returned when authenticate via HttpClient on WebLogic在 WebLogic 上通过 HttpClient 进行身份验证时返回 401
【发布时间】:2016-01-21 16:52:58
【问题描述】:

我在 WebLogic Application Server 12 中部署了基于 REST 的服务,它使用 Spring Security 使用 BASIC Auth 进行身份验证。以前我发现 WebLogic 有一个错误,如果请求中包含授权标头,它会拦截调用。

我找到了一个非常有用的链接,它通过在 WebLogic 的 config.xml 中禁用 <enforce-valid-basic-auth-credentials>false</enforce-valid-basic-auth-credentials> 这个来解决这个问题。现在,如果我通过 POSTMan 访问我的服务,它工作得很好,Spring 处理了安全性。

在此之后,我编写了一些使用 Apache Common HttpClient 库调用我的服务的自动化测试,但我不断从 WebLogic 获得 401 Unauthorized。我的客户端代码如下;

httpClient = new HttpClient();
        httpClient.getState().setCredentials(
            new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(
                    getTestUsername(config.getUsername()), 
                    getTestPassword(config.getPassword()))
            );

我尝试将 auth pref 设置为 Basic,将 Authorization 标头添加到我的请求中,甚至将 auth 设置为 Preemptoive 以使一切都保持不变。

我确信 Weblogic 正在以某种方式拦截我来自 Java Standalone 客户端的调用!因为在响应头中我得到'realm:weblogic',它不正确,因为它应该是'realm:Spring Security Application',更奇怪的是,我能够使用相同的安全凭证从POSTMan访问相同的URL。我错过了什么吗?

【问题讨论】:

    标签: spring-security weblogic httpclient


    【解决方案1】:

    是的,我确认 Weblogic 会拦截您的电话。

    您必须在 weblogic config.xml 文件中强制 <enforce-valid-basic-auth-credentials> 标记为 false。

    请看Error adding enforce-valid-basic-auth-credentials to config.xmlhttp://www.dba-oracle.com/t_weblogic_bypass_basic_authentication.htm

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-20
      • 2020-07-18
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多