I am trying to use policy based authorisation in an MVC app in C# .NET CORE (8) , using membership of OnPrem AD groups to assign roles .
This is a snippet of the appsettings.json telling the system I want to grant the Admin role to members of AD Group1, and so on for the Editors & Readers roles :
"AppConfig": {
"Admins": "AD Group1",
"Editors": "AD Group2",
"Readers": "AD Group3",
"DBConnstr2": "myconnstr"
}
This is a snippet of the Program.cs to actually apply the policy
var Admins = builder.Configuration["AppConfig:Admins"];
var Editors = builder.Configuration["AppConfig:Editors"];
var Readers = builder.Configuration["AppConfig:Readers"];
builder.Services.AddAuthorization(options =>
{
options.AddPolicy("Admins", policy => policy.RequireRole(Admins));
options.AddPolicy("Editors", policy => policy.RequireRole(Editors));
options.AddPolicy("Readers", policy => policy.RequireRole(Readers));
});
These roles are used in the MVC controllers to apply permissions to each function
[Authorize(Policy = "Readers")]
public async Task<IActionResult> Index(){
}
The problem is that some of the AD Groups do not get mapped into roles, for example my user claims lists me as a member of AD Group1 , 2 & 3, but the roles I have do not include the Editors role ( I get the role when I set a different group in AppConfig:Editors). This suggests that something is different about how Group2 is set up.
What is causing this, & what do I need to do get AD Group 2 behaving in the same way as Groups 1 & 3?
Thanks in advance