/// <summary>
            /// Attempt to retrieve a session token
            /// </summary>
            /// <returns></returns>
            public virtual string RetrieveSessionToken(ISessionRetriever sessionRetriever)
            {
                // Attempt to find a session token
                string sessionToken = request.GetText("sessionToken");

                if (string.IsNullOrEmpty(sessionToken) && (sessionRetriever != null))
                {
                    sessionToken = sessionRetriever.RetrieveSessionToken(request);
                }
                return(sessionToken);
            }
Example #2
0
        public HtmlFragmentResponse Execute()
        {
            Hashtable velocityContext = new Hashtable();

            velocityContext["changePassword"] = string.Empty;

            string serverName = request.ServerName;

            if (!string.IsNullOrEmpty(serverName) && (configuration.PluginConfiguration.SecurityPlugins.Length > 0))
            {
                string sessionToken = retriever.RetrieveSessionToken(request.Request);

                string userName = string.Empty;


                if (string.IsNullOrEmpty(sessionToken))
                {
                    velocityContext["action"] = linkFactory.CreateServerLink(request.ServerSpecifier,
                                                                             "Login",
                                                                             configuration.PluginConfiguration.SecurityPlugins[0].NamedActions[0].ActionName);
                }
                else
                {
                    velocityContext["action"] = linkFactory.CreateServerLink(request.ServerSpecifier,
                                                                             "Logout",
                                                                             LogoutSecurityAction.ActionName);

                    velocityContext["changePassword"] = linkFactory.CreateServerLink(request.ServerSpecifier,
                                                                                     "Change Password",
                                                                                     ChangePasswordSecurityAction.ActionName);

                    string displayName = retriever.RetrieveDisplayName(request.Request);

                    if (string.IsNullOrEmpty(displayName))
                    {
                        userName = sessionToken;
                    }
                    else
                    {
                        userName = displayName;
                    }
                }

                velocityContext["userName"] = userName;
            }
            else
            {
                velocityContext["action"] = string.Empty;
            }

            return(velocityViewGenerator.GenerateView("LoginAction.vm", velocityContext));
        }
        private string ForceBuildIfNecessary(IRequest request)
        {
            // Attempt to find a session token
            string sessionToken = request.GetText("sessionToken");

            if (string.IsNullOrEmpty(sessionToken) && (sessionRetriever != null))
            {
                sessionToken = sessionRetriever.RetrieveSessionToken(request);
            }

            Dictionary <string, string> parameters = new Dictionary <string, string>();

            foreach (string parameterName in HttpContext.Current.Request.Form.AllKeys)
            {
                if (parameterName.StartsWith("param_"))
                {
                    parameters.Add(parameterName.Substring(6), HttpContext.Current.Request.Form[parameterName]);
                }
            }

            // Make the actual call
            if (request.FindParameterStartingWith("StopBuild") != string.Empty)
            {
                farmService.Stop(ProjectSpecifier(request), sessionToken);
                return(this.translations.Translate("Stopping project {0}", SelectedProject(request)));
            }
            else if (request.FindParameterStartingWith("StartBuild") != string.Empty)
            {
                farmService.Start(ProjectSpecifier(request), sessionToken);
                return(this.translations.Translate("Starting project {0}", SelectedProject(request)));
            }
            else if (request.FindParameterStartingWith("ForceBuild") != string.Empty)
            {
                farmService.ForceBuild(ProjectSpecifier(request), sessionToken, parameters);
                return(this.translations.Translate("Build successfully forced for {0}", SelectedProject(request)));
            }
            else if (request.FindParameterStartingWith("AbortBuild") != string.Empty)
            {
                farmService.AbortBuild(ProjectSpecifier(request), sessionToken);
                return(this.translations.Translate("Abort successfully forced for {0}", SelectedProject(request)));
            }
            else
            {
                return(string.Empty);
            }
        }
 /// <summary>
 /// Attempt to retrieve a session token
 /// </summary>
 /// <returns></returns>
 public virtual string RetrieveSessionToken(ISessionRetriever sessionRetriever)
 {
     // Attempt to find a session token
     string sessionToken = request.GetText("sessionToken");
     if (string.IsNullOrEmpty(sessionToken) && (sessionRetriever != null))
     {
         sessionToken = sessionRetriever.RetrieveSessionToken(request);
     }
     return sessionToken;
 }