コード例 #1
0
ファイル: FirmaSession.cs プロジェクト: sitkatech/alevin
        public void ResumeOriginalUser(Uri optionalPreviousPageUri, out string impersonationStatusMessage)
        {
            var lastPageLinkHtml = MakeLastPageLinkHtml(optionalPreviousPageUri);

            Check.EnsureNotNull(OriginalPerson, "FirmaSession {0} is not impersonating; it is not valid to call ResumeOriginalUser()");
            impersonationStatusMessage = $"Logon {OriginalPerson.GetFullNameFirstLast()} resuming their original session; ceasing impersonation of Logon {Person.GetFullNameFirstLast()}.{lastPageLinkHtml}";
            //_logger.InfoFormat(impersonationStatusMessage);
            // Swap back
            Person = OriginalPerson;
            // Clear impersonation data
            OriginalPerson   = null;
            OriginalPersonID = null;
        }
コード例 #2
0
ファイル: FirmaSession.cs プロジェクト: sitkatech/alevin
        public void ImpersonateUser(Person personToImpersonate,
                                    Uri optionalPreviousPageUri,
                                    out string impersonationStatusMessage,
                                    out string impersonationStatusWarning)
        {
            Check.EnsureNotNull(this.PersonID, "Anonymous users can't impersonate authentic users.");
            Check.EnsureNotNull(personToImpersonate, "You can't impersonate an Anonymous user.");

            impersonationStatusWarning = null;
            string currentImpersonationString = string.Empty;

            // Keep track of who we started as -- unless we are *already* impersonating,
            // in which case we keep our original identity through each new impersonation.
            if (OriginalPerson == null)
            {
                OriginalPerson = Person;
            }
            else
            {
                // If we are trying to impersonate *ourself*, we instead resume our original session.
                // (there are other checks elsewhere to prevent and warn about this, but this is a last-ditch exit.)
                if (OriginalPerson.PersonID == personToImpersonate.PersonID)
                {
                    ResumeOriginalUser(optionalPreviousPageUri, out impersonationStatusMessage);
                    return;
                }

                currentImpersonationString = $" (currently impersonating {Person.GetFullNameFirstLast()})";
            }

            var lastPageLinkHtml = MakeLastPageLinkHtml(optionalPreviousPageUri);

            // Switch to the new user we want to impersonate
            Person = personToImpersonate;
            impersonationStatusMessage = $"Logon {OriginalPerson.GetFullNameFirstLast()}{currentImpersonationString} switching to impersonate Logon {personToImpersonate.GetFullNameFirstLast()}.{lastPageLinkHtml}";
            //_logger.InfoFormat(impersonationStatusMessage);

            if (!personToImpersonate.IsActive)
            {
                impersonationStatusWarning = $"Logon {personToImpersonate.GetFullNameFirstLast()} is inactive. Impersonation will allow you to act as this person, but be aware of potential issues due to the account being inactive.";
            }
        }
コード例 #3
0
ファイル: client.cs プロジェクト: zhimaqiao51/docs
    public static void Main()
    {
        // Picks up configuration from the config file.
        using (SampleServiceClient wcfClient = new SampleServiceClient())
        {
            try
            {
                // Making calls.
                Console.Write("Enter the first name to send: ");
                string first = Console.ReadLine();
                Console.Write("Enter the last name to send: ");
                string last = Console.ReadLine();
                Console.Write("Enter a message: ");
                string msg = Console.ReadLine();

                OriginalPerson person = new OriginalPerson();
                person.lastName       = last;
                person.firstName      = first;
                person.Message        = msg;
                person.additionalData = "extra data the service does not have.";

                person.Blob = new ArgumentException();

                OriginalPerson replyPerson = wcfClient.SampleMethod(person);

                Console.WriteLine("The service responded: " + replyPerson.Message);
                Console.WriteLine("From \"{0}, {1}\".", replyPerson.firstName, replyPerson.lastName);

                if (replyPerson.additionalData == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("The return additional data is null");
                    Console.ResetColor();
                }
                else
                {
                    Console.WriteLine("Any extra data: {0}.", replyPerson.additionalData.ToString());
                }

                if (replyPerson.Blob != null)
                {
                    Console.WriteLine("And the added object is: " + replyPerson.Blob.ToString());
                }
                else
                {
                    Console.WriteLine("There is no added data in the extra object property.");
                }

                Console.WriteLine("Press ENTER to exit:");
                Console.ReadLine();

                // Done with service.
                wcfClient.Close();
                Console.WriteLine("Done!");
            }
            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message);
                Console.Read();
            }
        }
    }