Ejemplo n.º 1
0
        protected void ExpireSession()
        {
            try
            {
                Customer customer = AuthoriseRequest();

                logger.Debug("SIPSorceryAuthenticatedService ExpireSession called for " + customer.CustomerUsername + ".");

                CRMSessionManager.ExpireToken(ServiceAuthToken.GetAuthId());

                // If running in IIS remove the cookie.
                if (HttpContext.Current != null)
                {
                    HttpContext.Current.Request.Cookies.Remove(m_authIDKey);
                }
            }
            catch (UnauthorizedAccessException)
            {
                // This exception will occur if the SIP Server agent is restarted and the client sends a previously valid token.
                //logger.Debug("An unauthorised exception was thrown in logout.");
            }
            catch (Exception excp)
            {
                logger.Error("Exception ExpireSession. " + excp.Message);
            }
        }
Ejemplo n.º 2
0
        protected Customer AuthoriseRequest()
        {
            try
            {
                string authId = ServiceAuthToken.GetAuthId();
                //logger.Debug("Authorising request for sessionid=" + authId + ".");

                if (!authId.IsNullOrBlank())
                {
                    CustomerSession customerSession = CRMSessionManager.Authenticate(authId);
                    if (customerSession == null)
                    {
                        logger.Warn("SIPSorceryAuthenticatedService AuthoriseRequest failed for " + authId + ".");
                        throw new UnauthorizedAccessException();
                    }
                    else
                    {
                        Customer customer = CRMCustomerPersistor.Get(c => c.CustomerUsername == customerSession.CustomerUsername);
                        return(customer);
                    }
                }
                else
                {
                    string apiKey = ServiceAuthToken.GetAPIKey();

                    if (!apiKey.IsNullOrBlank())
                    {
                        Customer customer = CRMCustomerPersistor.Get(c => c.APIKey == apiKey);
                        return(customer);
                    }
                    else
                    {
                        logger.Warn("SIPSorceryAuthenticatedService AuthoriseRequest failed no authid header.");
                        throw new UnauthorizedAccessException();
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                throw;
            }
            catch (Exception excp)
            {
                logger.Error("Exception AuthoriseRequest. " + excp.Message);
                throw new Exception("There was an exception authorising the request.");
            }
        }
Ejemplo n.º 3
0
        protected void ExtendExistingSession(int minutes)
        {
            try
            {
                Customer customer = AuthoriseRequest();

                logger.Debug("SIPSorceryAuthenticatedService ExtendExistingSession called for " + customer.CustomerUsername + " and " + minutes + " minutes.");
                if (HttpContext.Current != null)
                {
                    HttpCookie authIdCookie = HttpContext.Current.Request.Cookies[m_authIDKey];
                    authIdCookie.Expires = authIdCookie.Expires.AddMinutes(minutes);
                }
                CRMSessionManager.ExtendSession(ServiceAuthToken.GetAuthId(), minutes);
            }
            catch (Exception excp)
            {
                logger.Error("Exception ExtendExistingSession. " + excp.Message);
                throw;
            }
        }