mirror of
https://github.com/bitwarden/server.git
synced 2024-12-24 17:17:40 +01:00
abstract context building to overrideable SetContextAsync (#766)
* abstract context building to overrideable SetContextAsync * update method calls
This commit is contained in:
parent
d36c403e6b
commit
4bd3e01a80
@ -26,7 +26,7 @@ namespace Bit.Core
|
|||||||
public virtual Guid? InstallationId { get; set; }
|
public virtual Guid? InstallationId { get; set; }
|
||||||
public virtual Guid? OrganizationId { get; set; }
|
public virtual Guid? OrganizationId { get; set; }
|
||||||
|
|
||||||
public void Build(HttpContext httpContext, GlobalSettings globalSettings)
|
public async virtual Task BuildAsync(HttpContext httpContext, GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
if (_builtHttpContext)
|
if (_builtHttpContext)
|
||||||
{
|
{
|
||||||
@ -35,7 +35,7 @@ namespace Bit.Core
|
|||||||
|
|
||||||
_builtHttpContext = true;
|
_builtHttpContext = true;
|
||||||
HttpContext = httpContext;
|
HttpContext = httpContext;
|
||||||
Build(httpContext.User, globalSettings);
|
await BuildAsync(httpContext.User, globalSettings);
|
||||||
|
|
||||||
if (DeviceIdentifier == null && httpContext.Request.Headers.ContainsKey("Device-Identifier"))
|
if (DeviceIdentifier == null && httpContext.Request.Headers.ContainsKey("Device-Identifier"))
|
||||||
{
|
{
|
||||||
@ -49,7 +49,7 @@ namespace Bit.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Build(ClaimsPrincipal user, GlobalSettings globalSettings)
|
public async virtual Task BuildAsync(ClaimsPrincipal user, GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
if (_builtClaimsPrincipal)
|
if (_builtClaimsPrincipal)
|
||||||
{
|
{
|
||||||
@ -58,9 +58,14 @@ namespace Bit.Core
|
|||||||
|
|
||||||
_builtClaimsPrincipal = true;
|
_builtClaimsPrincipal = true;
|
||||||
IpAddress = HttpContext.GetIpAddress(globalSettings);
|
IpAddress = HttpContext.GetIpAddress(globalSettings);
|
||||||
|
await SetContextAsync(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual Task SetContextAsync(ClaimsPrincipal user)
|
||||||
|
{
|
||||||
if (user == null || !user.Claims.Any())
|
if (user == null || !user.Claims.Any())
|
||||||
{
|
{
|
||||||
return;
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
var claimsDict = user.Claims.GroupBy(c => c.Type).ToDictionary(c => c.Key, c => c.Select(v => v));
|
var claimsDict = user.Claims.GroupBy(c => c.Type).ToDictionary(c => c.Key, c => c.Select(v => v));
|
||||||
@ -143,6 +148,7 @@ namespace Bit.Core
|
|||||||
Type = OrganizationUserType.Manager
|
Type = OrganizationUserType.Manager
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
return Task.FromResult(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool OrganizationUser(Guid orgId)
|
public bool OrganizationUser(Guid orgId)
|
||||||
|
@ -14,7 +14,7 @@ namespace Bit.Core.Utilities
|
|||||||
|
|
||||||
public async Task Invoke(HttpContext httpContext, CurrentContext currentContext, GlobalSettings globalSettings)
|
public async Task Invoke(HttpContext httpContext, CurrentContext currentContext, GlobalSettings globalSettings)
|
||||||
{
|
{
|
||||||
currentContext.Build(httpContext, globalSettings);
|
await currentContext.BuildAsync(httpContext, globalSettings);
|
||||||
await _next.Invoke(httpContext);
|
await _next.Invoke(httpContext);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ namespace Bit.Notifications
|
|||||||
public override async Task OnConnectedAsync()
|
public override async Task OnConnectedAsync()
|
||||||
{
|
{
|
||||||
var currentContext = new CurrentContext();
|
var currentContext = new CurrentContext();
|
||||||
currentContext.Build(Context.User, _globalSettings);
|
await currentContext.BuildAsync(Context.User, _globalSettings);
|
||||||
if (currentContext.Organizations != null)
|
if (currentContext.Organizations != null)
|
||||||
{
|
{
|
||||||
foreach (var org in currentContext.Organizations)
|
foreach (var org in currentContext.Organizations)
|
||||||
@ -35,7 +35,7 @@ namespace Bit.Notifications
|
|||||||
public override async Task OnDisconnectedAsync(Exception exception)
|
public override async Task OnDisconnectedAsync(Exception exception)
|
||||||
{
|
{
|
||||||
var currentContext = new CurrentContext();
|
var currentContext = new CurrentContext();
|
||||||
currentContext.Build(Context.User, _globalSettings);
|
await currentContext.BuildAsync(Context.User, _globalSettings);
|
||||||
if (currentContext.Organizations != null)
|
if (currentContext.Organizations != null)
|
||||||
{
|
{
|
||||||
foreach (var org in currentContext.Organizations)
|
foreach (var org in currentContext.Organizations)
|
||||||
|
Loading…
Reference in New Issue
Block a user