Ejemplo n.º 1
0
        void MvcApplication_PostAcquireRequestState(object sender, EventArgs e)
        {
            if (HttpContext.Current.Handler is System.Web.SessionState.IRequiresSessionState || HttpContext.Current.Handler is System.Web.SessionState.IReadOnlySessionState)
            {
                if (Request.IsAuthenticated)
                {
                    //get the username which we previously set in
                    //forms authentication ticket in our login1_authenticate event
                    string loggedUser = HttpContext.Current.User.Identity.Name;

                    if (Session[SessionPrincipalKey] == null)
                    {
                        System.Diagnostics.Debug.WriteLine("Getting User Info From DB");
                        //build a custom identity and custom principal object based on this username
                        var identity  = new ConcentratorIdentity(loggedUser);
                        var principal = new ConcentratorPrincipal(identity);

                        #region not working yet
                        var timeout = identity.Timeout;

                        Session.Timeout = timeout;
                        #endregion

                        Session[SessionPrincipalKey] = principal;
                    }
                    //set the principal to the current context
                    HttpContext.Current.User = Session[SessionPrincipalKey] as ConcentratorPrincipal;
                }
                else
                {
                    Session[SessionPrincipalKey] = null;
                }
            }
        }
Ejemplo n.º 2
0
        public bool Evaluate(EvaluationContext evaluationContext, ref object state)
        {
            // var repository = UnitOfWork.Current.Repository<IPortfolioRepository>();

            // get the authenticated client identity
            IIdentity client = GetClientIdentity(evaluationContext);

            //var portfolio = repository.GetPortfolioByServiceCredentials(client.Name);

            // if (portfolio == null || !portfolio.IsActive)
            // {
            //   throw new Exception("Invalid User Data");
            // }

            ConcentratorIdentity  id   = new ConcentratorIdentity(client.Name);
            ConcentratorPrincipal prin = new ConcentratorPrincipal(id);

            evaluationContext.Properties["Principal"] = prin;

            return(true);
        }