private async Task <Box> GetBoxAsyncOrFail(string box) { var boxEntry = await _boxRepository.GetAsync(box); if (boxEntry == null) { throw new ArgumentNullException(nameof(boxEntry), $"Box '{box}' has not been found."); } return(boxEntry); }
public async Task <object> GetValueAsync(string box, string key, string encryptionKey) { var entryBox = await _boxRepository.GetAsync(box); if (entryBox == null) { throw new ArgumentException($"Box '{box}' has not been found."); } var entry = entryBox.GetEntry(key); if (entry == null) { return(null); } var value = _encrypter.Decrypt(entry.Value, entry.Salt, encryptionKey); return(JsonConvert.DeserializeObject(value)); }
public async Task <BoxDto> Handle(GetBoxByIdQuery request, CancellationToken cancellationToken) { var result = await _boxRepo.GetAsync(request.Id); return(new BoxDto { Id = result.Id, Name = result.BoxName, Notes = result.Notes }); }
private async Task ValidatePermission(string username, string box, Permission permission) { var entryBox = await _boxRepository.GetAsync(box); if (entryBox == null) { throw new ArgumentException($"Box '{box}' has not been found."); } var user = await _userRepository.GetAsync(username); if (user == null) { throw new ArgumentException($"User '{username}' has not been found.", nameof(username)); } if (!user.IsActive) { throw new AuthenticationException($"User '{username}' is not active."); } if (user.Role == Role.Admin) { return; } var boxUser = entryBox.GetUser(username); if (boxUser == null) { throw new ArgumentException($"User '{username}' has not been found in box {box}.", nameof(username)); } if (boxUser.Permissions.Contains(permission)) { return; } throw new AuthenticationException($"User '{username}' does not have permission '{permission}' in box '{box}'."); }
public async Task <Box> GetAsync(string name) => await _boxRepository.GetAsync(name);