-
Notifications
You must be signed in to change notification settings - Fork 59
Work around UnauthorizedAccessException for WindowsIdentity.get_AuthenticationType on IIS #231
Comments
Alternative solutions:
|
Note WebListener probably has the same issue. |
For the record, the underlying issue is the fact that MSDN page for LsaGetLogonSessionData states "To retrieve information about a logon session, the caller must be the owner of the session or a local system administrator." https://msdn.microsoft.com/en-us/library/windows/desktop/aa378290(v=vs.85).aspx So this issue is likely to affect all production applications that calls this code. (Any application using a policy with AuthenticationScheme of "Automatic", "Negotiate", or "NTLM"). |
@pakrym can you check WebListener as well? |
This is also happening with EF based identity, when calling
Notice the call to You can see the full source code here: https://github.com/aspnet/Identity/blob/eb3ff7fc32dbfff65a1ba6dfdca16487e0f6fc41/src/Microsoft.AspNetCore.Identity/SignInManager.cs The PR in this issue does not resolves this problem. |
Title
A
System.UnauthorizedAccessException
occurs when accessingSystem.Security.Principal.WindowsIdentity.WindowsIdentity.AuthenticationType
getter on IIS, breaking the Windows Authentication of IISIntegration.Functional impact
When using Windows Authentication, any time the
Microsoft.AspNetCore.Server.IISIntegration.AuthenticationHandler.AuthenticateAsync
method is called, which accesses theAuthenticationType
getter, the following exception is thrown:This renders the Windows Authentication unusable on our IIS deployment server.
Minimal repro steps
IISOptions
AutomaticAuthentication
andForwardWindowsAuthentication
set to true, and Cookies authentication viaUseCookieAuthentication()
. Having Windows Authentication alone should however be sufficient to reproduce.Expected result
Browser's Windows Authentication popup due to HTTP 401 response that gets the
WWW-Authenticate
header field with "NTLM" injected by IIS.Actual result
We get an unhandled exception as response, with the above mentioned exception details and causes.
Further technical details
Deployment server:
Details
Accessing the
AuthenticationType
getter works when running on IIS Express on our development machines. It also works when changing the IIS application pool identity to "LocalSystem". It also works when currently not being logged in or logged in via Cookies authentication.This stackoverflow report describes the problem in detail. There it is suggested to use another
WindowsIdentity
constructor with the AuthenticationType parameter, which should solve the problem.Solution suggestions
Maybe you could change the
AuthenticationHandler
to catch this exception and if it occurs assume Windows Authentication.Maybe use the other
WindowsIdentity
constructor inIISMiddleware
.(if that does not disregard the
AuthenticationDescriptions
option)Notes
The exception was also mentioned in issue 75, although in a different context.
The text was updated successfully, but these errors were encountered: