public virtual void TestRequiresAuthorizationAccess() { Configuration conf = new Configuration(); ServletContext context = Org.Mockito.Mockito.Mock <ServletContext>(); Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.ConfContextAttribute)). ThenReturn(conf); HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>(); HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>(); //requires admin access to instrumentation, FALSE by default Assert.True(HttpServer2.IsInstrumentationAccessAllowed(context, request, response)); //requires admin access to instrumentation, TRUE conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityInstrumentationRequiresAdmin , true); conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, true); AccessControlList acls = Org.Mockito.Mockito.Mock <AccessControlList>(); Org.Mockito.Mockito.When(acls.IsUserAllowed(Org.Mockito.Mockito.Any <UserGroupInformation >())).ThenReturn(false); Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn( acls); NUnit.Framework.Assert.IsFalse(HttpServer2.IsInstrumentationAccessAllowed(context , request, response)); }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { if (!HttpServer2.IsInstrumentationAccessAllowed(GetServletContext(), request, response )) { return; } string format = request.GetParameter("format"); ICollection <MetricsContext> allContexts = ContextFactory.GetFactory().GetAllContexts (); if ("json".Equals(format)) { response.SetContentType("application/json; charset=utf-8"); PrintWriter @out = response.GetWriter(); try { // Uses Jetty's built-in JSON support to convert the map into JSON. @out.Write(new JSON().ToJSON(MakeMap(allContexts))); } finally { @out.Close(); } } else { PrintWriter @out = response.GetWriter(); try { PrintMap(@out, MakeMap(allContexts)); } finally { @out.Close(); } } }
/// <exception cref="Javax.Servlet.ServletException"/> /// <exception cref="System.IO.IOException"/> protected override void DoGet(HttpServletRequest request, HttpServletResponse response ) { if (!HttpServer2.IsInstrumentationAccessAllowed(GetServletContext(), request, response )) { return; } string format = request.GetParameter(FormatParam); if (null == format) { format = FormatXml; } if (FormatXml.Equals(format)) { response.SetContentType("text/xml; charset=utf-8"); } else { if (FormatJson.Equals(format)) { response.SetContentType("application/json; charset=utf-8"); } } TextWriter @out = response.GetWriter(); try { WriteResponse(GetConfFromContext(), @out, format); } catch (ConfServlet.BadFormatException bfe) { response.SendError(HttpServletResponse.ScBadRequest, bfe.Message); } @out.Close(); }
/// <exception cref="System.IO.IOException"/> protected internal virtual bool IsInstrumentationAccessAllowed(HttpServletRequest request, HttpServletResponse response) { return(HttpServer2.IsInstrumentationAccessAllowed(GetServletContext(), request, response )); }