【发布时间】: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