Jersey 客户端 API - 身份验证

Jersey 客户端 API - 身份验证

问题描述:

我正在使用 Jersey 客户端 API 将 SOAP 请求提交到 JAX-WS 网络服务.默认情况下,Jersey 在受到挑战时以某种方式使用我的 Windows Nt 凭据进行身份验证.谁能解释 Jersey 在代码中的位置?它可以被覆盖吗?

I'm using the Jersey client API to submit SOAP requests to a JAX-WS webservice. By default Jersey is somehow using my Windows Nt credentials for authentication when challenged. Can anyone explain where Jersey does this in the code? And can it be overriden?

我尝试使用 HTTPBasicAuthFilter 并在客户端上添加为过滤器.我还尝试将我的凭据添加到 WebResoruce queryParams 字段,但都没有被选中.

I have tried using HTTPBasicAuthFilter and adding as a filter on the Client. I have also tried adding my credentials to the WebResoruce queryParams field however neither are being picked up.

起初我按照 Jersey 用户指南中的说明进行工作

At first I got this working as documented in the Jersey User guide

Authenticator.setDefault (authinstance);

但是我不喜欢这个,因为它依赖于设置全局身份验证器.经过一番研究,我发现 Jersey 有一个 HTTPBasicAuthFilter,它更易于使用.

However I did not like this as it relied on setting a global authenticator. After some research I discovered that Jersey has a HTTPBasicAuthFilter which is even easier to use.

Client c = Client.create();
c.addFilter(new HTTPBasicAuthFilter(user, password));

见:https://jersey.github.io/nonav/apidocs/1.10/jersey/com/sun/jersey/api/client/filter/HTTPBasicAuthFilter.htmlhttps://jersey.github.io/nonav/apidocs/1.10/jersey/com/sun/jersey/api/client/filter/Filterable.html#addFilter(com.sun.jersey.api.client.filter.ClientFilter)