Exemplo n.º 1
0
        /// <summary>
        /// Override to get session object using whatever parameters are available in response context (i.e. a cookie),
        /// or create a new one if 'onlyExisting'=false(default)
        /// </summary>
        protected internal virtual void FetchExistingOrMakeNewSession(WorkContext work, bool onlyExisting = false)
        {
            if (work.Session != null)
            {
                return;
            }
            WaveSession session   = null;
            ulong       sidSecret = 0;
            var         sid       = ExtractSessionID(work, out sidSecret);

            if (sid.HasValue)
            {
                session = App.ObjectStore.CheckOut(sid.Value) as WaveSession;

                if (session != null && session.IDSecret != sidSecret)
                {
                    App.ObjectStore.UndoCheckout(sid.Value);
                    session = null;//The secret password does not match
                    if (Server.m_InstrumentationEnabled)
                    {
                        Interlocked.Increment(ref Server.m_Stat_SessionInvalidID);
                    }
                }
            }

            if (session == null)
            {
                if (onlyExisting)
                {
                    return;        //do not create anything
                }
                if (NetGate != null && NetGate.Enabled)
                {
                    NetGate.IncreaseVariable(IO.Net.Gate.TrafficDirection.Incoming,
                                             work.Request.RemoteEndPoint.Address.ToString(),
                                             NETGATE_NEWSESSION_VAR_NAME,
                                             1);
                }

                session = MakeNewSession(work);
            }
            else
            if (Server.m_InstrumentationEnabled)
            {
                Interlocked.Increment(ref Server.m_Stat_SessionExisting);
            }

            session.Acquire();
            if (work.GeoEntity != null)
            {
                session.GeoEntity = work.GeoEntity;
            }
            work.m_Session = session;
            ApplicationModel.ExecutionContext.__SetThreadLevelSessionContext(session);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Override to encode session ID GUID into string representation
        /// </summary>
        protected virtual string EncodeSessionID(WorkContext work, WaveSession session, bool hasApiHeaders)
        {
            var encoded = new ELink(session.IDSecret, session.ID.ToByteArray());

            return(encoded.Link);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Override to get session object using whatever parameters are available in response context (i.e. a cookie),
        /// or create a new one if 'onlyExisting'=false(default)
        /// </summary>
        protected internal virtual void FetchExistingOrMakeNewSession(WorkContext work, bool onlyExisting = false)
        {
            if (work.Session != null)
            {
                return;
            }
            WaveSession session   = null;
            ulong       sidSecret = 0;
            var         sid       = ExtractSessionID(work, out sidSecret);

            if (sid.HasValue)
            {
                session = App.ObjectStore.CheckOut(sid.Value) as WaveSession;

                if (session != null && session.IDSecret != sidSecret)
                {
                    App.ObjectStore.UndoCheckout(sid.Value);
                    session = null;//The secret password does not match
                    if (Server.m_InstrumentationEnabled)
                    {
                        Interlocked.Increment(ref Server.m_stat_SessionInvalidID);
                    }
                }
            }

            var foundExisting = true;

            if (session == null)
            {
                //20160124 DKh to use long term tokens
                //if (onlyExisting) return;//do not create anything
                if (onlyExisting)
                {
                    session = TryMakeSessionFromExistingLongTermToken(work);
                    if (session == null)
                    {
                        return;       //do not create anything
                    }
                }

                if (session == null)
                {
                    foundExisting = false;
                    if (NetGate != null && NetGate.Enabled)
                    {
                        NetGate.IncreaseVariable(IO.Net.Gate.TrafficDirection.Incoming,
                                                 work.EffectiveCallerIPEndPoint.Address.ToString(),
                                                 NETGATE_NEWSESSION_VAR_NAME,
                                                 1);
                    }

                    session = MakeNewSession(work);
                }
            }

            if (foundExisting && Server.m_InstrumentationEnabled)
            {
                Interlocked.Increment(ref Server.m_stat_SessionExisting);
            }

            session.Acquire();
            if (work.GeoEntity != null)
            {
                session.GeoEntity = work.GeoEntity;
            }
            work.m_Session = session;
            ApplicationModel.ExecutionContext.__SetThreadLevelSessionContext(session);

            work.SetAuthenticated(session.User.IsAuthenticated);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Override to encode session ID GUID into string representation
 /// </summary>
 protected virtual string EncodeSessionID(WaveSession session)
 {
   var encoded = new ELink(session.IDSecret, session.ID.ToByteArray());
   return encoded.Link;
 }
Exemplo n.º 5
0
 /// <summary>
 /// Override to encode session ID GUID into string representation
 /// </summary>
 protected virtual string EncodeSessionID(WorkContext work, WaveSession session, bool hasApiHeaders)
 {
     var encoded = new ELink(session.IDSecret, session.ID.ToByteArray());
     return encoded.Link;
 }
Exemplo n.º 6
0
        /// <summary>
        /// Override to encode session ID GUID into string representation
        /// </summary>
        protected virtual string EncodeSessionID(WaveSession session)
        {
            var encoded = new ELink(session.IDSecret, session.ID.ToByteArray());

            return(encoded.Link);
        }