public static SessionPrincipal GetSessionPrincipal(string token)
        {
            UserSession sessionDb = null;
            UserSession session   = null;

            using (var repository = new GeoMsgContext())
            {
                sessionDb = repository.UserSession.SingleOrDefault(x => x.Token == token);

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

                session = new UserSession
                {
                    ID         = sessionDb.ID,
                    DateCreate = sessionDb.DateCreate,
                    User       = sessionDb.User,
                    UserId     = sessionDb.UserId
                };
            }

            var principal = new SessionPrincipal(session);

            return(principal);
        }
Example #2
0
        //protected override bool IsAuthorized(HttpActionContext actionContext)
        //{
        //	if (actionContext == null)
        //	{
        //		throw new ArgumentNullException("actionContext");
        //	}

        //	if (string.IsNullOrEmpty(Roles))
        //		return true;

        //	var requiredList = UtilitarioGeral.SepararChaves(Roles);


        //	//Verificando permissões
        //	var result = requiredList.Any(role => _logado.IsInRole(role));

        //	return result;
        //}

        private bool IsAuthenticated(HttpActionContext actionContext)
        {
            if (actionContext == null)
            {
                throw new ArgumentNullException("actionContext");
            }

            _logged = HttpContext.Current == null ? null : HttpContext.Current.User as SessionPrincipal;

            if (_logged == null)
            {
                HandleUnauthenticatedRequest(actionContext);
                return(false);
            }

            return(true);
        }