示例#1
0
        private void SetupThreadContext(UserContextData contextData, SessionId id)
        {
            if (contextData == null)
            {
                return;
            }

            IPrincipal principal = TryGetPrincipal();

            if (principal != null)
            {
                if (!(principal is GenericPrincipal))
                {
                    // Debug.Fail("It has to be the same principal!");
                }
                contextData.OriginalPrincipal = principal;
            }

            principal = new UserContextPrincipal(contextData);

            SetPrincipal(principal);

            AppliactionContext.Log.Debug(this, String.Format("User '{0}' with sessionId '{1}' was attached to the thread.", User.Username, SessionId));

            if (ExecutionContext.IsFlowSuppressed())
            {
                ExecutionContext.RestoreFlow();
            }
        }
示例#2
0
        private static UserContextPrincipal TryGetUserContextPrincipal()
        {
            UserContextPrincipal principal = Thread.CurrentPrincipal as UserContextPrincipal;

            if (principal == null)
            {
                if (HttpContext.Current != null)
                {
                    principal = HttpContext.Current.User as UserContextPrincipal;
                }
            }

            return(principal);
        }
示例#3
0
        private UserContextData GetCurrentContextData()
        {
            UserContextPrincipal principal = TryGetUserContextPrincipal();

            if (principal == null)
            {
                return(null);
            }

            if (principal.Context == null)
            {
                return(null);
            }

            return(principal.Context);
        }
示例#4
0
        private void DetachThreadExecutionContext(SessionId id)
        {
            UserContextData contextData = Instance.ContextData;

            if (contextData == null)
            {
                return;
            }

            if (contextData.SessionId != id)
            {
                AppliactionContext.Log.Error(this, String.Format("Different sessionId '{0}'. Context sessionId sessiosId '{1}'.", id, contextData.SessionId));
            }

            UserContextPrincipal principal = TryGetUserContextPrincipal();

            if (principal != null)
            {
                AppliactionContext.Log.Debug(this, String.Format("Detaching user '{0}' with sessiosId '{1}' from the thread.", User.Username, SessionId));
                SetPrincipal(contextData.OriginalPrincipal);
                contextData.OriginalPrincipal = null;
            }
        }