【发布时间】:2014-04-01 11:06:22
【问题描述】:
我正在尝试使用 REST 对在我的 jboss 上运行的登录模块执行基本身份验证。我已经找到了一个 StackOverflow 主题,它解释了如何使用凭据进行身份验证。
RESTEasy client framework authentication credentials
这不起作用。分析与 Wireshark 建立的连接我无法看到带有 Authorization: Basic 的 HTTP 包。经过更多研究,我发现这篇文章 http://docs.jboss.org/resteasy/docs/2.3.3.Final/userguide/html/RESTEasy_Client_Framework.html 描述了如何从 resteasy 将基本身份验证附加到 ApacheHttpClient4Executor。
// Configure HttpClient to authenticate preemptively
// by prepopulating the authentication data cache.
// 1. Create AuthCache instance
AuthCache authCache = new BasicAuthCache();
// 2. Generate BASIC scheme object and add it to the local auth cache
BasicScheme basicAuth = new BasicScheme();
authCache.put("com.bluemonkeydiamond.sippycups", basicAuth);
// 3. Add AuthCache to the execution context
BasicHttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.AUTH_CACHE, authCache);
// 4. Create client executor and proxy
httpClient = new DefaultHttpClient();
ApacheHttpClient4Executor executor = new ApacheHttpClient4Executor(httpClient, localContext);
client = ProxyFactory.create(BookStoreService.class, url, executor);
但这也不起作用。没有描述如何将基本身份验证的用户名和密码附加到构造中。为什么该信息与来自httpcomponent 的任何类都没有关联?
【问题讨论】:
标签: basic-authentication resteasy