Jersey 客户端 API - 身份验证 [英] Jersey Client API - authentication

查看:47
本文介绍了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)

这篇关于Jersey 客户端 API - 身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆