Example #1
0
 public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
 {
     base.OnActionExecuted(actionExecutedContext);
     filterUtils.Translation(actionExecutedContext.ActionContext);
 }
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            bool         faultOccured = false;
            ResponseBase r            = new ResponseBase();

            try
            {
                base.OnAuthorization(actionContext);
                if (actionContext.ActionDescriptor.GetCustomAttributes <CredentialsHeaderAttribute>().Count == 0)
                {
                    return;
                }
                string credentialsValue = actionContext.Request.Headers.GetValues("Authorization").ElementAt(0);

                AccessCredentials credentials = new AccessCredentials();
                ParseAuthorizationHeader(credentialsValue, credentials, r);


                if (r.ErrorList.Count > 0)
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, r, GlobalConfiguration.Configuration);
                    faultOccured           = true;

                    return;
                }

                validateUserIdWithToken(r, credentials);

                if (!credentials.IsValid(r))
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, r, GlobalConfiguration.Configuration);
                    faultOccured           = true;

                    return;
                }



                var Controller = actionContext.ControllerContext.Controller as Controllers.RESTAPIControllerBase;
                Controller.UserID       = credentials.UserID;
                Controller.SessionToken = credentials.SessionToken;
                Controller.CallerId     = credentials.CallerId;
                Controller.LanguageCode = credentials.LanguageCode;
                Controller.CountryCode  = credentials.CountryCode;
                Controller.Token        = credentials.Token;
                Controller.LoginDate    = credentials.LoginDate;

                if (credentials.Platform != null)
                {
                    var isPlatformDefined = Enum.IsDefined(typeof(RESTAPIPlatform), credentials.Platform);
                    if (isPlatformDefined)
                    {
                        Controller.ClientPlatform = (RESTAPIPlatform)Enum.Parse(typeof(RESTAPIPlatform), credentials.Platform);
                    }
                    else
                    {
                        Controller.ClientPlatform = RESTAPIPlatform.notsupported;
                    }
                }
                if (r.ErrorList.Count == 0)
                {
                    IsAuthorized(actionContext);
                }


                return;
            }
            catch (Exception)
            {
                r.ErrorList.Add(Faults.InvalidCredentials);
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.OK, r, GlobalConfiguration.Configuration);
                faultOccured           = true;
            }
            finally
            {
                APILogLevel apiLogLevel;
                Enum.TryParse(SettingRepository.Get <string>("LogAPICalls", "None"), out apiLogLevel);
                if (faultOccured)
                {
                    filterUtils.Translation(actionContext);
                    filterUtils.LogIntoAdmLogsTable(actionContext.Request, actionContext.Response, actionContext, null, apiLogLevel, faultOccured, false);
                }
            }
        }