From cf3f81aef7c32019d70cbce218a64a03276268f0 Mon Sep 17 00:00:00 2001 From: Jakob Buchgraber Date: Thu, 8 Feb 2018 12:19:57 -0800 Subject: remote: Add support for HTTP Basic Auth Closes #4609. PiperOrigin-RevId: 185032751 --- .../build/lib/remote/blobstore/http/AbstractHttpHandler.java | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main/java/com/google/devtools/build/lib') diff --git a/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandler.java b/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandler.java index 5b7df8a106..fc8c14a005 100644 --- a/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandler.java +++ b/src/main/java/com/google/devtools/build/lib/remote/blobstore/http/AbstractHttpHandler.java @@ -14,10 +14,13 @@ package com.google.devtools.build.lib.remote.blobstore.http; import com.google.auth.Credentials; +import com.google.common.base.Charsets; +import com.google.common.io.BaseEncoding; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelOutboundHandler; import io.netty.channel.ChannelPromise; import io.netty.channel.SimpleChannelInboundHandler; +import io.netty.handler.codec.http.HttpHeaderNames; import io.netty.handler.codec.http.HttpObject; import io.netty.handler.codec.http.HttpRequest; import java.io.IOException; @@ -53,6 +56,12 @@ abstract class AbstractHttpHandler extends SimpleChannelIn } protected void addCredentialHeaders(HttpRequest request, URI uri) throws IOException { + String userInfo = uri.getUserInfo(); + if (userInfo != null) { + String value = BaseEncoding.base64Url().encode(userInfo.getBytes(Charsets.UTF_8)); + request.headers().set(HttpHeaderNames.AUTHORIZATION, "Basic " + value); + return; + } if (credentials == null || !credentials.hasRequestMetadata()) { return; } -- cgit v1.2.3