diff --git a/Falcon.SugarApi/JWT/ApiAuthorizationAttribute.cs b/Falcon.SugarApi/JWT/ApiAuthorizationAttribute.cs
index 2f0639e..9a908ea 100644
--- a/Falcon.SugarApi/JWT/ApiAuthorizationAttribute.cs
+++ b/Falcon.SugarApi/JWT/ApiAuthorizationAttribute.cs
@@ -18,7 +18,21 @@ namespace Falcon.SugarApi.JWT
///
/// 用户需要具有的角色
///
- public List Roles { get; set; } = new List();
+ public string[] Roles { get; set; }
+
+ ///
+ /// 只需要登录即可通过验证
+ ///
+ public ApiAuthorizationAttribute() {
+ this.Roles = new string[] { };
+ }
+ ///
+ /// 需要登录并且具有一定的角色
+ ///
+ /// 角色组
+ public ApiAuthorizationAttribute(params string[] roles) {
+ this.Roles = roles;
+ }
///
public void OnAuthorization(AuthorizationFilterContext context) {
@@ -41,7 +55,7 @@ namespace Falcon.SugarApi.JWT
Unauthorized(context);
return;
}
- if (this.Roles != null && this.Roles.Count > 0 && !userLogin.UserInRoles(user, this.Roles)) {
+ if (this.Roles != null && this.Roles.Length > 0 && !userLogin.UserInRoles(user, this.Roles)) {
Unauthorized(context);
return;
}
diff --git a/Falcon.SugarApi/JWT/IUserLogin.cs b/Falcon.SugarApi/JWT/IUserLogin.cs
index c335415..a8118db 100644
--- a/Falcon.SugarApi/JWT/IUserLogin.cs
+++ b/Falcon.SugarApi/JWT/IUserLogin.cs
@@ -34,6 +34,6 @@ namespace Falcon.SugarApi.JWT
/// 用户信息
/// 需要具有的角色组
/// True具有,False不具有
- bool UserInRoles(LoginUserInfo userInfo, List roles);
+ bool UserInRoles(LoginUserInfo userInfo, params string[] roles);
}
}