Beispiel #1
0
        private void ClearUserGrantsCache(string userName, DbObjectType objectType, ObjectName objectName, bool withOption, bool withPublic)
        {
            if (grantsCache == null)
            {
                return;
            }

            var key = new GrantCacheKey(userName, objectType, objectName.FullName, withOption, withPublic);

            grantsCache.Remove(key);
        }
Beispiel #2
0
 public void Revoke(DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges,
                    bool grantOption = false)
 {
     try {
         var revoker = Session.User.Name;
         var grant   = new Grant(privileges, objectName, objectType, grantee, revoker, grantOption);
         SystemSession.Access().PrivilegeManager.Revoke(grant);
     } finally {
         var key = new GrantCacheKey(grantee, objectType, objectName.FullName, grantOption, false);
         PrivilegesCache.Remove(key);
     }
 }
Beispiel #3
0
        private void SetPrivilegesInCache(string userName, DbObjectType objectType, ObjectName objectName, bool withOption, bool withPublic,
                                          Privileges privileges)
        {
            var key = new GrantCacheKey(userName, objectType, objectName.FullName, withOption, withPublic);

            if (grantsCache == null)
            {
                grantsCache = new Dictionary <GrantCacheKey, Privileges>();
            }

            grantsCache[key] = privileges;
        }
Beispiel #4
0
        private bool TryGetPrivilegesFromCache(string userName, DbObjectType objectType, ObjectName objectName, bool withOption, bool withPublic,
                                               out Privileges privileges)
        {
            if (grantsCache == null)
            {
                privileges = Privileges.None;
                return(false);
            }

            var key = new GrantCacheKey(userName, objectType, objectName.FullName, withOption, withPublic);

            return(grantsCache.TryGetValue(key, out privileges));
        }
Beispiel #5
0
        private Privileges GetPrivileges(string grantee, DbObjectType objectType, ObjectName objectName, bool withOption)
        {
            object     privsObj;
            Privileges privs;

            var key = new GrantCacheKey(grantee, objectType, objectName.FullName, true, true);

            if (PrivilegesCache.TryGet(key, out privsObj))
            {
                privs = (Privileges)privsObj;
            }
            else
            {
                var grants = PrivilegeManager.GetGrants(grantee, true);
                foreach (var g in grants)
                {
                    PrivilegesCache.Set(new GrantCacheKey(g.Grantee, g.ObjectType, g.ObjectName.FullName, g.WithOption, true), g.Privileges);
                }

                if (withOption)
                {
                    grants = grants.Where(x => x.WithOption &&
                                          x.ObjectType == objectType &&
                                          x.ObjectName.Equals(objectName))
                             .ToArray();
                }

                privs = Privileges.None;
                foreach (var grant in grants)
                {
                    privs |= grant.Privileges;
                }
            }

            return(privs);
        }