예제 #1
0
        public virtual void TestGetProxyUriFromPluginsReturnsNullIfNoPlugins()
        {
            ApplicationId             id   = BuilderUtils.NewApplicationId(6384623l, 5);
            IList <TrackingUriPlugin> list = Lists.NewArrayListWithExpectedSize(0);

            NUnit.Framework.Assert.IsNull(ProxyUriUtils.GetUriFromTrackingPlugins(id, list));
        }
예제 #2
0
 public virtual void TestGetPathApplicationId()
 {
     NUnit.Framework.Assert.AreEqual("/proxy/application_100_0001", ProxyUriUtils.GetPath
                                         (BuilderUtils.NewApplicationId(100l, 1)));
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005", ProxyUriUtils.
                                     GetPath(BuilderUtils.NewApplicationId(6384623l, 5)));
 }
예제 #3
0
 public virtual void TestGetPathAndQuery()
 {
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005/static/app?foo=bar"
                                     , ProxyUriUtils.GetPathAndQuery(BuilderUtils.NewApplicationId(6384623l, 5), "/static/app"
                                                                     , "?foo=bar", false));
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005/static/app?foo=bar&bad=good&proxyapproved=true"
                                     , ProxyUriUtils.GetPathAndQuery(BuilderUtils.NewApplicationId(6384623l, 5), "/static/app"
                                                                     , "foo=bar&bad=good", true));
 }
예제 #4
0
        private static Cookie MakeCheckCookie(ApplicationId id, bool isSet)
        {
            Cookie c = new Cookie(GetCheckCookieName(id), isSet.ToString());

            c.SetPath(ProxyUriUtils.GetPath(id));
            c.SetMaxAge(60 * 60 * 2);
            //2 hours in seconds
            return(c);
        }
예제 #5
0
        public virtual void TestGetProxyUriNull()
        {
            URI           originalUri = null;
            URI           proxyUri    = new URI("http://proxy.net:8080/");
            ApplicationId id          = BuilderUtils.NewApplicationId(6384623l, 5);
            URI           expected    = new URI("http://proxy.net:8080/proxy/application_6384623_0005/");
            URI           result      = ProxyUriUtils.GetProxyUri(originalUri, proxyUri, id);

            NUnit.Framework.Assert.AreEqual(expected, result);
        }
예제 #6
0
 public virtual void TestGetPathApplicationIdString()
 {
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005", ProxyUriUtils.
                                     GetPath(BuilderUtils.NewApplicationId(6384623l, 5), null));
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005/static/app", ProxyUriUtils
                                     .GetPath(BuilderUtils.NewApplicationId(6384623l, 5), "/static/app"));
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005/", ProxyUriUtils
                                     .GetPath(BuilderUtils.NewApplicationId(6384623l, 5), "/"));
     NUnit.Framework.Assert.AreEqual("/proxy/application_6384623_0005/some/path", ProxyUriUtils
                                     .GetPath(BuilderUtils.NewApplicationId(6384623l, 5), "some/path"));
 }
예제 #7
0
        public virtual void TestGetProxyUriFromPluginsReturnsValidUriWhenAble()
        {
            ApplicationId             id   = BuilderUtils.NewApplicationId(6384623l, 5);
            IList <TrackingUriPlugin> list = Lists.NewArrayListWithExpectedSize(2);

            // Insert a plugin that returns null.
            list.AddItem(new _TrackingUriPlugin_108());
            // Insert a plugin that returns a valid URI.
            list.AddItem(new _TrackingUriPlugin_114());
            URI result = ProxyUriUtils.GetUriFromTrackingPlugins(id, list);

            NUnit.Framework.Assert.IsNotNull(result);
        }
예제 #8
0
 public virtual void TestGetPathApplicationIdBad()
 {
     ProxyUriUtils.GetPath(null);
 }
예제 #9
0
        /// <exception cref="System.IO.IOException"/>
        protected override void DoGet(HttpServletRequest req, HttpServletResponse resp)
        {
            try
            {
                string   userApprovedParamS = req.GetParameter(ProxyUriUtils.ProxyApprovalParam);
                bool     userWasWarned      = false;
                bool     userApproved       = Sharpen.Extensions.ValueOf(userApprovedParamS);
                bool     securityEnabled    = IsSecurityEnabled();
                string   remoteUser         = req.GetRemoteUser();
                string   pathInfo           = req.GetPathInfo();
                string[] parts = pathInfo.Split("/", 3);
                if (parts.Length < 2)
                {
                    Log.Warn("{} gave an invalid proxy path {}", remoteUser, pathInfo);
                    NotFound(resp, "Your path appears to be formatted incorrectly.");
                    return;
                }
                //parts[0] is empty because path info always starts with a /
                string        appId = parts[1];
                string        rest  = parts.Length > 2 ? parts[2] : string.Empty;
                ApplicationId id    = Apps.ToAppID(appId);
                if (id == null)
                {
                    Log.Warn("{} attempting to access {} that is invalid", remoteUser, appId);
                    NotFound(resp, appId + " appears to be formatted incorrectly.");
                    return;
                }
                if (securityEnabled)
                {
                    string   cookieName = GetCheckCookieName(id);
                    Cookie[] cookies    = req.GetCookies();
                    if (cookies != null)
                    {
                        foreach (Cookie c in cookies)
                        {
                            if (cookieName.Equals(c.GetName()))
                            {
                                userWasWarned = true;
                                userApproved  = userApproved || Sharpen.Extensions.ValueOf(c.GetValue());
                                break;
                            }
                        }
                    }
                }
                bool checkUser = securityEnabled && (!userWasWarned || !userApproved);
                AppReportFetcher.FetchedAppReport fetchedAppReport = null;
                ApplicationReport applicationReport = null;
                try
                {
                    fetchedAppReport = GetApplicationReport(id);
                    if (fetchedAppReport != null)
                    {
                        if (fetchedAppReport.GetAppReportSource() != AppReportFetcher.AppReportSource.Rm &&
                            fetchedAppReport.GetAppReportSource() != AppReportFetcher.AppReportSource.Ahs)
                        {
                            throw new NotSupportedException("Application report not " + "fetched from RM or history server."
                                                            );
                        }
                        applicationReport = fetchedAppReport.GetApplicationReport();
                    }
                }
                catch (ApplicationNotFoundException)
                {
                    applicationReport = null;
                }
                if (applicationReport == null)
                {
                    Log.Warn("{} attempting to access {} that was not found", remoteUser, id);
                    URI toFetch = ProxyUriUtils.GetUriFromTrackingPlugins(id, this.trackingUriPlugins
                                                                          );
                    if (toFetch != null)
                    {
                        ProxyUtils.SendRedirect(req, resp, toFetch.ToString());
                        return;
                    }
                    NotFound(resp, "Application " + appId + " could not be found " + "in RM or history server"
                             );
                    return;
                }
                string original = applicationReport.GetOriginalTrackingUrl();
                URI    trackingUri;
                if (original == null || original.Equals("N/A") || original.Equals(string.Empty))
                {
                    if (fetchedAppReport.GetAppReportSource() == AppReportFetcher.AppReportSource.Rm)
                    {
                        // fallback to ResourceManager's app page if no tracking URI provided
                        // and Application Report was fetched from RM
                        Log.Debug("Original tracking url is '{}'. Redirecting to RM app page", original ==
                                  null ? "NULL" : original);
                        ProxyUtils.SendRedirect(req, resp, StringHelper.Pjoin(rmAppPageUrlBase, id.ToString
                                                                                  ()));
                    }
                    else
                    {
                        if (fetchedAppReport.GetAppReportSource() == AppReportFetcher.AppReportSource.Ahs)
                        {
                            // fallback to Application History Server app page if the application
                            // report was fetched from AHS
                            Log.Debug("Original tracking url is '{}'. Redirecting to AHS app page", original
                                      == null ? "NULL" : original);
                            ProxyUtils.SendRedirect(req, resp, StringHelper.Pjoin(ahsAppPageUrlBase, id.ToString
                                                                                      ()));
                        }
                    }
                    return;
                }
                else
                {
                    if (ProxyUriUtils.GetSchemeFromUrl(original).IsEmpty())
                    {
                        trackingUri = ProxyUriUtils.GetUriFromAMUrl(WebAppUtils.GetHttpSchemePrefix(conf)
                                                                    , original);
                    }
                    else
                    {
                        trackingUri = new URI(original);
                    }
                }
                string runningUser = applicationReport.GetUser();
                if (checkUser && !runningUser.Equals(remoteUser))
                {
                    Log.Info("Asking {} if they want to connect to the " + "app master GUI of {} owned by {}"
                             , remoteUser, appId, runningUser);
                    WarnUserPage(resp, ProxyUriUtils.GetPathAndQuery(id, rest, req.GetQueryString(),
                                                                     true), runningUser, id);
                    return;
                }
                // Append the user-provided path and query parameter to the original
                // tracking url.
                IList <NameValuePair> queryPairs = URLEncodedUtils.Parse(req.GetQueryString(), null
                                                                         );
                UriBuilder builder = UriBuilder.FromUri(trackingUri);
                foreach (NameValuePair pair in queryPairs)
                {
                    builder.QueryParam(pair.GetName(), pair.GetValue());
                }
                URI toFetch_1 = builder.Path(rest).Build();
                Log.Info("{} is accessing unchecked {}" + " which is the app master GUI of {} owned by {}"
                         , remoteUser, toFetch_1, appId, runningUser);
                switch (applicationReport.GetYarnApplicationState())
                {
                case YarnApplicationState.Killed:
                case YarnApplicationState.Finished:
                case YarnApplicationState.Failed:
                {
                    ProxyUtils.SendRedirect(req, resp, toFetch_1.ToString());
                    return;
                }

                default:
                {
                    break;
                }
                }
                // fall out of the switch
                Cookie c_1 = null;
                if (userWasWarned && userApproved)
                {
                    c_1 = MakeCheckCookie(id, true);
                }
                ProxyLink(req, resp, toFetch_1, c_1, GetProxyHost());
            }
            catch (Exception e)
            {
                throw new IOException(e);
            }
        }