The entity that holds the access control granted to an user or a group to a specific object in a database.
Exemplo n.º 1
0
        public void RevokeFromUser(string userName, Grant grant)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }

            try {
                RevokeAllGrantsFromUser(grant.ObjectType, grant.ObjectName, grant.GranterName, userName, grant.WithOption);
            } finally {
                ClearUserGrantsCache(userName, grant.ObjectType, grant.ObjectName, grant.WithOption, false);
            }
        }
        public void Grant(Grant grant)
        {
            if (grant == null)
            {
                throw new ArgumentNullException("grant");
            }

            var objectType = grant.ObjectType;
            var objectName = grant.ObjectName;
            var privileges = grant.Privileges;

            Privileges oldPrivs = GetPrivileges(grant.Grantee, objectType, objectName, grant.WithOption);

            privileges |= oldPrivs;

            if (!oldPrivs.Equals(privileges))
            {
                UpdateUserGrants(objectType, objectName, grant.GranterName, grant.Grantee, privileges, grant.WithOption);
            }
        }
Exemplo n.º 3
0
        public static void GrantToGroupOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string groupName, Privileges privileges, bool withOption = false)
        {
            if (SystemGroups.IsSystemGroup(groupName))
            {
                throw new InvalidOperationException("Cannot grant to a system group.");
            }

            if (!query.UserCanManageGroups())
            {
                throw new MissingPrivilegesException(query.UserName(), new ObjectName(groupName));
            }

            if (!query.ObjectExists(objectType, objectName))
            {
                throw new ObjectNotFoundException(objectName);
            }

            var granter = query.UserName();
            var grant   = new Grant(privileges, objectName, objectType, granter, withOption);

            query.Direct().PrivilegeManager().GrantToGroup(groupName, grant);
        }
Exemplo n.º 4
0
        public static void GrantToUserOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges, bool withOption = false)
        {
            if (String.Equals(grantee, User.SystemName))                   // The @SYSTEM user does not need any other
            {
                return;
            }

            if (!query.ObjectExists(objectType, objectName))
            {
                throw new ObjectNotFoundException(objectName);
            }

            if (!query.UserHasGrantOption(objectType, objectName, privileges))
            {
                throw new MissingPrivilegesException(query.UserName(), objectName, privileges);
            }

            var granter = query.UserName();
            var grant   = new Grant(privileges, objectName, objectType, granter, withOption);

            query.Direct().PrivilegeManager().GrantToUser(grantee, grant);
        }
Exemplo n.º 5
0
        public void GrantToUser(string userName, Grant grant)
        {
            if (String.IsNullOrEmpty(userName))
            {
                throw new ArgumentNullException("userName");
            }
            if (grant == null)
            {
                throw new ArgumentNullException("grant");
            }

            var objectType = grant.ObjectType;
            var objectName = grant.ObjectName;
            var privileges = grant.Privileges;

            Privileges oldPrivs = GetUserPrivileges(userName, objectType, objectName, grant.WithOption);

            privileges |= oldPrivs;

            if (!oldPrivs.Equals(privileges))
            {
                UpdateUserGrants(objectType, objectName, grant.GranterName, userName, privileges, grant.WithOption);
            }
        }
        public static void GrantToUserOn(this IQueryContext context, DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges, bool withOption = false)
        {
            if (String.Equals(grantee, User.SystemName))       // The @SYSTEM user does not need any other
                return;

            if (!context.ObjectExists(objectType, objectName))
                throw new ObjectNotFoundException(objectName);

            if (!context.UserHasGrantOption(objectType, objectName, privileges))
                throw new MissingPrivilegesException(context.UserName(), objectName, privileges);

            var granter = context.UserName();
            var grant = new Grant(privileges, objectName, objectType, granter, withOption);
            context.ForSystemUser().PrivilegeManager().GrantToUser(grantee, grant);
        }
        public static void GrantToGroupOn(this IQueryContext context, DbObjectType objectType, ObjectName objectName, string groupName, Privileges privileges, bool withOption = false)
        {
            if (SystemGroups.IsSystemGroup(groupName))
                throw new InvalidOperationException("Cannot grant to a system group.");

            if (!context.UserCanManageGroups())
                throw new MissingPrivilegesException(context.UserName(), new ObjectName(groupName));

            if (!context.ObjectExists(objectType, objectName))
                throw new ObjectNotFoundException(objectName);

            var granter = context.UserName();
            var grant = new Grant(privileges, objectName, objectType, granter, withOption);
            context.ForSystemUser().PrivilegeManager().GrantToGroup(groupName, grant);
        }
 public void Revoke(Grant grant)
 {
     RevokeAllGrantsFrom(grant.ObjectType, grant.ObjectName, grant.GranterName, grant.Grantee, grant.WithOption);
 }
Exemplo n.º 9
0
 public void RevokeFromGroup(string groupName, Grant grant)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 10
0
 public void GrantToGroup(string groupName, Grant grant)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 11
0
 public void Revoke(Grant grant)
 {
     RevokeAllGrantsFrom(grant.ObjectType, grant.ObjectName, grant.GranterName, grant.Grantee, grant.WithOption);
 }
Exemplo n.º 12
0
        public void Grant(Grant grant)
        {
            if (grant == null)
                throw new ArgumentNullException("grant");

            var objectType = grant.ObjectType;
            var objectName = grant.ObjectName;
            var privileges = grant.Privileges;

            Privileges oldPrivs = GetPrivileges(grant.Grantee, objectType, objectName, grant.WithOption);
            privileges |= oldPrivs;

            if (!oldPrivs.Equals(privileges))
                UpdateUserGrants(objectType, objectName, grant.GranterName, grant.Grantee, privileges, grant.WithOption);
        }