小编Mor*_*ner的帖子

使用Resteasy客户端进行基本身份验证

我正在尝试使用REST对我的jboss上运行的登录模块执行基本身份验证.我已经找到了StackOverflow主题,该主题解释了如何使用凭据进行身份验证.

RESTEasy客户端框架身份验证凭据

这不起作用.分析与Wireshark建立的连接我无法看到带有Authorization:Basic的HTTP包.经过更多的研究,我发现了这篇文章http://docs.jboss.org/resteasy/docs/2.3.3.Final/userguide/html/RESTEasy_Client_Framework.html,它描述了如何ApacheHttpClient4Executor从resteasy中添加基本​​身份验证.

// 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 = …
Run Code Online (Sandbox Code Playgroud)

basic-authentication resteasy

7
推荐指数
3
解决办法
2万
查看次数

标签 统计

basic-authentication ×1

resteasy ×1