Ejemplo n.º 1
0
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            HttpContext context = HttpContext.Current;

            var authorizationAttributes = actionContext.ActionDescriptor.GetCustomAttributes <AllowAnonymousAttribute>();

            if (authorizationAttributes.Count() > 0)
            {
                base.OnActionExecuting(actionContext);
                return;
            }


            try
            {
                var strAuthorization     = actionContext.Request.Headers.GetValues("Authorization").FirstOrDefault();
                var strJsonSecurityToken = EncDec.Decrypt(strAuthorization.Substring(7));

                PayloadDto oPayloadDto = null;
                oPayloadDto = new JavaScriptSerializer().Deserialize <PayloadDto>(strJsonSecurityToken);
                DateTime dteExpireDate = new DateTime(oPayloadDto.expireDate);
                if (dteExpireDate <= DateTime.Now)
                {
                    throw new Exception();
                }

                Setting.payloadDto = oPayloadDto;
            }

            catch (Exception ex)
            {
                actionContext.Response = new System.Net.Http.HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
            }
        }
Ejemplo n.º 2
0
        internal byte[] Serialize()
        {
            var dto = new PayloadDto()
            {
                Key             = Key,
                RelativeQuality = RelativeQuality,
                CustomData      = _customData.Count > 0 ? _customData : null
            };

            return(dto.Serialize());
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Filter payloadDto
 /// </summary>
 /// <param name="payloadDto"></param>
 /// <returns></returns>
 public IEnumerable <PayloadItemShortDto> FilterPayload(PayloadDto payloadDto)
 {
     return(from item in payloadDto.Payload
            where item != null &&
            item.Drm.HasValue &&
            item.Drm == true &&
            item.EpisodeCount.HasValue &&
            item.EpisodeCount > 0
            select new PayloadItemShortDto
     {
         Image = item.Image.ShowImage,
         Slug = item.Slug,
         Title = item.Title
     });
 }
Ejemplo n.º 4
0
        public PayloadDto DecodeToken(string token)
        {
            string payload      = "{";
            var    tokenHandler = new JwtSecurityTokenHandler();

            if (tokenHandler.CanReadToken(token))
            {
                var securityToken = tokenHandler.ReadJwtToken(token);
                foreach (Claim c in securityToken.Claims)
                {
                    payload += '"' + c.Type + "\":\"" + c.Value + "\",";
                }
            }
            payload += "}";

            PayloadDto payloadDto = JsonConvert.DeserializeObject <PayloadDto>(payload);

            return(payloadDto);
        }
Ejemplo n.º 5
0
        public IHttpActionResult FilterPayload([FromBody] PayloadDto payloadDto)
        {
            if (!_dataService.ValidatePayload(payloadDto))
            {
                //if invalid, return 400 with message
                return(Content(HttpStatusCode.BadRequest,
                               new ErrorMessageDto {
                    Error = "Could not decode request: JSON parsing failed"
                }));
            }

            var data = _dataService.FilterPayload(payloadDto);

            var payloadItemShortDtos = data as PayloadItemShortDto[] ?? data.ToArray();

            return(Ok(new PayloadResponseDto {
                Response = payloadItemShortDtos
            }));
        }
Ejemplo n.º 6
0
        public async Task <JasonWebTokenDto> Login(UserLoginDto userLoginDto)
        {
            string strPassword = EncDec.Encrypt(userLoginDto.password);
            string strUsername = userLoginDto.username;

            var oUserDto = await _AccountingService.getAndCheckLoginUser(strUsername, strPassword);

            if (oUserDto == null)
            {
                return(null);
            }
            //  oResult.resultCode = "404";
            //  oResult.userInfo = null;
            //  oResult.menutitlesDto = null;
            //  oResult.resultCode = "200";
            // oResult.userInfo = oUserDto;
            //  Session["UserInfo"] = oUserDto;

            var oPayloadDto = new PayloadDto()
            {
                expireDate  = DateTime.Now.AddMinutes(Setting.JWT_TIMEOUT_MINUTE).Ticks,
                companyId   = oUserDto.companyId,
                isDataAdmin = oUserDto.isDataAdmin,
                isItemAdmin = oUserDto.isItemAdmin,
                userId      = oUserDto.id,
            };

            var strJsonSecurityToken = new JavaScriptSerializer().Serialize(oPayloadDto);
            var strEncryptedJson     = EncDec.Encrypt(strJsonSecurityToken);

            return(new JasonWebTokenDto()
            {
                JWT = strEncryptedJson,
            });

            //var oMenutitlesDto = _AccountingService.getMenutitles(oUserDto.id, oUserDto.isItemAdmin);
            // Session["Menutitles"] = oMenutitlesDto;

            //         oResult.resultCode = "200";
        }
Ejemplo n.º 7
0
        public async Task <IActionResult> Create([FromBody][Required] PayloadDto request)
        {
            _logger.LogInformation(ConstantVarriables.AzureServiceBusApiCreateEnterMessage);
            ObjectResult response;

            try
            {
                await _serviceBusSender.SendMessage(new Payload
                {
                    Goals  = request.Goals,
                    Name   = request.Name,
                    Delete = false
                });

                response = Ok(ConstantVarriables.TopicPushSuccessMessage + " TopicName:" + request.Name);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex, ex.Message);
                response = BadRequest(ConstantVarriables.GenericExeptionMessage);
            }
            _logger.LogInformation(ConstantVarriables.AzureServiceBusApiCreateExitMessage);
            return(response);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Validate payloadDto
 /// </summary>
 /// <param name="payloadDto"></param>
 /// <returns></returns>
 public bool ValidatePayload(PayloadDto payloadDto)
 {
     return(payloadDto != null && payloadDto.Payload != null);
 }
Ejemplo n.º 9
0
        public static EnqueueTokenPayload Deserialize(string input, string secretKey, string tokenIdentifier)
        {
            var dto = PayloadDto.DeserializePayload(input, secretKey, tokenIdentifier);

            return(new EnqueueTokenPayload(dto.Key, dto.RelativeQuality, dto.CustomData));
        }