YARN-9385. Fixed ApiServiceClient to use current UGI.

Contributed by Eric Yang
This commit is contained in:
Eric Yang 2019-03-18 13:16:34 -04:00
parent 5446e3cb8a
commit 19b22c4385
2 changed files with 17 additions and 5 deletions

View File

@ -151,7 +151,7 @@ public class ApiServiceClient extends AppAdminClient {
* @return URI to API Service
* @throws IOException
*/
private String getServicePath(String appName) throws IOException {
protected String getServicePath(String appName) throws IOException {
String url = getRMWebAddress();
StringBuilder api = new StringBuilder();
api.append(url)
@ -203,12 +203,15 @@ public class ApiServiceClient extends AppAdminClient {
return api.toString();
}
private void appendUserNameIfRequired(StringBuilder builder) {
private void appendUserNameIfRequired(StringBuilder builder)
throws IOException {
Configuration conf = getConfig();
if (conf.get("hadoop.http.authentication.type").equalsIgnoreCase(
"simple")) {
if (conf.get("hadoop.http.authentication.type")
.equalsIgnoreCase("simple")) {
String username = UserGroupInformation.getCurrentUser()
.getShortUserName();
builder.append("?user.name=").append(UrlEncoded
.encodeString(System.getProperty("user.name")));
.encodeString(username));
}
}

View File

@ -27,6 +27,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.common.collect.Lists;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.yarn.exceptions.YarnException;
import org.eclipse.jetty.server.Server;
@ -310,5 +311,13 @@ public class TestApiServiceClient {
}
}
@Test
public void testNoneSecureApiClient() throws IOException {
String url = asc.getServicePath("/foobar");
assertTrue("User.name flag is missing in service path.",
url.contains("user.name"));
assertTrue("User.name flag is not matching JVM user.",
url.contains(System.getProperty("user.name")));
}
}