Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        public bool IsInRole(string role)
        {
            UserContextData contextData = Context;

            if (contextData != null)
            {
                return(contextData.IsInRole(role));
            }
            return(false);
        }
Ejemplo n.º 3
0
        private void CreateContext(UserContextData contextData)
        {
            if (contextData.SessionId.IsEmpty)
            {
                AppliactionContext.Log.Error(this, String.Format("Can't create context for user '{0}' with sessiosId '{1}'.", User.Username, SessionId));
                return;
            }

            if (!_contexts.ContainsKey(contextData.SessionId))
            {
                AppliactionContext.Log.Debug(this, String.Format("Creating context for user '{0}' with sessiosId '{1}'.", contextData.User.Username, contextData.SessionId));
                while (!_contexts.TryAdd(contextData.SessionId, contextData))
                {
                }
                InitializeContextData(contextData);
                AttachThreadExecutionContext(contextData.SessionId);
            }
            AppliactionContext.Log.Debug(this, String.Format("Context was created for user '{0}' with sessiosId '{1}'.", User.Username, SessionId));
        }
Ejemplo n.º 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;
            }
        }
Ejemplo n.º 5
0
 public UserContextPrincipal(UserContextData data)
 {
     _context = new WeakReference<UserContextData>(data);
 }
Ejemplo n.º 6
0
 public UserContextPrincipal(UserContextData data)
 {
     _context = new WeakReference <UserContextData>(data);
 }
Ejemplo n.º 7
0
 private void ClosseContextData(UserContextData contextData)
 {
     contextData.Logout();
 }
Ejemplo n.º 8
0
 private void InitializeContextData(UserContextData contextData)
 {
 }