【问题标题】:How do I access a password-protected WSDL using JAXWS without using default Authenticator?如何在不使用默认身份验证器的情况下使用 JAXWS 访问受密码保护的 WSDL?
【发布时间】:2010-08-19 09:45:35
【问题描述】:

下面的wsdlLocation 受密码保护,但偏执狂让我对为应用程序设置默认身份验证器感到不舒服。如何在不使用默认身份验证器的情况下设置身份验证?

protected Orders getOrdersPort(String wsdlLocation, String namespaceURI) {
    Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication("username", "password".toCharArray());
        }
    });
    OrdersService service = new OrdersService(createUrlThrowRuntimeException(wsdlLocation), new QName(namespaceURI,
            "OrdersService"));
    Orders ordersPort = service.getOrdersSoap12();
    setConnectionTimeout(ordersPort);
    return ordersPort;
}

【问题讨论】:

  • 究竟是什么让你偏执?
  • 两件事:我不希望凭据在应用程序的其他地方错误地对应用程序进行身份验证。我不想错误地将凭据暴露给外界。 IE。通过 http 而不是 https 发送它们,或者发送到不受信任的服务。一般来说,我对默认身份验证器的了解不够,无法相信我总是安全地使用它。
  • Authenticator 为您提供了各种方法来确定您将数据发送到何处:getRequestingURL() 可能对您来说是最重要的。
  • 好的,所以您建议我使用身份验证器,但将其限制为我想要的 URL。听起来不错,谢谢!
  • 使用默认身份验证器还有另一个潜在问题,描述为here。因此,一旦成功进行身份验证尝试,您可能无法覆盖凭据。

标签: java web-services jax-ws


【解决方案1】:

一种解决方法当然是将 wsdl 下载到本地文件并改用该文件。不过,不必这样做就好了。

【讨论】:

    猜你喜欢
    • 2020-12-08
    • 2015-12-20
    • 2018-03-31
    • 2021-07-26
    • 1970-01-01
    • 2019-04-27
    • 2012-09-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多