Merge branch 'release/2.2'

This commit is contained in:
MikaelMengistu 2018-09-20 13:48:33 -07:00
commit a2e5e8755f
13 changed files with 54 additions and 16 deletions

View File

@ -71,6 +71,8 @@
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.6.0-preview1-26907-04</SystemRuntimeCompilerServicesUnsafePackageVersion>
<SystemThreadingChannelsPackageVersion>4.6.0-preview1-26907-04</SystemThreadingChannelsPackageVersion>
<SystemThreadingTasksExtensionsPackageVersion>4.6.0-preview1-26907-04</SystemThreadingTasksExtensionsPackageVersion>
<SystemRuntimeCompilerServicesUnsafePackageVersion>4.5.1</SystemRuntimeCompilerServicesUnsafePackageVersion>
<SystemSecurityPrincipalWindowsPackageVersion>4.5.0</SystemSecurityPrincipalWindowsPackageVersion>
<XunitAssertPackageVersion>2.3.1</XunitAssertPackageVersion>
<XunitExtensibilityCorePackageVersion>2.3.1</XunitExtensibilityCorePackageVersion>
<XunitPackageVersion>2.3.1</XunitPackageVersion>

View File

@ -3,7 +3,7 @@
package com.microsoft.aspnet.signalr;
public enum HubMessageType {
enum HubMessageType {
INVOCATION(1),
STREAM_ITEM(2),
COMPLETION(3),

View File

@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class HandshakeProtocolTest {
class HandshakeProtocolTest {
@Test
public void VerifyCreateHandshakerequestMessage() {

View File

@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Test;
public class HubConnectionTest {
class HubConnectionTest {
private static final String RECORD_SEPARATOR = "\u001e";
@Test

View File

@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class HubExceptionTest {
class HubExceptionTest {
@Test
public void VeryHubExceptionMesssageIsSet() {
String errorMessage = "This is a HubException";

View File

@ -12,7 +12,7 @@ import java.util.List;
import org.junit.jupiter.api.Test;
public class JsonHubProtocolTest {
class JsonHubProtocolTest {
private JsonHubProtocol jsonHubProtocol = new JsonHubProtocol();
@Test

View File

@ -8,7 +8,7 @@ import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
public class NegotiateResponseTest {
class NegotiateResponseTest {
@Test
public void VerifyNegotiateResponse() {

View File

@ -11,7 +11,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class ResolveNegotiateUrlTest {
class ResolveNegotiateUrlTest {
private static Stream<Arguments> protocols() {
return Stream.of(
Arguments.of("http://example.com/hub/", "http://example.com/hub/negotiate"),

View File

@ -9,7 +9,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.Test;
public class WebSocketTransportTest {
class WebSocketTransportTest {
@Test
public void WebsocketThrowsIfItCantConnect() throws Exception {
Transport transport = new WebSocketTransport("www.notarealurl12345.fake", new NullLogger());

View File

@ -12,7 +12,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
public class WebSocketTransportUrlFormatTest {
class WebSocketTransportUrlFormatTest {
private static Stream<Arguments> protocols() {
return Stream.of(
Arguments.of("http://example.com", "ws://example.com"),

View File

@ -6,6 +6,7 @@ using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO.Pipelines;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
@ -208,6 +209,14 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
Cancellation?.Dispose();
Cancellation = null;
if (User != null && User.Identity is WindowsIdentity)
{
foreach (var identity in User.Identities)
{
(identity as IDisposable)?.Dispose();
}
}
}
await disposeTask;

View File

@ -7,11 +7,11 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.IO.Pipelines;
using System.Security.Claims;
using System.Security.Principal;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Connections;
using Microsoft.AspNetCore.Connections.Features;
using Microsoft.AspNetCore.Http.Connections.Features;
using Microsoft.AspNetCore.Http.Connections.Internal.Transports;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Internal;
@ -608,9 +608,6 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
return false;
}
// Setup the connection state from the http context
connection.User = context.User;
// Configure transport-specific features.
if (transportType == HttpTransportType.LongPolling)
{
@ -630,7 +627,15 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
{
// Set the request trace identifier to the current http request handling the poll
existing.TraceIdentifier = context.TraceIdentifier;
existing.User = context.User;
// Don't copy the identity if it's a windows identity
// We specifically clone the identity on first poll if it's a windows identity
// If we swapped the new User here we'd have to dispose the old identities which could race with the application
// trying to access the identity.
if (context.User.Identity is WindowsIdentity)
{
existing.User = context.User;
}
}
}
else
@ -638,6 +643,9 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
connection.HttpContext = context;
}
// Setup the connection state from the http context
connection.User = connection.HttpContext.User;
// Set the Connection ID on the logging scope so that logs from now on will have the
// Connection ID metadata set.
logScope.ConnectionId = connection.ConnectionId;
@ -645,6 +653,23 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
return true;
}
private static void CloneUser(HttpContext newContext, HttpContext oldContext)
{
if (oldContext.User.Identity is WindowsIdentity)
{
newContext.User = new ClaimsPrincipal();
foreach (var identity in oldContext.User.Identities)
{
newContext.User.AddIdentity(identity.Clone());
}
}
else
{
newContext.User = oldContext.User;
}
}
private static HttpContext CloneHttpContext(HttpContext context)
{
// The reason we're copying the base features instead of the HttpContext properties is
@ -692,7 +717,8 @@ namespace Microsoft.AspNetCore.Http.Connections.Internal
var newHttpContext = new DefaultHttpContext(features);
newHttpContext.TraceIdentifier = context.TraceIdentifier;
newHttpContext.User = context.User;
CloneUser(newHttpContext, context);
// Making request services function property could be tricky and expensive as it would require
// DI scope per connection. It would also mean that services resolved in middleware leading up to here

View File

@ -29,6 +29,7 @@
<PackageReference Include="Microsoft.Extensions.WebEncoders.Sources" Version="$(MicrosoftExtensionsWebEncodersSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.ValueStopwatch.Sources" Version="$(MicrosoftExtensionsValueStopwatchSourcesPackageVersion)" PrivateAssets="All" />
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
<PackageReference Include="System.Security.Principal.Windows" Version="$(SystemSecurityPrincipalWindowsPackageVersion)" />
</ItemGroup>
</Project>