1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-17 15:40:59 -05:00

implemented grant repository and identity server PersistedGrantStore

This commit is contained in:
Kyle Spearrin
2017-01-11 23:20:54 -05:00
parent 9749d1e3a8
commit 2abb1aaae5
5 changed files with 221 additions and 4 deletions

View File

@ -0,0 +1,17 @@
using System;
using System.Threading.Tasks;
using Bit.Core.Domains;
using System.Collections.Generic;
namespace Bit.Core.Repositories
{
public interface IGrantRepository
{
Task<Grant> GetByKeyAsync(string key);
Task<ICollection<Grant>> GetManyAsync(string subjectId);
Task SaveAsync(Grant obj);
Task DeleteAsync(string key);
Task DeleteAsync(string subjectId, string clientId);
Task DeleteAsync(string subjectId, string clientId, string type);
}
}

View File

@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Threading.Tasks;
using Bit.Core.Domains;
using Dapper;
namespace Bit.Core.Repositories.SqlServer
{
public class GrantRepository : BaseRepository, IGrantRepository
{
public GrantRepository(GlobalSettings globalSettings)
: this(globalSettings.SqlServer.ConnectionString)
{ }
public GrantRepository(string connectionString)
: base(connectionString)
{ }
public async Task<Grant> GetByKeyAsync(string key)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Grant>(
"[dbo].[Grant_ReadByKey]",
new { Key = key },
commandType: CommandType.StoredProcedure);
return results.SingleOrDefault();
}
}
public async Task<ICollection<Grant>> GetManyAsync(string subjectId)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.QueryAsync<Grant>(
"[dbo].[Grant_ReadBySubjectId]",
new { SubjectId = subjectId },
commandType: CommandType.StoredProcedure);
return results.ToList();
}
}
public async Task SaveAsync(Grant obj)
{
using(var connection = new SqlConnection(ConnectionString))
{
var results = await connection.ExecuteAsync(
"[dbo].[Grant_Save]",
obj,
commandType: CommandType.StoredProcedure);
}
}
public async Task DeleteAsync(string key)
{
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[Grant_DeleteByKey]",
new { Key = key },
commandType: CommandType.StoredProcedure);
}
}
public async Task DeleteAsync(string subjectId, string clientId)
{
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[Grant_DeleteBySubjectIdClientId]",
new { SubjectId = subjectId, ClientId = clientId },
commandType: CommandType.StoredProcedure);
}
}
public async Task DeleteAsync(string subjectId, string clientId, string type)
{
using(var connection = new SqlConnection(ConnectionString))
{
await connection.ExecuteAsync(
"[dbo].[Grant_DeleteBySubjectIdClientIdType]",
new { SubjectId = subjectId, ClientId = clientId, Type = type },
commandType: CommandType.StoredProcedure);
}
}
}
}