示例#1
0
        public UserOdataPermissionService(IPlatformUser user, IUserPlatformRoleAccessor roles, IMemoryCache cache)
        {
            var key = Core.CacheKeyBuilder.UserOdataPermission(user.Id);

            OdataQueryPermission = cache.GetOrCreate(key, entry =>
            {
                entry.AbsoluteExpirationRelativeToNow = new System.TimeSpan(0, 10, 0);
                return(new CombinedOdataQueryPermission(roles.Roles.SelectMany(x => x.QueryPermissions).ToArray()));
            });
        }
示例#2
0
 public RoleTokenHandler(IUserPlatformRoleAccessor userRoles)
 {
     if (userRoles.Roles != null)
     {
         var map = new Dictionary <string, HashSet <string> >();
         foreach (var pp in userRoles.Roles.Select(p => new { p.Code, p.Roles }))
         {
             map.AddIfNotExists(pp.Code, () => new HashSet <string>());
             map[pp.Code] = new HashSet <string>(map[pp.Code].Concat(pp.Roles).Distinct());
         }
         platformPermissionToRoleMap = map;
     }
 }