Exemplo n.º 1
0
        private Customer AuthoriseRequest()
        {
            try
            {
                string apiKey = ServiceAuthToken.GetAPIKey();

                if (!apiKey.IsNullOrBlank())
                {
                    Customer customer = m_service.GetCustomerForAPIKey(apiKey);
                    if (customer == null)
                    {
                        throw new ApplicationException("The " + ServiceAuthToken.API_KEY + " header value was not recognised as belonging to a valid account.");
                    }
                    else if (customer.Suspended)
                    {
                        throw new ApplicationException("Your account is suspended.");
                    }
                    else
                    {
                        return(customer);
                    }
                }
                else
                {
                    throw new ApplicationException("No " + ServiceAuthToken.API_KEY + " header was found in the request.");
                }
            }
            catch (Exception excp)
            {
                logger.Error("Exception Provisioning.AuthoriseRequest. " + excp.Message);
                throw;
            }
        }
Exemplo 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.");
            }
        }