Add hubType to HubInvocationContext (#14459)
This commit is contained in:
parent
1ba180e87c
commit
b960e07e37
|
|
@ -176,9 +176,11 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
public partial class HubInvocationContext
|
public partial class HubInvocationContext
|
||||||
{
|
{
|
||||||
public HubInvocationContext(Microsoft.AspNetCore.SignalR.HubCallerContext context, string hubMethodName, object[] hubMethodArguments) { }
|
public HubInvocationContext(Microsoft.AspNetCore.SignalR.HubCallerContext context, string hubMethodName, object[] hubMethodArguments) { }
|
||||||
|
public HubInvocationContext(Microsoft.AspNetCore.SignalR.HubCallerContext context, System.Type hubType, string hubMethodName, object[] hubMethodArguments) { }
|
||||||
public Microsoft.AspNetCore.SignalR.HubCallerContext Context { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
public Microsoft.AspNetCore.SignalR.HubCallerContext Context { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
||||||
public System.Collections.Generic.IReadOnlyList<object> HubMethodArguments { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
public System.Collections.Generic.IReadOnlyList<object> HubMethodArguments { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
||||||
public string HubMethodName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
public string HubMethodName { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
||||||
|
public System.Type HubType { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
|
||||||
}
|
}
|
||||||
public abstract partial class HubLifetimeManager<THub> where THub : Microsoft.AspNetCore.SignalR.Hub
|
public abstract partial class HubLifetimeManager<THub> where THub : Microsoft.AspNetCore.SignalR.Hub
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
// Copyright (c) .NET Foundation. All rights reserved.
|
// Copyright (c) .NET Foundation. All rights reserved.
|
||||||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
||||||
|
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Microsoft.AspNetCore.Authorization;
|
using Microsoft.AspNetCore.Authorization;
|
||||||
|
|
||||||
|
|
@ -11,6 +12,18 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class HubInvocationContext
|
public class HubInvocationContext
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a new instance of the <see cref="HubInvocationContext"/> class.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="context">Context for the active Hub connection and caller.</param>
|
||||||
|
/// <param name="hubType">The type of the Hub.</param>
|
||||||
|
/// <param name="hubMethodName">The name of the Hub method being invoked.</param>
|
||||||
|
/// <param name="hubMethodArguments">The arguments provided by the client.</param>
|
||||||
|
public HubInvocationContext(HubCallerContext context, Type hubType, string hubMethodName, object[] hubMethodArguments): this(context, hubMethodName, hubMethodArguments)
|
||||||
|
{
|
||||||
|
HubType = hubType;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Instantiates a new instance of the <see cref="HubInvocationContext"/> class.
|
/// Instantiates a new instance of the <see cref="HubInvocationContext"/> class.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -29,6 +42,11 @@ namespace Microsoft.AspNetCore.SignalR
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public HubCallerContext Context { get; }
|
public HubCallerContext Context { get; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the Hub type.
|
||||||
|
/// </summary>
|
||||||
|
public Type HubType { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the name of the Hub method being invoked.
|
/// Gets the name of the Hub method being invoked.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
||||||
|
|
@ -495,7 +495,7 @@ namespace Microsoft.AspNetCore.SignalR.Internal
|
||||||
return TaskCache.True;
|
return TaskCache.True;
|
||||||
}
|
}
|
||||||
|
|
||||||
return IsHubMethodAuthorizedSlow(provider, hubConnectionContext.User, policies, new HubInvocationContext(hubConnectionContext.HubCallerContext, hubMethodName, hubMethodArguments));
|
return IsHubMethodAuthorizedSlow(provider, hubConnectionContext.User, policies, new HubInvocationContext(hubConnectionContext.HubCallerContext, typeof(THub), hubMethodName, hubMethodArguments));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async Task<bool> IsHubMethodAuthorizedSlow(IServiceProvider provider, ClaimsPrincipal principal, IList<IAuthorizeData> policies, HubInvocationContext resource)
|
private static async Task<bool> IsHubMethodAuthorizedSlow(IServiceProvider provider, ClaimsPrincipal principal, IList<IAuthorizeData> policies, HubInvocationContext resource)
|
||||||
|
|
|
||||||
|
|
@ -2215,6 +2215,7 @@ namespace Microsoft.AspNetCore.SignalR.Tests
|
||||||
{
|
{
|
||||||
Assert.NotNull(context.Resource);
|
Assert.NotNull(context.Resource);
|
||||||
var resource = Assert.IsType<HubInvocationContext>(context.Resource);
|
var resource = Assert.IsType<HubInvocationContext>(context.Resource);
|
||||||
|
Assert.Equal(typeof(MethodHub), resource.HubType);
|
||||||
Assert.Equal(nameof(MethodHub.MultiParamAuthMethod), resource.HubMethodName);
|
Assert.Equal(nameof(MethodHub.MultiParamAuthMethod), resource.HubMethodName);
|
||||||
Assert.Equal(2, resource.HubMethodArguments?.Count);
|
Assert.Equal(2, resource.HubMethodArguments?.Count);
|
||||||
Assert.Equal("Hello", resource.HubMethodArguments[0]);
|
Assert.Equal("Hello", resource.HubMethodArguments[0]);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue