/// <exception cref="Javax.Servlet.ServletException"/>
 /// <exception cref="System.IO.IOException"/>
 protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                               )
 {
     // Do the authorization
     if (HttpServer2.HasAdministratorAccess(GetServletContext(), request, response))
     {
         // Authorization is done. Just call super.
         base.DoGet(request, response);
     }
 }
        public virtual void TestHasAdministratorAccess()
        {
            Configuration conf = new Configuration();

            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, false);
            ServletContext context = Org.Mockito.Mockito.Mock <ServletContext>();

            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.ConfContextAttribute)).
            ThenReturn(conf);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                null);
            HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>();

            Org.Mockito.Mockito.When(request.GetRemoteUser()).ThenReturn(null);
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            //authorization OFF
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
            //authorization ON & user NULL
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, true);
            NUnit.Framework.Assert.IsFalse(HttpServer2.HasAdministratorAccess(context, request
                                                                              , response));
            Org.Mockito.Mockito.Verify(response).SendError(Org.Mockito.Mockito.Eq(HttpServletResponse
                                                                                  .ScForbidden), Org.Mockito.Mockito.AnyString());
            //authorization ON & user NOT NULL & ACLs NULL
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            Org.Mockito.Mockito.When(request.GetRemoteUser()).ThenReturn("foo");
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
            //authorization ON & user NOT NULL & ACLs NOT NULL & user not in ACLs
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            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.HasAdministratorAccess(context, request
                                                                              , response));
            Org.Mockito.Mockito.Verify(response).SendError(Org.Mockito.Mockito.Eq(HttpServletResponse
                                                                                  .ScForbidden), Org.Mockito.Mockito.AnyString());
            //authorization ON & user NOT NULL & ACLs NOT NULL & user in in ACLs
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            Org.Mockito.Mockito.When(acls.IsUserAllowed(Org.Mockito.Mockito.Any <UserGroupInformation
                                                                                 >())).ThenReturn(true);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                acls);
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
        }
Exemple #3
0
            /// <exception cref="Javax.Servlet.ServletException"/>
            /// <exception cref="System.IO.IOException"/>
            protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                                          )
            {
                // Do the authorization
                if (!HttpServer2.HasAdministratorAccess(GetServletContext(), request, response))
                {
                    return;
                }
                PrintWriter @out    = ServletUtil.InitHTML(response, "Log Level");
                string      logName = ServletUtil.GetParameter(request, "log");
                string      level   = ServletUtil.GetParameter(request, "level");

                if (logName != null)
                {
                    @out.WriteLine("<br /><hr /><h3>Results</h3>");
                    @out.WriteLine(Marker + "Submitted Log Name: <b>" + logName + "</b><br />");
                    Org.Apache.Commons.Logging.Log log = LogFactory.GetLog(logName);
                    @out.WriteLine(Marker + "Log Class: <b>" + log.GetType().FullName + "</b><br />");
                    if (level != null)
                    {
                        @out.WriteLine(Marker + "Submitted Level: <b>" + level + "</b><br />");
                    }
                    if (log is Log4JLogger)
                    {
                        Process(((Log4JLogger)log).GetLogger(), level, @out);
                    }
                    else
                    {
                        if (log is Jdk14Logger)
                        {
                            Process(((Jdk14Logger)log).GetLogger(), level, @out);
                        }
                        else
                        {
                            @out.WriteLine("Sorry, " + log.GetType() + " not supported.<br />");
                        }
                    }
                }
                @out.WriteLine(Forms);
                @out.WriteLine(ServletUtil.HtmlTail);
            }