コード例 #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.";
            }
        }