Java 类org.springframework.http.HttpBasicAuthentication 实例源码

项目:findlunch    文件:AuthenticatedRequest.java   
/**
 * 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());
}
项目:bushido-android-app    文件:CodeActivity.java   
@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;
}
项目:bushido-android-app    文件:CodeActivity.java   
@Override
protected Void doInBackground(String... params) {
    Token2FARequest request = new Token2FARequest(controller.username, true);
    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 {
        restTemplate.exchange(params[0], HttpMethod.POST, requestEntity, Response.class);
    } catch (Exception e) {
    }
    return null;
}
项目:moserp    文件:BasicAuthorizationInterceptor.java   
@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);
}
项目:geo-koala-android-client    文件:PublisherServiceUtil.java   
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;

   }
项目:intermine-android    文件:GetUserTokenRequest.java   
@Override
public HttpHeaders getHeaders() {
    HttpHeaders headers = super.getHeaders();
    headers.setAuthorization(new HttpBasicAuthentication(mUsername, mPassword));
    return headers;
}