We have an application that have three levels of roles. Depending on which role a user is in determines what they have access to. The users are in activedomain groups. The client has asked that test groups be created for test and the original groups are to be used in production. We're using web.config transforms to distinguish the groups in each environment. Previous to this the AuthorizedAttribute class was set up for a save method as follows:
The Group A and Administration are production. In test there is now Group A - Test and Administration - Test.
Here is our AuthorizeUsers class:
Is there a way to pull from the web.config file and assign it to the Roles property?
We tried the following:
But it gacked. The AuthorizeUsers class inherits from AuthorizeAttribute. Any ideas?
Just a note as to why we're looking at doing this is because the testers have lower access in production but need higher access in test to test all the functionality.
C#:
[AuthorizeUsers(Roles = "Group A, Administration")] public SomeInformation Post([FromBody]SomeInformation infodata)
{
return _manager.SaveInfo(infodata);
}
Here is our AuthorizeUsers class:
C#:
public class AuthorizeUsers : AuthorizeAttribute {
protected override bool IsAuthorized(System.Web.Http.Controllers.HttpActionContext actionContext)
{
var isAuthorized = base.IsAuthorized(actionContext);
if (!isAuthorized)
return false;
return HttpContext.Current.User.IsInRole(Settings.Default.GroupA)
|| HttpContext.Current.User.IsInRole(Settings.Default.Administration);
}
}
Is there a way to pull from the web.config file and assign it to the Roles property?
We tried the following:
C#:
private string Env = Settings.Default.GroupA + ", " + Settings.Default.Administration
[AuthorizeUsers(Roles = Env)]
Just a note as to why we're looking at doing this is because the testers have lower access in production but need higher access in test to test all the functionality.
Last edited: