diff --git a/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java b/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java index aa5fd359..a8a7e898 100644 --- a/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java +++ b/client/src/main/java/org/apache/sqoop/client/request/ResourceRequest.java @@ -22,6 +22,7 @@ import org.apache.hadoop.security.SecurityUtil; import org.apache.hadoop.security.authentication.client.AuthenticationException; import org.apache.hadoop.security.authentication.client.ConnectionConfigurator; +import org.apache.hadoop.security.authentication.client.PseudoAuthenticator; import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.delegation.web.DelegationTokenAuthenticatedURL; import org.apache.log4j.Logger; @@ -65,6 +66,8 @@ protected String doHttpRequest(String strURL, String method, String data) { DataOutputStream wr = null; BufferedReader reader = null; try { +// This user name is only in simple mode. In Kerberos mode, this user name will be ignored by Sqoop server and user name in UGI which is authenticated by Kerberos server will be used instead. + strURL = addUsername(strURL); URL url = new URL(strURL); HttpURLConnection conn = new DelegationTokenAuthenticatedURL().openConnection(url, authToken); @@ -220,4 +223,10 @@ private Text getDelegationTokenService(String strURL) throws IOException { public DelegationTokenAuthenticatedURL.Token getAuthToken() { return authToken; } -} + + private String addUsername(String strUrl) { + String paramSeparator = (strUrl.contains("?")) ? "&" : "?"; + strUrl += paramSeparator + PseudoAuthenticator.USER_NAME + "=" + System.getProperty("user.name"); + return strUrl; + } +} \ No newline at end of file diff --git a/server/src/main/java/org/apache/sqoop/server/RequestContext.java b/server/src/main/java/org/apache/sqoop/server/RequestContext.java index d0963f5b..5324a0a0 100644 --- a/server/src/main/java/org/apache/sqoop/server/RequestContext.java +++ b/server/src/main/java/org/apache/sqoop/server/RequestContext.java @@ -18,7 +18,9 @@ package org.apache.sqoop.server; import org.apache.hadoop.security.authentication.client.PseudoAuthenticator; +import org.apache.hadoop.security.token.delegation.web.HttpUserGroupInformation; import org.apache.sqoop.common.SqoopException; +import org.apache.sqoop.security.AuthenticationManager; import org.apache.sqoop.server.common.ServerError; import javax.servlet.http.HttpServletRequest; @@ -67,7 +69,7 @@ public Method getMethod() { return Method.valueOf(request.getMethod()); } catch(IllegalArgumentException ex) { throw new SqoopException(ServerError.SERVER_0002, - "Unsupported HTTP method:" + request.getMethod(), ex); + "Unsupported HTTP method:" + request.getMethod(), ex); } } @@ -119,6 +121,10 @@ public Locale getAcceptLanguageHeader() { * @return Name of user sending the request */ public String getUserName() { - return request.getParameter(PseudoAuthenticator.USER_NAME); + if (AuthenticationManager.getAuthenticationHandler().isSecurityEnabled()) { + return HttpUserGroupInformation.get().getUserName(); + } else { + return request.getParameter(PseudoAuthenticator.USER_NAME); + } } }