이것은 사용자 지정 데이터베이스에서 사용 권한을 확인하는 권한 부여입니다. 예를 들어 예를 들어 당신이 방법을 가지고, 당신은 권한 계정, 클라이언트, 구성 3 bools을 가지고 있고 당신은 당신도이 허락 한 액션을 추가 할 수 있습니다 actionresult
에 행 다음에 장소보다 그들에 따라 사용자를 제한 할 당신이 데이터베이스에서 bools을 확인 라인
[PermissionBasedAuthorize("Client, Account")]
이 아래 방법으로 다음을 추가 할 수있는 것보다 계정 및 클라이언트 권한을 액세스 할 수있다.
public class PermissionBasedAuthorize : AuthorizeAttribute
{
private List<string> screen { get; set; }
public PermissionBasedAuthorize(string ScreenNames)
{
if (!string.IsNullOrEmpty(ScreenNames))
screen = ScreenNames.Split(',').ToList();
}
public override void OnAuthorization(HttpActionContext actionContext)
{
base.OnAuthorization(actionContext);
var UserId = HttpContext.Current.User.Identity.GetUserId();
ApplicationContext db = new ApplicationContext();
var Permissions = db.Permissions.Find(UserId);
if (screen == null || screen.Count() == 0)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
}
bool IsAllowed = false;
foreach (var item in screen)
foreach (var property in Permissions.GetType().GetProperties())
{
if (property.Name.ToLower().Equals(item.ToLower()))
{
bool Value = (bool)property.GetValue(Permissions, null);
if (Value)
{
IsAllowed = true;
}
break;
}
}
if (!IsAllowed)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Unauthorized);
}
}
}
클레임이있는 토큰 (예 : oAuth)을 사용하면 토큰에 "Roles"라는 소유권이 있습니다. 사이트가이 토큰을 받으면 Principal 개체를 만들고 역할 클레임의 역할을 기반으로 역할을 설정합니다. 그렇다면 표준'AuthorizeAttribute' 또는 사용자 정의'AuthLogAttribute'를 계속 사용할 수 있습니다. –
이 분야에 대한 지식이 부족합니다. 세부 사항 및 지침에서 논의하는 기사로 나를 리디렉션 할 수 있습니까? 감사 –