private SysUserModel MakeSysUser(AuthUsers rawuser, AuthRoles roles, List <AuthUserClaims> claimslist) { return(new SysUserModel { SubjectId = rawuser.Uid, Username = rawuser.Account, Password = rawuser.Password, Claims = { new Claim(JwtClaimTypes.Email, rawuser.Email), new Claim(JwtClaimTypes.GivenName, rawuser.DisplayName), new Claim(JwtClaimTypes.NickName, rawuser.Phone), new Claim(JwtClaimTypes.Locale, roles.Rolename), new Claim(JwtClaimTypes.ZoneInfo, roles.Roledescript), new Claim(JwtClaimTypes.Gender, roles.Id.ToString()), new Claim("mytestclaim", "mytestdata"), } }); }
public bool IsInRole(User user, Scope scope, AuthRoles role) { return (GetRoles(user, scope) & role) == role; }
public AuthenticationValidationFilter(AuthRoles role) { this._role = role; }
/// <summary> /// Gets whether any of the roles are authorized to perform the action within /// the given context based on the role matrix. The role matrix /// is first checked at the collection level and then it bubbles up /// to the workspace level and onto the service level and then /// finally the default built-in role matrix. /// </summary> /// <param name="user">The user.</param> /// <param name="id">The entry Id or the collection Id.</param> /// <param name="action">The action.</param> /// <returns></returns> public bool IsAuthorized(AuthRoles roles, Scope scope, AuthAction action) { RoleMatrix rm = null; RoleAction ra = null; AppService appService = AppServiceRepository.GetService(); if (!scope.IsEntireSite) { var w = appService.GetWorkspace(scope.Workspace); if (scope.IsCollection) { //try collection level first rm = w.GetCollection(scope.Collection).RoleMatrix; if (rm != null) ra = rm.RoleActions.Where(a => a.Name == action.ToString()).FirstOrDefault(); } //try workspace level next if (ra == null) { rm = w.RoleMatrix; if (rm != null) ra = rm.RoleActions.Where(a => a.Name == action.ToString()).FirstOrDefault(); } } //service level if (ra == null) { rm = appService.RoleMatrix; if (rm != null) ra = rm.RoleActions.Where(a => a.Name == action.ToString()).FirstOrDefault(); } //use default role matrix if (ra == null) { rm = RoleMatrix.Default; if (rm != null) ra = rm.RoleActions.Where(a => a.Name == action.ToString()).FirstOrDefault(); } if (ra == null) { LogService.Warn("Action not found in any role matrix."); return false; } return ((ra.AuthRoles & roles) > AuthRoles.None); }