|
@@ -94,6 +94,8 @@ import org.mortbay.util.MultiException;
|
|
|
import com.google.common.base.Preconditions;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import com.sun.jersey.spi.container.servlet.ServletContainer;
|
|
|
+import static org.apache.hadoop.fs.CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER;
|
|
|
+import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_HTTP_STATIC_USER;
|
|
|
|
|
|
/**
|
|
|
* Create a Jetty embedded server to answer http requests. The primary goal is
|
|
@@ -1080,6 +1082,24 @@ public final class HttpServer2 implements FilterContainer {
|
|
|
return sb.toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * check whether user is static and unauthenticated, if the
|
|
|
+ * answer is TRUE, that means http sever is in non-security
|
|
|
+ * environment.
|
|
|
+ * @param servletContext the servlet context.
|
|
|
+ * @param request the servlet request.
|
|
|
+ * @return TRUE/FALSE based on the logic described above.
|
|
|
+ */
|
|
|
+ public static boolean isStaticUserAndNoneAuthType(
|
|
|
+ ServletContext servletContext, HttpServletRequest request) {
|
|
|
+ Configuration conf =
|
|
|
+ (Configuration) servletContext.getAttribute(CONF_CONTEXT_ATTRIBUTE);
|
|
|
+ final String authType = request.getAuthType();
|
|
|
+ final String staticUser = conf.get(HADOOP_HTTP_STATIC_USER,
|
|
|
+ DEFAULT_HADOOP_HTTP_STATIC_USER);
|
|
|
+ return authType == null && staticUser.equals(request.getRemoteUser());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Checks the user has privileges to access to instrumentation servlets.
|
|
|
* <p/>
|
|
@@ -1177,9 +1197,14 @@ public final class HttpServer2 implements FilterContainer {
|
|
|
|
|
|
@Override
|
|
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
- throws ServletException, IOException {
|
|
|
- if (!HttpServer2.isInstrumentationAccessAllowed(getServletContext(),
|
|
|
- request, response)) {
|
|
|
+ throws ServletException, IOException {
|
|
|
+ // If user is a static user and auth Type is null, that means
|
|
|
+ // there is a non-security environment and no need authorization,
|
|
|
+ // otherwise, do the authorization.
|
|
|
+ final ServletContext servletContext = getServletContext();
|
|
|
+ if (!HttpServer2.isStaticUserAndNoneAuthType(servletContext, request) &&
|
|
|
+ !HttpServer2.isInstrumentationAccessAllowed(servletContext,
|
|
|
+ request, response)) {
|
|
|
return;
|
|
|
}
|
|
|
response.setContentType("text/plain; charset=UTF-8");
|