Windows credentials will be checked whenever a user attempts to execute an action that is decorated with the [Authorize]
filter. You could simply derive a new filter from that one:
public class ImportAuthorizeAttribute : AuthorizeAttribute
{
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
if (base.AuthorizeCore(httpContext))
{
//If the base authorize returns true, then authorization has successfully
//occurred.
var identity = httpContext.User.Identity;
//You'll need to figure this part out
ImportIdentityIfNotPresent(identity);
}
}
}
Now, you can restrict access by applying it at the action level:
[ImportAuthorizeAttribute]
public ActionResult Create()
Or at the controller level:
[ImportAuthorizeAttribute]
public class AdminController : Controller
Or even globally by editing FilterConfig.cs
in `/App_Start':
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new Code.Filters.MVC.ImportAuthorizeAttribute());
}