List of usage examples for com.google.common.net HttpHeaders AUTHORIZATION
String AUTHORIZATION
To view the source code for com.google.common.net HttpHeaders AUTHORIZATION.
Click Source Link
From source file:com.cdancy.bitbucket.rest.filters.BitbucketAuthenticationFilter.java
@Override public HttpRequest filter(final HttpRequest request) throws HttpException { if (creds.authType() == AuthenticationType.Anonymous) { return request; } else {// w w w .j a v a2 s . co m final String authHeader = creds.authType() + " " + creds.authValue(); return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, authHeader).build(); } }
From source file:org.jclouds.b2.binders.UploadFileBinder.java
@Override public <R extends HttpRequest> R bindToRequest(R request, Map<String, Object> postParams) { UploadUrlResponse uploadUrl = (UploadUrlResponse) postParams.get("uploadUrl"); String fileName = (String) postParams.get("fileName"); String contentSha1 = (String) postParams.get("contentSha1"); if (contentSha1 == null) { contentSha1 = "do_not_verify"; }//w w w . jav a 2 s.c o m Map<String, String> fileInfo = (Map<String, String>) postParams.get("fileInfo"); HttpRequest.Builder builder = request.toBuilder().endpoint(uploadUrl.uploadUrl()) .replaceHeader(HttpHeaders.AUTHORIZATION, uploadUrl.authorizationToken()) .replaceHeader(B2Headers.CONTENT_SHA1, contentSha1) .replaceHeader(B2Headers.FILE_NAME, escaper.escape(fileName)); for (Map.Entry<String, String> entry : fileInfo.entrySet()) { builder.replaceHeader(B2Headers.FILE_INFO_PREFIX + entry.getKey(), escaper.escape(entry.getValue())); } return (R) builder.build(); }
From source file:org.graylog2.rest.RemoteInterfaceProvider.java
public <T> T get(Node node, final String authorizationToken, Class<T> interfaceClass) { final OkHttpClient okHttpClient = this.okHttpClient.newBuilder().addInterceptor(chain -> { final Request original = chain.request(); Request.Builder builder = original.newBuilder() .header(HttpHeaders.ACCEPT, MediaType.JSON_UTF_8.toString()) .method(original.method(), original.body()); if (authorizationToken != null) { builder = builder.header(HttpHeaders.AUTHORIZATION, authorizationToken); }/*from www . java2 s . c o m*/ return chain.proceed(builder.build()); }).build(); final Retrofit retrofit = new Retrofit.Builder().baseUrl(node.getTransportAddress()) .addConverterFactory(JacksonConverterFactory.create(objectMapper)).client(okHttpClient).build(); return retrofit.create(interfaceClass); }
From source file:com.sector91.wit.http.BasicAuthInterceptor.java
@Override public void intercept(Request request, Response response) throws HttpException { final String auth = request.getValue(HttpHeaders.AUTHORIZATION); try {/* w w w . j av a 2s . c o m*/ if (auth.startsWith(PREFIX)) { final String b64 = auth.split("\\s+")[1]; final String parsed = new String(BaseEncoding.base64().decode(b64), Charsets.UTF_8); final String[] parts = parsed.split("[:]"); if (!authenticator.auth(parts[0], parts[1])) throw new HttpException(Status.UNAUTHORIZED).withHeader(HttpHeaders.WWW_AUTHENTICATE, "Basic realm=\"" + realm + "\""); } } catch (RuntimeException ex) { } }
From source file:org.jclouds.b2.filters.RequestAuthorization.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { Authorization auth = this.auth.get(); // Replace with API URL URI endpoint = request.getEndpoint(); endpoint = URI.create(auth.apiUrl() + (endpoint.getPort() == -1 ? "" : ":" + endpoint.getPort()) + endpoint.getPath() + (endpoint.getQuery() == null ? "" : "?" + endpoint.getQuery())); request = request.toBuilder().endpoint(endpoint) .replaceHeader(HttpHeaders.AUTHORIZATION, auth.authorizationToken()).build(); return request; }
From source file:org.jclouds.b2.filters.RequestAuthorizationDownload.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { Authorization auth = this.auth.get(); // Replace with download URL URI endpoint = request.getEndpoint(); endpoint = URI.create(auth.downloadUrl() + (endpoint.getPort() == -1 ? "" : ":" + endpoint.getPort()) + endpoint.getRawPath() + (endpoint.getQuery() == null ? "" : "?" + endpoint.getQuery())); request = request.toBuilder().endpoint(endpoint) .replaceHeader(HttpHeaders.AUTHORIZATION, auth.authorizationToken()).build(); return request; }
From source file:com.netflix.genie.client.security.oauth2.impl.OAuth2SecurityInterceptor.java
@Override public Response intercept(final Chain chain) throws IOException { final AccessToken accessToken = this.tokenFetcher.getToken(); final Request newRequest = chain.request().newBuilder().addHeader(HttpHeaders.AUTHORIZATION, accessToken.getTokenType() + " " + accessToken.getAccessToken()).build(); log.debug("Sending request {} on {} {} {}", newRequest.url(), chain.connection(), newRequest.headers()); return chain.proceed(newRequest); }
From source file:org.jclouds.b2.filters.B2RetryHandler.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { HttpRequest.Builder<?> builder = request.toBuilder(); // B2 requires retrying on a different storage node for uploads String path = request.getEndpoint().getPath(); if (path.startsWith("/b2api/v1/b2_upload_file")) { String bucketId = path.split("/")[4]; UploadUrlResponse uploadUrl = api.getObjectApi().getUploadUrl(bucketId); builder.endpoint(uploadUrl.uploadUrl()).replaceHeader(HttpHeaders.AUTHORIZATION, uploadUrl.authorizationToken()); } else if (path.startsWith("/b2api/v1/b2_upload_part")) { String fileId = path.split("/")[4]; GetUploadPartResponse uploadUrl = api.getMultipartApi().getUploadPartUrl(fileId); builder.endpoint(uploadUrl.uploadUrl()).replaceHeader(HttpHeaders.AUTHORIZATION, uploadUrl.authorizationToken()); }/* ww w.ja v a2s . co m*/ return builder.build(); }
From source file:com.cdancy.etcd.rest.filters.EtcdAuthentication.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { Credentials currentCreds = checkNotNull(creds.get(), "credential supplier returned null"); if (currentCreds.credential != null && currentCreds.credential.trim().length() > 0) { /*//from ww w . j a va2s . c om * client can pass in credential string in 1 of 2 ways: 1.) As colon * delimited username and password: admin:password 2.) As base64 * encoded value of colon delimited username and password: * YWRtaW46cGFzc3dvcmQ= */ String foundCredential = currentCreds.credential; if (foundCredential.contains(":")) { foundCredential = base64().encode(foundCredential.getBytes()); } if (isBase64Encoded(foundCredential)) { return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, "Basic " + foundCredential).build(); } else { throw new IllegalArgumentException( "Credential is not in base64 format: credential=" + foundCredential); } } else { return request.toBuilder().build(); } }
From source file:com.cdancy.bitbucket.rest.filters.BitbucketAuthentication.java
@Override public HttpRequest filter(HttpRequest request) throws HttpException { Credentials currentCreds = checkNotNull(creds.get(), "credential supplier returned null"); if (currentCreds.credential != null && currentCreds.credential.trim().length() > 0) { /*/* w w w. j av a 2s . c om*/ * client can pass in credential string in 1 of 2 ways: * * 1.) As colon delimited username and password: admin:password * * 2.) As base64 encoded value of colon delimited username and * password: YWRtaW46cGFzc3dvcmQ= * */ String foundCredential = currentCreds.credential; if (foundCredential.contains(":")) { foundCredential = base64().encode(foundCredential.getBytes()); } if (isBase64Encoded(foundCredential)) { return request.toBuilder().addHeader(HttpHeaders.AUTHORIZATION, "Basic " + foundCredential).build(); } else { throw new IllegalArgumentException( "Credential is not in base64 format: credential=" + foundCredential); } } else { return request.toBuilder().build(); } }