• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java HttpBasicAuthentication类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.springframework.http.HttpBasicAuthentication的典型用法代码示例。如果您正苦于以下问题:Java HttpBasicAuthentication类的具体用法?Java HttpBasicAuthentication怎么用?Java HttpBasicAuthentication使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



HttpBasicAuthentication类属于org.springframework.http包,在下文中一共展示了HttpBasicAuthentication类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: AuthenticatedRequest

import org.springframework.http.HttpBasicAuthentication; //导入依赖的package包/类
/**
 * Instantiates a new Authenticated request.
 *
 * @param requestReason         the request reason
 * @param context               the context
 * @param loadingMessage        the loading message
 * @param connectionInformation the connection information
 * @param userName              the user name
 * @param password              the password
 */
public AuthenticatedRequest(RequestReason requestReason, OnHttpRequestFinishedCallback context,
                            String loadingMessage, ConnectionInformation connectionInformation,
                            String userName, String password) {
    super(requestReason, context, loadingMessage, connectionInformation);
    this.userName = userName;
    this.password = password;

    // Set the username and password for creating a Basic Auth request
    authHeader = new HttpBasicAuthentication(userName, password);
    requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestEntity = new HttpEntity<Object>(requestHeaders);

    // Add the String message converter
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
}
 
开发者ID:andju,项目名称:findlunch,代码行数:27,代码来源:AuthenticatedRequest.java


示例2: doInBackground

import org.springframework.http.HttpBasicAuthentication; //导入依赖的package包/类
@Override
protected UserLoginResponse doInBackground(String... params) {
    EditText authCodeCtrl = (EditText) findViewById(R.id.authcode);
    String authCode = authCodeCtrl.getText().toString();
    List<String> cred = new ArrayList<String>();
    cred.add(authCode);
    UserLoginRequest request = new UserLoginRequest(controller.username, cred);
    HttpAuthentication authHeader = new HttpBasicAuthentication(controller.username, controller.password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setContentType(new MediaType("application", "json"));
    HttpEntity<Object> requestEntity = new HttpEntity<Object>(request, requestHeaders);
    RestTemplate restTemplate = new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    try {
        ResponseEntity<UserLoginResponse> response = restTemplate.exchange(params[0], HttpMethod.POST, requestEntity, UserLoginResponse.class);
        return response.getBody();
    } catch (Exception e) {
        Log.i("", e.toString());
    }
    return null;
}
 
开发者ID:bushidowallet,项目名称:bushido-android-app,代码行数:23,代码来源:CodeActivity.java


示例3: intercept

import org.springframework.http.HttpBasicAuthentication; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException {
    HttpHeaders headers = request.getHeaders();
    HttpAuthentication auth = new HttpBasicAuthentication(backendPreferences.userName().get(), backendPreferences.password().get());
    headers.setAuthorization(auth);
    return execution.execute(request, body);
}
 
开发者ID:thomasletsch,项目名称:moserp,代码行数:8,代码来源:BasicAuthorizationInterceptor.java


示例4: publish

import org.springframework.http.HttpBasicAuthentication; //导入依赖的package包/类
public static JSONObject publish(Collection<Event> events, String username,
    String password, String appKey) throws JsonProcessingException,
    IOException, Exception {

JSONObject statusJSONObject = new JSONObject();

JSONObject topNode = convertToJson(events);

final HttpBasicAuthentication authHeader = new HttpBasicAuthentication(
	username, password);

final HttpHeaders requestHeaders = new HttpHeaders();

requestHeaders.setAuthorization(authHeader);

requestHeaders.add("X-Mashape-Key",
	"E0yCNooETJmsh1J1S4me9PvLaZgXp1Ryh4LjsnsSSjbIYqOxYl");

requestHeaders.add("Content-Type", "application/json");

requestHeaders.setAccept(Collections
	.singletonList(MediaType.APPLICATION_JSON));

HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params,
	HTTP.DEFAULT_CONTENT_CHARSET);
HttpProtocolParams.setUseExpectContinue(params, true);

SchemeRegistry schReg = new SchemeRegistry();
schReg.register(new Scheme("https",
	SSLSocketFactory.getSocketFactory(), 443));

ClientConnectionManager conMgr = new ThreadSafeClientConnManager(
	params, schReg);

HttpClient client = new DefaultHttpClient(conMgr, params);

final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
factory.setHttpClient(client);

// Create a new RestTemplate instance
final RestTemplate restTemplate = new RestTemplate(factory);

restTemplate.getMessageConverters().add(
	new MappingJacksonHttpMessageConverter());

final String url = "https://twoencore-reaperfire-aka-geokoala-v1.p.mashape.com/rest/v1/public/accounts/"
	+ appKey + "/events";
 JsonNode featureCollectionJsonNode = null;
try {
    final ObjectMapper mapper = new ObjectMapper();

    featureCollectionJsonNode = mapper.readTree(topNode
	    .toString());

    final HttpEntity<JsonNode> entity = new HttpEntity<JsonNode>(
	    featureCollectionJsonNode, requestHeaders);

    trustSelfSignedSSL();

    final ResponseEntity<JsonNode> response = restTemplate.exchange(
	    url, HttpMethod.POST, entity, JsonNode.class);

    statusJSONObject.put("response", response);

    synchronized (events) {
	events.clear();
    }
} catch (final HttpClientErrorException ex) {
    StringWriter errors = new StringWriter();
    ex.printStackTrace(new PrintWriter(errors));
    statusJSONObject.put("url", url);
    statusJSONObject.put("error", errors.toString());
}

return statusJSONObject;

   }
 
开发者ID:VanitySoft,项目名称:geo-koala-android-client,代码行数:80,代码来源:PublisherServiceUtil.java


示例5: getHeaders

import org.springframework.http.HttpBasicAuthentication; //导入依赖的package包/类
@Override
public HttpHeaders getHeaders() {
    HttpHeaders headers = super.getHeaders();
    headers.setAuthorization(new HttpBasicAuthentication(mUsername, mPassword));
    return headers;
}
 
开发者ID:stairs,项目名称:intermine-android,代码行数:7,代码来源:GetUserTokenRequest.java



注:本文中的org.springframework.http.HttpBasicAuthentication类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LogSettingsDialog类代码示例发布时间:2022-05-22
下一篇:
Java RequiredAuthentication类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap