public async Task <IActionResult> Get(string id)
        {
            try
            {
                if (!HttpContext.Request.IsHttps)//if request is not https, then throw unauthorized exception
                {
                    throw new UnauthorizedAccessException("Request must be HTTPS");
                }

                Guid entityId = new Guid(id);

                var existingCredential = repository.GetOne(entityId);
                if (existingCredential == null)
                {
                    return(NotFound());
                }

                if (_credentialManager.ValidateRetrievalDate(existingCredential))
                {
                    existingCredential.PasswordSecret = _credentialManager.GetPassword(existingCredential);
                    return(Ok(existingCredential));
                }
                ModelState.AddModelError("Credential", "Current date does not fall withing the start and end date range");
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Get(string id)
        {
            try
            {
                Guid entityId = new Guid(id);

                var existingAgent = repository.GetOne(entityId);
                if (existingAgent == null)
                {
                    return(NotFound());
                }

                if (credentialManager.ValidateRetrievalDate(existingAgent))
                {
                    return(await base.GetEntity(id));
                }
                ModelState.AddModelError("Credential", "Current date does not fall withing the start and end date range");
                return(BadRequest(ModelState));
            }
            catch (Exception ex)
            {
                return(ex.GetActionResult());
            }
        }