async public Task <bool> CreateLockerAsync(SecretsLocker secretsLocker, CancellationToken cancellationToken) { if (String.IsNullOrWhiteSpace(secretsLocker?.Name)) { throw new StatusMessageException("Invalid locker name"); } var di = new DirectoryInfo($"{ _rootPath }/{ secretsLocker.Name }"); if (di.Exists) { throw new StatusMessageException($"Locker { secretsLocker.Name } already exists"); } di.Create(); byte[] buffer = Encoding.UTF8.GetBytes( _cryptoService.EncryptText(_blobSerializer.SerializeObject(secretsLocker))); using (var fs = new FileStream($"{ di.FullName }/_item.meta", FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, buffer.Length, true)) { await fs.WriteAsync(buffer, 0, buffer.Length); } return(true); }
async public Task <IdentityResult> CreateAsync(ApplicationRole role, CancellationToken cancellationToken) { role.Id = RolenameToId(role); FileInfo fi = new FileInfo($"{ _rootPath }/{ role.Id }.role"); if (fi.Exists) { return(IdentityResult.Failed(new IdentityError() { Code = "already_exists", Description = "Role already exists" })); } byte[] buffer = Encoding.UTF8.GetBytes( _cryptoService.EncryptText(_blobSerializer.SerializeObject(role))); using (var fs = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, buffer.Length, true)) { await fs.WriteAsync(buffer, 0, buffer.Length); } return(IdentityResult.Success); }
async public Task <IdentityResult> CreateAsync(ApplicationUser user, CancellationToken cancellationToken) { if (user.UserName.ToUpper() != user.Email.ToUpper()) { return(IdentityResult.Failed(new IdentityError() { Code = "invalid_username", Description = "username and email must be identical" })); } user.Id = UsernameToId(user); FileInfo fi = new FileInfo($"{ _rootPath }/{ user.Id }.user"); if (fi.Exists) { return(IdentityResult.Failed(new IdentityError() { Code = "already_exists", Description = "User already exists" })); } byte[] buffer = Encoding.UTF8.GetBytes( _cryptoService.EncryptText(_blobSerializer.SerializeObject(user))); using (var fs = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, buffer.Length, true)) { await fs.WriteAsync(buffer, 0, buffer.Length); } return(IdentityResult.Success); }
public BlobTableEntity(string partitionKey, string rowKey, object dataObject, ICryptoService cryptoService, IBlobSerializer blobSerializer) { this.PartitionKey = partitionKey; this.RowKey = rowKey; this.Blob = cryptoService.EncryptText(blobSerializer.SerializeObject(dataObject)); }
async public Task AddApiResourceAsync(ApiResourceModel apiResource) { string id = apiResource.Name.NameToHexId(_cryptoService); FileInfo fi = new FileInfo($"{ _rootPath }/{ id }.api"); if (fi.Exists) { throw new Exception("Api already exists"); } byte[] buffer = Encoding.UTF8.GetBytes( _cryptoService.EncryptText(_blobSerializer.SerializeObject(apiResource))); using (var fs = new FileStream(fi.FullName, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None, buffer.Length, true)) { await fs.WriteAsync(buffer, 0, buffer.Length); } }
async public Task AddApiResourceAsync(ApiResourceModel apiResource) { if (apiResource == null) { return; } if (await FindApiResourceAsync(apiResource.Name) != null) { throw new Exception("Api resource alread exists"); } string id = apiResource.Name.ApiNameToHexId(_cryptoService); var collection = GetApiResourceCollection(); var document = new ApiResourceDocument() { Id = id, BlobData = _cryptoService.EncryptText(_blobSerializer.SerializeObject(apiResource)) }; await collection.InsertOneAsync(document); }
async public Task AddClientAsync(ClientModel client) { if (client == null) { return; } if (await FindClientByIdAsync(client.ClientId) != null) { throw new Exception("client alread exists"); } string id = client.ClientId.ClientIdToHexId(_cryptoService); var collection = GetCollection(); var document = new ClientBlobDocument() { Id = id, BlobData = _cryptoService.EncryptText(_blobSerializer.SerializeObject(client)) }; await collection.InsertOneAsync(document); }