Esempio n. 1
0
        private void CreateSession(LogOn.FormInfo formInfo)
        {
            string str;
            string applicationName;
            string str1;
            string originalString;
            WSManConnectionInfo wSManConnectionInfo = null;

            if (formInfo.ConfigurationName.Length == 0)
            {
                str = null;
            }
            else
            {
                str = string.Concat("http://schemas.microsoft.com/powershell/", formInfo.ConfigurationName);
            }
            string       str2         = str;
            PSCredential pSCredential = new PSCredential(formInfo.DestinationUserName, formInfo.DestinationPassword);

            if (!formInfo.IsUriConnection)
            {
                if (string.Compare(formInfo.ApplicationName, "WSMAN", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    applicationName = null;
                }
                else
                {
                    applicationName = formInfo.ApplicationName;
                }
                string str3 = applicationName;
                try
                {
                    wSManConnectionInfo = new WSManConnectionInfo(formInfo.UseSsl, formInfo.ComputerName, formInfo.Port, str3, str2, pSCredential);
                }
                catch (UriFormatException uriFormatException)
                {
                    throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidComputerNameUriFormat);
                }
                wSManConnectionInfo.AuthenticationMechanism = formInfo.AuthenticationType;
                PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_COMPUTERNAME(formInfo.DestinationUserName, wSManConnectionInfo.ComputerName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri, wSManConnectionInfo.AuthenticationMechanism.ToString());
            }
            else
            {
                wSManConnectionInfo = new WSManConnectionInfo(formInfo.ConnectionUri, str2, pSCredential);
                if (!formInfo.AllowRedirection)
                {
                    wSManConnectionInfo.MaximumConnectionRedirectionCount = 0;
                }
                PowwaEvents.PowwaEVENT_DEBUG_CONNECT_USING_URI(formInfo.DestinationUserName, wSManConnectionInfo.ConnectionUri.AbsoluteUri, wSManConnectionInfo.ShellUri);
            }
            string sourceIPAddressRemoteAddr        = SessionHelper.GetSourceIPAddressRemoteAddr();
            string sourceIPAddressHttpXForwardedFor = SessionHelper.GetSourceIPAddressHttpXForwardedFor();

            if (formInfo.IsUriConnection)
            {
                str1 = null;
            }
            else
            {
                str1 = PswaHelper.TranslateLocalComputerName(formInfo.ComputerName);
            }
            string str4 = str1;

            PowwaAuthorizationManager.Instance.CheckLogOnCredential(formInfo.UserName, formInfo.Password, str4, formInfo.ConnectionUri, formInfo.ConfigurationName, sourceIPAddressRemoteAddr, sourceIPAddressHttpXForwardedFor);
            ClientInfo   clientInfo   = new ClientInfo(HttpContext.Current.Request.UserAgent, CultureInfo.CurrentCulture, CultureInfo.CurrentUICulture);
            PowwaSession powwaSession = PowwaSessionManager.Instance.CreateSession(this.Session.SessionID, wSManConnectionInfo, clientInfo, formInfo.UserName);
            string       name         = powwaSession.Name;
            string       userName     = formInfo.UserName;
            string       str5         = sourceIPAddressRemoteAddr;
            string       str6         = sourceIPAddressHttpXForwardedFor;

            if (formInfo.IsUriConnection)
            {
                originalString = wSManConnectionInfo.ConnectionUri.OriginalString;
            }
            else
            {
                originalString = wSManConnectionInfo.ComputerName;
            }
            PowwaEvents.PowwaEVENT_SESSION_START(name, userName, str5, str6, originalString, formInfo.DestinationUserName, wSManConnectionInfo.Port, wSManConnectionInfo.AppName, wSManConnectionInfo.ShellUri);
            HttpCookie item = base.Request.Cookies["ASP.NET_SessionId"];

            if (FormsAuthentication.RequireSSL && item != null)
            {
                item.Secure = true;
            }
            FormsAuthentication.SetAuthCookie(formInfo.UserName, false, "/");
            base.Response.Redirect("~/default.aspx");
            //FormsAuthentication.RedirectFromLoginPage(formInfo.UserName, false);
        }
Esempio n. 2
0
        private LogOn.FormInfo ValidateForm()
        {
            string           value;
            HtmlInputControl htmlInputControl;

            LogOn.FormInfo formInfo = new LogOn.FormInfo();
            LogOn.ValidateCharactersInString(this.userNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.altUserNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.passwordTextBox.Value);
            LogOn.ValidateCharactersInString(this.connectionUriTextBox.Value);
            LogOn.ValidateCharactersInString(this.targetNodeTextBox.Value);
            LogOn.ValidateCharactersInString(this.configurationNameTextBox.Value);
            LogOn.ValidateCharactersInString(this.applicationNameTextBox.Value);
            formInfo.UserName = PswaHelper.TranslateLocalAccountName(this.userNameTextBox.Value);
            formInfo.Password = this.passwordTextBox.Value;
            LogOn.FormInfo formInfo1 = formInfo;
            if (this.altUserNameTextBox.Value.Length > 0)
            {
                value = this.altUserNameTextBox.Value;
            }
            else
            {
                value = formInfo.UserName;
            }
            formInfo1.DestinationUserName = value;
            if (this.altPasswordTextBox.Value.Length > 0)
            {
                htmlInputControl = this.altPasswordTextBox;
            }
            else
            {
                htmlInputControl = this.passwordTextBox;
            }
            char[] charArray = htmlInputControl.Value.ToCharArray();
            formInfo.DestinationPassword = new SecureString();
            for (int i = 0; i < (int)charArray.Length; i++)
            {
                formInfo.DestinationPassword.AppendChar(charArray[i]);
                charArray[i] = '*';
            }
            formInfo.IsUriConnection = string.Compare(this.connectionTypeSelection.Value, "connection-uri", StringComparison.OrdinalIgnoreCase) == 0;
            if (!formInfo.IsUriConnection)
            {
                formInfo.ComputerName = this.targetNodeTextBox.Value;
                formInfo.UseSsl       = this.useSslSelection.Value == "1";
                if (this.portTextBox.Value.Length != 0)
                {
                    if (!int.TryParse(this.portTextBox.Value, out formInfo.Port))
                    {
                        throw PowwaException.CreateValidationErrorException(Resources.LogonError_InvalidPort);
                    }
                }
                else
                {
                    formInfo.Port = 0x1761;
                }
                formInfo.ApplicationName = this.applicationNameTextBox.Value;
            }
            else
            {
                try
                {
                    formInfo.ConnectionUri = new Uri(this.connectionUriTextBox.Value);
                }
                catch (UriFormatException uriFormatException1)
                {
                    UriFormatException uriFormatException = uriFormatException1;
                    object[]           message            = new object[1];
                    message[0] = uriFormatException.Message;
                    throw PowwaException.CreateValidationErrorException(string.Format(CultureInfo.CurrentUICulture, Resources.LogonError_InvalidUri, message));
                }
                formInfo.AllowRedirection = this.allowRedirectionSelection.Value == "1";
            }
            formInfo.ConfigurationName = this.configurationNameTextBox.Value;
            string str  = this.authenticationTypeSelection.Value;
            string str1 = str;

            if (str != null)
            {
                if (str1 == "0")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Default;
                }
                else if (str1 == "1")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Basic;
                }
                else if (str1 == "2")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Negotiate;
                }
                else if (str1 == "4")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Credssp;
                }
                else if (str1 == "5")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Digest;
                }
                else if (str1 == "6")
                {
                    formInfo.AuthenticationType = AuthenticationMechanism.Kerberos;
                }
                else
                {
                    throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
                }
                return(formInfo);
            }
            throw PowwaException.CreateValidationErrorException(Resources.InternalError_InvalidAuthenticationMechanism);
        }