を通過します。
public class ConfigAuthorizationAttribute: AuthorizeAttribute
{
private readonly IActionRoleConfigService configService;
private readonly IUserRoleService roleService;
private string actionName;
public ConfigAuthorizationAttribute()
{
configService = new ActionRoleConfigService();
roleService = new UserRoleService();
}
protected override void OnAuthorization(AuthorizationContext filterContext)
{
actionName = filterContext.ActionDescription.ActionName;
base.OnAuthorization(filterContext);
}
protected override bool AuthorizeCore(HttpContextBase httpContext)
{
var availableRoles = configService.GetActionRoles(actionName); // return list of strings
var userName = httpContext.User.Identity.Name;
var userRoles = roleService.GetUserRoles(userName); // return list of strings
return availableRoles.Any(x => userRoles.Contains(x));
}
}
私はあなたに役立つことを願っています。
明らかに、私の場合、グループはロールとロールが機能になります。したがって、私の用語を使用して、各ロールは、ロール(1) - 関数(*)のような多対多の関係を持つことになります。私の計画は、あなたの 'CreateUser'属性で行ったようにアクション名を使用することです。この場合、ユーザーを作成する機能を持つロールは許可されます。 –
@zebulaそれは正しいです。 – Eranga