#306 Consistently use WindowsPrincipal

This commit is contained in:
Chris R 2017-03-01 16:08:42 -08:00
parent d103bdb1ba
commit c328e22699
4 changed files with 10 additions and 6 deletions

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http.Features.Authentication; using Microsoft.AspNetCore.Http.Features.Authentication;
using Microsoft.Extensions.Internal; using Microsoft.Extensions.Internal;
@ -25,7 +26,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
public Task AuthenticateAsync(AuthenticateContext context) public Task AuthenticateAsync(AuthenticateContext context)
{ {
var identity = (ClaimsIdentity)_requestContext.User?.Identity; var identity = _requestContext.User?.Identity;
foreach (var authType in ListEnabledAuthSchemes()) foreach (var authType in ListEnabledAuthSchemes())
{ {
@ -35,7 +36,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
if (identity != null && identity.IsAuthenticated if (identity != null && identity.IsAuthenticated
&& string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal)) && string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal))
{ {
context.Authenticated(new ClaimsPrincipal(identity), properties: null, description: GetDescription(authScheme)); context.Authenticated(_requestContext.User, properties: null, description: null);
} }
else else
{ {

View File

@ -212,7 +212,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
return false; return false;
} }
internal ClaimsPrincipal GetUser() internal WindowsPrincipal GetUser()
{ {
var requestInfo = NativeRequestV2->pRequestInfo; var requestInfo = NativeRequestV2->pRequestInfo;
var infoCount = NativeRequestV2->RequestInfoCount; var infoCount = NativeRequestV2->RequestInfoCount;
@ -228,7 +228,8 @@ namespace Microsoft.AspNetCore.Server.HttpSys
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString())); GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
} }
} }
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated
return new WindowsPrincipal(WindowsIdentity.GetAnonymous()); // Anonymous / !IsAuthenticated
} }
private static AuthenticationSchemes GetAuthTypeFromRequest(HttpApi.HTTP_REQUEST_AUTH_TYPE input) private static AuthenticationSchemes GetAuthTypeFromRequest(HttpApi.HTTP_REQUEST_AUTH_TYPE input)

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Net; using System.Net;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -214,7 +215,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
// HTTP.Sys allows you to upgrade anything to opaque unless content-length > 0 or chunked are specified. // HTTP.Sys allows you to upgrade anything to opaque unless content-length > 0 or chunked are specified.
internal bool IsUpgradable => !HasEntityBody && ComNetOS.IsWin8orLater; internal bool IsUpgradable => !HasEntityBody && ComNetOS.IsWin8orLater;
internal ClaimsPrincipal User { get; } internal WindowsPrincipal User { get; }
// Populates the client certificate. The result may be null if there is no client cert. // Populates the client certificate. The result may be null if there is no client cert.
// TODO: Does it make sense for this to be invoked multiple times (e.g. renegotiate)? Client and server code appear to // TODO: Does it make sense for this to be invoked multiple times (e.g. renegotiate)? Client and server code appear to

View File

@ -6,6 +6,7 @@ using System.Diagnostics;
using System.IO; using System.IO;
using System.Security.Authentication.ExtendedProtection; using System.Security.Authentication.ExtendedProtection;
using System.Security.Claims; using System.Security.Claims;
using System.Security.Principal;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -39,7 +40,7 @@ namespace Microsoft.AspNetCore.Server.HttpSys
public Response Response { get; } public Response Response { get; }
public ClaimsPrincipal User => Request.User; public WindowsPrincipal User => Request.User;
public CancellationToken DisconnectToken public CancellationToken DisconnectToken
{ {