private long?GetAccountId() { if (!_httpContextAccessor.HttpContext.GetRouteData().Values.TryGetValue("employerAccountId", out var hashedAccountId)) { return(null); } if (!_encodingService.TryDecode(hashedAccountId.ToString(), EncodingType.AccountId, out var accountId)) { throw new UnauthorizedAccessException(); } return(accountId); }
private long?GetCohortId() { if (!TryGetValueFromHttpContext(RouteValueKeys.CohortReference, out var cohortReference)) { return(null); } if (!_encodingService.TryDecode(cohortReference, EncodingType.CohortReference, out var cohortId)) { throw new UnauthorizedAccessException($"Failed to decode '{RouteValueKeys.CohortReference}' value '{cohortReference}' using encoding type '{EncodingType.CohortReference}'"); } return(cohortId); }
public override async Task OnActionExecutionAsync( ActionExecutingContext context, ActionExecutionDelegate next) { if (_serviceParameters.AuthenticationType == AuthenticationType.Employer) { if (!context.RouteData.Values.TryGetValue("employerAccountId", out var employerAccountId)) { context.Result = new RedirectToRouteResult(RouteNames.Error500, null); return; } if (!_encodingService.TryDecode(employerAccountId.ToString(), EncodingType.AccountId, out var decodedAccountId)) { context.Result = new RedirectToRouteResult(RouteNames.Error403, null); return; } var legalEntities = await _mediator.Send(new GetLegalEntitiesQuery { AccountId = decodedAccountId }); if (legalEntities.AccountLegalEntities.Any(x => x.IsLevy)) { context.Result = new RedirectToRouteResult(RouteNames.Error403, null); return; } } await next(); }
public static bool TryDecodeSafe(this IEncodingService encodingService, string encodedValue, EncodingType encodingType, out long decodedValue) { try { return(encodingService.TryDecode(encodedValue, encodingType, out decodedValue)); } catch (Exception e) { decodedValue = 0; return(false); } }
private long?GetAndDecodeValueIfExists(string keyName, EncodingType encodedType) { if (!TryGetValueFromHttpContext(keyName, out var encodedValue)) { return(null); } if (!_encodingService.TryDecode(encodedValue, encodedType, out var id)) { throw new UnauthorizedAccessException($"Failed to decode '{keyName}' value '{encodedValue}' using encoding type '{encodedType}'"); } return(id); }
private string GetDecodingResult(EncodingType encodingType) { string message; if (_encodingService.TryDecode(_args.Value, encodingType, out var decodedValue)) { message = $"Success - {decodedValue}"; } else { message = "Decoding failed"; } return(message); }