Skip to content
This repository was archived by the owner on Mar 19, 2019. It is now read-only.

Commit c328e22

Browse files
committed
#306 Consistently use WindowsPrincipal
1 parent d103bdb commit c328e22

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

src/Microsoft.AspNetCore.Server.HttpSys/AuthenticationHandler.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Security.Claims;
7+
using System.Security.Principal;
78
using System.Threading.Tasks;
89
using Microsoft.AspNetCore.Http.Features.Authentication;
910
using Microsoft.Extensions.Internal;
@@ -25,7 +26,7 @@ internal AuthenticationHandler(RequestContext requestContext)
2526

2627
public Task AuthenticateAsync(AuthenticateContext context)
2728
{
28-
var identity = (ClaimsIdentity)_requestContext.User?.Identity;
29+
var identity = _requestContext.User?.Identity;
2930

3031
foreach (var authType in ListEnabledAuthSchemes())
3132
{
@@ -35,7 +36,7 @@ public Task AuthenticateAsync(AuthenticateContext context)
3536
if (identity != null && identity.IsAuthenticated
3637
&& string.Equals(authScheme, identity.AuthenticationType, StringComparison.Ordinal))
3738
{
38-
context.Authenticated(new ClaimsPrincipal(identity), properties: null, description: GetDescription(authScheme));
39+
context.Authenticated(_requestContext.User, properties: null, description: null);
3940
}
4041
else
4142
{

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/NativeRequestContext.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ internal bool CheckAuthenticated()
212212
return false;
213213
}
214214

215-
internal ClaimsPrincipal GetUser()
215+
internal WindowsPrincipal GetUser()
216216
{
217217
var requestInfo = NativeRequestV2->pRequestInfo;
218218
var infoCount = NativeRequestV2->RequestInfoCount;
@@ -228,7 +228,8 @@ internal ClaimsPrincipal GetUser()
228228
GetAuthTypeFromRequest(info->pInfo->AuthType).ToString()));
229229
}
230230
}
231-
return new ClaimsPrincipal(new ClaimsIdentity()); // Anonymous / !IsAuthenticated
231+
232+
return new WindowsPrincipal(WindowsIdentity.GetAnonymous()); // Anonymous / !IsAuthenticated
232233
}
233234

234235
private static AuthenticationSchemes GetAuthTypeFromRequest(HttpApi.HTTP_REQUEST_AUTH_TYPE input)

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/Request.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Net;
88
using System.Security.Claims;
99
using System.Security.Cryptography.X509Certificates;
10+
using System.Security.Principal;
1011
using System.Threading;
1112
using System.Threading.Tasks;
1213

@@ -214,7 +215,7 @@ private SocketAddress LocalEndPoint
214215
// HTTP.Sys allows you to upgrade anything to opaque unless content-length > 0 or chunked are specified.
215216
internal bool IsUpgradable => !HasEntityBody && ComNetOS.IsWin8orLater;
216217

217-
internal ClaimsPrincipal User { get; }
218+
internal WindowsPrincipal User { get; }
218219

219220
// Populates the client certificate. The result may be null if there is no client cert.
220221
// TODO: Does it make sense for this to be invoked multiple times (e.g. renegotiate)? Client and server code appear to

src/Microsoft.AspNetCore.Server.HttpSys/RequestProcessing/RequestContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO;
77
using System.Security.Authentication.ExtendedProtection;
88
using System.Security.Claims;
9+
using System.Security.Principal;
910
using System.Threading;
1011
using System.Threading.Tasks;
1112
using Microsoft.AspNetCore.Http;
@@ -39,7 +40,7 @@ internal RequestContext(HttpSysListener server, NativeRequestContext memoryBlob)
3940

4041
public Response Response { get; }
4142

42-
public ClaimsPrincipal User => Request.User;
43+
public WindowsPrincipal User => Request.User;
4344

4445
public CancellationToken DisconnectToken
4546
{

0 commit comments

Comments
 (0)