コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: EntryService.cs プロジェクト: tuongntk/Lockbox
        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));
        }
コード例 #3
0
ファイル: GetBoxByIdQueryHandler.cs プロジェクト: Tappau/Boxi
        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
            });
        }
コード例 #4
0
        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}'.");
        }
コード例 #5
0
 public async Task <Box> GetAsync(string name)
 => await _boxRepository.GetAsync(name);