I am developing an intranet asp.net core web api application. The requirements for authentications are:
- REQ1 - when user which is trying to access the website is not in Active Directory's special group (let's name it "commonUsers") it is simply not authorized
- REQ2 - when user which is trying to access the website is in Active Directory's group "commonUsers" is is authorized and a web resource is returned
- REQ3 - when user which is trying to access the website is in Active Directory's group "superUser", it need to be prompted for his domain password once again (because it tries to access some very restricted resources)
Now, what I have so far:
- My service is hosted using http.sys server in order to support windows authentication.
I am using claims transformer middlewere in order to check the user's Active Directory group, let's say something like this:
public class ClaimsTransformer : IClaimsTransformation { private readonly IAuthorizationService _authorizationService; public ClaimsTransformer(IAuthorizationService authorizationService) { _authorizationService = authorizationService; } public Task<ClaimsPrincipal> TransformAsync(ClaimsPrincipal principal) { _authorizationService.Authorize(principal as IHmiClaimsPrincipal); return Task.FromResult(principal); }}
I have specified a special policies also in my service configuration, for instance something like that:
services.AddAuthorization(options => { options.AddPolicy("TestPolicy", policy => policy.RequireClaim(ClaimTypes.Role, "TestUser")); options.AddPolicy("TestPolicy2", policy => policy.RequireClaim(ClaimTypes.Role, "SuperUser")); });
I am using
[Authorize]
attribute with specific policy in order to restrict access to specific resources based on policies
Now the question is, how should I satisfy REQ3?