DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Query.Security.cs
Go to the documentation of this file.
1 //
2 // Copyright 2010-2015 Deveel
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 //
16 
17 using System;
18 using System.Linq;
19 
20 using Deveel.Data.Routines;
21 using Deveel.Data.Services;
22 using Deveel.Data.Sql;
24 using Deveel.Data.Sql.Query;
25 using Deveel.Data.Sql.Tables;
26 
27 namespace Deveel.Data.Security {
28  public static class Query {
29  private static IUserManager UserManager(this IQuery query) {
30  return query.Context.ResolveService<IUserManager>();
31  }
32 
33  private static IPrivilegeManager PrivilegeManager(this IQuery query) {
34  return query.Context.ResolveService<IPrivilegeManager>();
35  }
36 
37  public static void CreateUserGroup(this IQuery query, string groupName) {
38  if (!query.UserCanManageGroups())
39  throw new InvalidOperationException(String.Format("User '{0}' has not enough privileges to create a group.", query.UserName()));
40 
41  query.Direct().UserManager().CreateUserGroup(groupName);
42  }
43 
44  #region User Management
45 
46  public static User GetUser(this IQuery query, string userName) {
47  if (query.UserName().Equals(userName, StringComparison.OrdinalIgnoreCase))
48  return new User(userName);
49 
50  if (!query.UserCanAccessUsers())
51  throw new MissingPrivilegesException(query.UserName(), new ObjectName(userName), Privileges.Select,
52  String.Format("The user '{0}' has not enough rights to access other users information.", query.UserName()));
53 
54  if (!query.Direct().UserManager().UserExists(userName))
55  return null;
56 
57  return new User(userName);
58  }
59 
60  public static void SetUserStatus(this IQuery queryContext, string username, UserStatus status) {
61  if (!queryContext.UserCanManageUsers())
62  throw new MissingPrivilegesException(queryContext.UserName(), new ObjectName(username), Privileges.Alter,
63  String.Format("User '{0}' cannot change the status of user '{1}'", queryContext.UserName(), username));
64 
65  queryContext.Direct().UserManager().SetUserStatus(username, status);
66  }
67 
68  public static UserStatus GetUserStatus(this IQuery queryContext, string userName) {
69  if (!queryContext.UserName().Equals(userName) &&
70  !queryContext.UserCanAccessUsers())
71  throw new MissingPrivilegesException(queryContext.UserName(), new ObjectName(userName), Privileges.Select,
72  String.Format("The user '{0}' has not enough rights to access other users information.", queryContext.UserName()));
73 
74  return queryContext.Direct().UserManager().GetUserStatus(userName);
75  }
76 
77  public static void SetUserGroups(this IQuery query, string userName, string[] groups) {
78  if (!query.UserCanManageUsers())
79  throw new MissingPrivilegesException(query.UserName(), new ObjectName(userName), Privileges.Alter,
80  String.Format("The user '{0}' has not enough rights to modify other users information.", query.UserName()));
81 
82  // TODO: Check if the user exists?
83 
84  var userGroups = query.Direct().UserManager().GetUserGroups(userName);
85  foreach (var userGroup in userGroups) {
86  query.Direct().UserManager().RemoveUserFromGroup(userName, userGroup);
87  }
88 
89  foreach (var userGroup in groups) {
90  query.Direct().UserManager().AddUserToGroup(userName, userGroup, false);
91  }
92  }
93 
94  public static bool UserExists(this IQuery query, string userName) {
95  return query.Direct().UserManager().UserExists(userName);
96  }
97 
98  public static void CreatePublicUser(this IQuery query) {
99  if (!query.User().IsSystem)
100  throw new InvalidOperationException("The @PUBLIC user can be created only by the SYSTEM");
101 
102  var userName = User.PublicName;
103  var userId = UserIdentification.PlainText;
104  var userInfo = new UserInfo(userName, userId);
105 
106  query.Direct().UserManager().CreateUser(userInfo, "####");
107  }
108 
109  public static User CreateUser(this IQuery query, string userName, string password) {
110  if (String.IsNullOrEmpty(userName))
111  throw new ArgumentNullException("userName");
112  if (String.IsNullOrEmpty(password))
113  throw new ArgumentNullException("password");
114 
115  if (!query.UserCanCreateUsers())
116  throw new MissingPrivilegesException(userName, new ObjectName(userName), Privileges.Create,
117  String.Format("User '{0}' cannot create users.", query.UserName()));
118 
119  if (String.Equals(userName, User.PublicName, StringComparison.OrdinalIgnoreCase))
120  throw new ArgumentException(
121  String.Format("User name '{0}' is reserved and cannot be registered.", User.PublicName), "userName");
122 
123  if (userName.Length <= 1)
124  throw new ArgumentException("User name must be at least one character.");
125  if (password.Length <= 1)
126  throw new ArgumentException("The password must be at least one character.");
127 
128  var c = userName[0];
129  if (c == '#' || c == '@' || c == '$' || c == '&')
130  throw new ArgumentException(
131  String.Format("User name '{0}' is invalid: cannot start with '{1}' character.", userName, c), "userName");
132 
133  var userId = UserIdentification.PlainText;
134  var userInfo = new UserInfo(userName, userId);
135 
136  query.Direct().UserManager().CreateUser(userInfo, password);
137 
138  return new User(userName);
139  }
140 
141  public static void AlterUserPassword(this IQuery queryContext, string username, string password) {
142  if (!queryContext.UserCanAlterUser(username))
143  throw new MissingPrivilegesException(queryContext.UserName(), new ObjectName(username), Privileges.Alter);
144 
145  var userId = UserIdentification.PlainText;
146  var userInfo = new UserInfo(username, userId);
147 
148  queryContext.Direct().UserManager().AlterUser(userInfo, password);
149  }
150 
151  public static bool DeleteUser(this IQuery query, string userName) {
152  if (String.IsNullOrEmpty(userName))
153  throw new ArgumentNullException("userName");
154 
155  if (!query.UserCanDropUser(userName))
156  throw new MissingPrivilegesException(query.UserName(), new ObjectName(userName), Privileges.Drop);
157 
158  return query.Direct().UserManager().DropUser(userName);
159  }
160 
176  public static User Authenticate(this IQuery queryContext, string username, string password) {
177  try {
178  if (String.IsNullOrEmpty(username))
179  throw new ArgumentNullException("username");
180  if (String.IsNullOrEmpty(password))
181  throw new ArgumentNullException("password");
182 
183  var userInfo = queryContext.Direct().UserManager().GetUser(username);
184 
185  if (userInfo == null)
186  return null;
187 
188  var userId = userInfo.Identification;
189 
190  if (userId.Method != "plain")
191  throw new NotImplementedException();
192 
193  if (!queryContext.Direct().UserManager().CheckIdentifier(username, password))
194  return null;
195 
196  // Successfully authenticated...
197  return new User(username);
198  } catch (SecurityException) {
199  throw;
200  } catch (Exception ex) {
201  throw new SecurityException("Could not authenticate user.", ex);
202  }
203  }
204 
205  #endregion
206 
207  #region User Grants Management
208 
209  public static void AddUserToGroup(this IQuery queryContext, string username, string group, bool asAdmin = false) {
210  if (String.IsNullOrEmpty(@group))
211  throw new ArgumentNullException("group");
212  if (String.IsNullOrEmpty(username))
213  throw new ArgumentNullException("username");
214 
215  if (!queryContext.UserCanAddToGroup(group))
216  throw new SecurityException();
217 
218  queryContext.Direct().UserManager().AddUserToGroup(username, group, asAdmin);
219  }
220 
221  public static void GrantToUserOn(this IQuery query, ObjectName objectName, string grantee, Privileges privileges, bool withOption = false) {
222  var obj = query.FindObject(objectName);
223  if (obj == null)
224  throw new ObjectNotFoundException(objectName);
225 
226  query.GrantToUserOn(obj.ObjectType, obj.FullName, grantee, privileges, withOption);
227  }
228 
229  public static void GrantToUserOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges, bool withOption = false) {
230  if (String.Equals(grantee, User.SystemName)) // The @SYSTEM user does not need any other
231  return;
232 
233  if (!query.ObjectExists(objectType, objectName))
234  throw new ObjectNotFoundException(objectName);
235 
236  if (!query.UserHasGrantOption(objectType, objectName, privileges))
237  throw new MissingPrivilegesException(query.UserName(), objectName, privileges);
238 
239  var granter = query.UserName();
240  var grant = new Grant(privileges, objectName, objectType, granter, withOption);
241  query.Direct().PrivilegeManager().GrantToUser(grantee, grant);
242  }
243 
244  public static void GrantToUserOnSchema(this IQuery query, string schemaName, string grantee, Privileges privileges, bool withOption = false) {
245  query.GrantToUserOn(DbObjectType.Schema, new ObjectName(schemaName), grantee, privileges, withOption);
246  }
247 
248  public static void GrantToGroupOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string groupName, Privileges privileges, bool withOption = false) {
249  if (SystemGroups.IsSystemGroup(groupName))
250  throw new InvalidOperationException("Cannot grant to a system group.");
251 
252  if (!query.UserCanManageGroups())
253  throw new MissingPrivilegesException(query.UserName(), new ObjectName(groupName));
254 
255  if (!query.ObjectExists(objectType, objectName))
256  throw new ObjectNotFoundException(objectName);
257 
258  var granter = query.UserName();
259  var grant = new Grant(privileges, objectName, objectType, granter, withOption);
260  query.Direct().PrivilegeManager().GrantToGroup(groupName, grant);
261  }
262 
263  public static void GrantTo(this IQuery query, string groupOrUserName, DbObjectType objectType, ObjectName objectName, Privileges privileges, bool withOption = false) {
264  if (query.Direct().UserManager().UserGroupExists(groupOrUserName)) {
265  if (withOption)
266  throw new SecurityException("User groups cannot be granted with grant option.");
267 
268  query.GrantToGroupOn(objectType, objectName, groupOrUserName, privileges);
269  } else if (query.Direct().UserManager().UserExists(groupOrUserName)) {
270  query.GrantToUserOn(objectType, objectName, groupOrUserName, privileges, withOption);
271  } else {
272  throw new SecurityException(String.Format("User or group '{0}' was not found.", groupOrUserName));
273  }
274  }
275 
276  public static void RevokeAllGrantsOnTable(this IQuery query, ObjectName objectName) {
277  RevokeAllGrantsOn(query, DbObjectType.Table, objectName);
278  }
279 
280  public static void RevokeAllGrantsOnView(this IQuery query, ObjectName objectName) {
281  query.RevokeAllGrantsOn(DbObjectType.View, objectName);
282  }
283 
284  public static void RevokeAllGrantsOn(this IQuery query, DbObjectType objectType, ObjectName objectName) {
285  var grantTable = query.GetMutableTable(SystemSchema.UserGrantsTableName);
286 
287  var objectTypeColumn = grantTable.GetResolvedColumnName(1);
288  var objectNameColumn = grantTable.GetResolvedColumnName(2);
289  // All that match the given object
290  var t1 = grantTable.SimpleSelect(query, objectTypeColumn, SqlExpressionType.Equal,
291  SqlExpression.Constant(DataObject.Integer((int)objectType)));
292  // All that match the given parameter
293  t1 = t1.SimpleSelect(query, objectNameColumn, SqlExpressionType.Equal,
295 
296  // Remove these rows from the table
297  grantTable.Delete(t1);
298  }
299 
300  public static void GrantToUserOnTable(this IQuery query, ObjectName tableName, string grantee, Privileges privileges) {
301  query.GrantToUserOn(DbObjectType.Table, tableName, grantee, privileges);
302  }
303 
304  #endregion
305 
306  #region User Grants Query
307 
308  public static string[] GetGroupsUserBelongsTo(this IQuery queryContext, string username) {
309  return queryContext.Direct().UserManager().GetUserGroups(username);
310  }
311 
312  public static bool UserBelongsToGroup(this IQuery queryContext, string group) {
313  return UserBelongsToGroup(queryContext, queryContext.UserName(), group);
314  }
315 
316  public static bool UserBelongsToGroup(this IQuery query, string username, string groupName) {
317  return query.Direct().UserManager().IsUserInGroup(username, groupName);
318  }
319 
320  public static bool UserCanManageGroups(this IQuery query) {
321  return query.User().IsSystem || query.UserHasSecureAccess();
322  }
323 
324  public static bool UserHasSecureAccess(this IQuery query) {
325  if (query.User().IsSystem)
326  return true;
327 
328  return query.UserBelongsToSecureGroup();
329  }
330 
331  public static bool UserBelongsToSecureGroup(this IQuery query) {
332  return query.UserBelongsToGroup(SystemGroups.SecureGroup);
333  }
334 
335  public static bool UserHasGrantOption(this IQuery query, DbObjectType objectType, ObjectName objectName, Privileges privileges) {
336  var user = query.User();
337  if (user.IsSystem)
338  return true;
339 
340  if (query.UserBelongsToSecureGroup())
341  return true;
342 
343  var grant = query.Direct().PrivilegeManager().GetUserPrivileges(user.Name, objectType, objectName, true);
344  return (grant & privileges) != 0;
345  }
346 
347  public static bool UserHasPrivilege(this IQuery query, DbObjectType objectType, ObjectName objectName, Privileges privileges) {
348  var user = query.User();
349  if (user.IsSystem)
350  return true;
351 
352  if (query.UserBelongsToSecureGroup())
353  return true;
354 
355  var userName = user.Name;
356  var grant = query.Direct().PrivilegeManager().GetUserPrivileges(userName, objectType, objectName, false);
357  return (grant & privileges) != 0;
358  }
359 
360  public static bool UserCanCreateUsers(this IQuery query) {
361  return query.UserHasSecureAccess() ||
362  query.UserBelongsToGroup(SystemGroups.UserManagerGroup);
363  }
364 
365  public static bool UserCanDropUser(this IQuery query, string userToDrop) {
366  return query.UserHasSecureAccess() ||
367  query.UserBelongsToGroup(SystemGroups.UserManagerGroup) ||
368  query.UserName().Equals(userToDrop, StringComparison.OrdinalIgnoreCase);
369  }
370 
371  public static bool UserCanAlterUser(this IQuery query, string userName) {
372  if (query.UserName().Equals(userName))
373  return true;
374 
375  if (userName.Equals(User.PublicName, StringComparison.OrdinalIgnoreCase))
376  return false;
377 
378  return query.UserHasSecureAccess();
379  }
380 
381  public static bool UserCanManageUsers(this IQuery query) {
382  return query.UserHasSecureAccess() || query.UserBelongsToGroup(SystemGroups.UserManagerGroup);
383  }
384 
385  public static bool UserCanAccessUsers(this IQuery query) {
386  return query.UserHasSecureAccess() || query.UserBelongsToGroup(SystemGroups.UserManagerGroup);
387  }
388 
389  public static bool UserHasTablePrivilege(this IQuery query, ObjectName tableName, Privileges privileges) {
390  return query.UserHasPrivilege(DbObjectType.Table, tableName, privileges);
391  }
392 
393  public static bool UserHasSchemaPrivilege(this IQuery query, string schemaName, Privileges privileges) {
394  if (query.UserHasPrivilege(DbObjectType.Schema, new ObjectName(schemaName), privileges))
395  return true;
396 
397  return query.UserHasSecureAccess();
398  }
399 
400  public static bool UserCanCreateSchema(this IQuery query) {
401  return query.UserHasSecureAccess();
402  }
403 
404  public static bool UserCanCreateInSchema(this IQuery query, string schemaName) {
405  return query.UserHasSchemaPrivilege(schemaName, Privileges.Create);
406  }
407 
408  public static bool UserCanCreateTable(this IQuery query, ObjectName tableName) {
409  var schema = tableName.Parent;
410  if (schema == null)
411  return query.UserHasSecureAccess();
412 
413  return query.UserCanCreateInSchema(schema.FullName);
414  }
415 
416  public static bool UserCanAlterInSchema(this IQuery query, string schemaName) {
417  if (query.UserHasSchemaPrivilege(schemaName, Privileges.Alter))
418  return true;
419 
420  return query.UserHasSecureAccess();
421  }
422 
423  public static bool UserCanAlterTable(this IQuery query, ObjectName tableName) {
424  var schema = tableName.Parent;
425  if (schema == null)
426  return false;
427 
428  return query.UserCanAlterInSchema(schema.FullName);
429  }
430 
431  public static bool UserCanSelectFromTable(this IQuery query, ObjectName tableName) {
432  return UserCanSelectFromTable(query, tableName, new string[0]);
433  }
434 
435  public static bool UserCanReferenceTable(this IQuery query, ObjectName tableName) {
436  return query.UserHasTablePrivilege(tableName, Privileges.References);
437  }
438 
439  public static bool UserCanSelectFromPlan(this IQuery query, IQueryPlanNode queryPlan) {
440  var selectedTables = queryPlan.DiscoverTableNames();
441  return selectedTables.All(query.UserCanSelectFromTable);
442  }
443 
444  public static bool UserCanSelectFromTable(this IQuery query, ObjectName tableName, params string[] columnNames) {
445  // TODO: Column-level select will be implemented in the future
446  return query.UserHasTablePrivilege(tableName, Privileges.Select);
447  }
448 
449  public static bool UserCanUpdateTable(this IQuery query, ObjectName tableName, params string[] columnNames) {
450  // TODO: Column-level select will be implemented in the future
451  return query.UserHasTablePrivilege(tableName, Privileges.Update);
452  }
453 
454  public static bool UserCanInsertIntoTable(this IQuery query, ObjectName tableName, params string[] columnNames) {
455  // TODO: Column-level select will be implemented in the future
456  return query.UserHasTablePrivilege(tableName, Privileges.Insert);
457  }
458 
459  public static bool UserCanExecute(this IQuery query, RoutineType routineType, Invoke invoke) {
460  if (routineType == RoutineType.Function &&
461  query.IsSystemFunction(invoke)) {
462  return true;
463  }
464 
465  if (query.UserHasSecureAccess())
466  return true;
467 
468  return query.UserHasPrivilege(DbObjectType.Routine, invoke.RoutineName, Privileges.Execute);
469  }
470 
471  public static bool UserCanExecuteFunction(this IQuery query, Invoke invoke) {
472  return query.UserCanExecute(RoutineType.Function, invoke);
473  }
474 
475  public static bool UserCanExecuteProcedure(this IQuery query, Invoke invoke) {
476  return query.UserCanExecute(RoutineType.Procedure, invoke);
477  }
478 
479  public static bool UserCanCreateObject(this IQuery query, DbObjectType objectType, ObjectName objectName) {
480  return query.UserHasPrivilege(objectType, objectName, Privileges.Create);
481  }
482 
483  public static bool UserCanDropObject(this IQuery query, DbObjectType objectType, ObjectName objectName) {
484  return query.UserHasPrivilege(objectType, objectName, Privileges.Drop);
485  }
486 
487  public static bool UserCanAlterObject(this IQuery query, DbObjectType objectType, ObjectName objectName) {
488  return query.UserHasPrivilege(objectType, objectName, Privileges.Alter);
489  }
490 
491  public static bool UserCanAccessObject(this IQuery query, DbObjectType objectType, ObjectName objectName) {
492  return query.UserHasPrivilege(objectType, objectName, Privileges.Select);
493  }
494 
495  public static bool UserCanDeleteFromTable(this IQuery query, ObjectName tableName) {
496  return query.UserHasTablePrivilege(tableName, Privileges.Delete);
497  }
498 
499  public static bool UserCanAddToGroup(this IQuery query, string groupName) {
500  if (query.User().IsSystem)
501  return true;
502 
503  if (query.UserBelongsToSecureGroup() ||
504  query.UserBelongsToGroup(SystemGroups.UserManagerGroup))
505  return true;
506 
507  return query.Direct().UserManager().IsUserGroupAdmin(query.UserName(), groupName);
508  }
509 
510  #endregion
511 
512  }
513 }
static bool UserCanAccessUsers(this IQuery query)
static void GrantToUserOnTable(this IQuery query, ObjectName tableName, string grantee, Privileges privileges)
static IUserManager UserManager(this IQuery query)
static User CreateUser(this IQuery query, string userName, string password)
static DataObject Integer(int value)
Definition: DataObject.cs:576
static bool IsSystemGroup(string groupName)
Definition: SystemGroups.cs:64
static bool UserCanSelectFromPlan(this IQuery query, IQueryPlanNode queryPlan)
static User Authenticate(this IQuery queryContext, string username, string password)
Authenticates the specified user using the provided credentials.
static void AddUserToGroup(this IQuery queryContext, string username, string group, bool asAdmin=false)
static bool UserHasPrivilege(this IQuery query, DbObjectType objectType, ObjectName objectName, Privileges privileges)
static bool UserCanAccessObject(this IQuery query, DbObjectType objectType, ObjectName objectName)
static bool UserCanDropObject(this IQuery query, DbObjectType objectType, ObjectName objectName)
static bool UserCanManageGroups(this IQuery query)
static void AlterUserPassword(this IQuery queryContext, string username, string password)
const string PublicName
The name of the PUBLIC special user.
Definition: User.cs:47
static bool UserCanSelectFromTable(this IQuery query, ObjectName tableName)
static bool UserCanCreateTable(this IQuery query, ObjectName tableName)
static IPrivilegeManager PrivilegeManager(this IQuery query)
static string[] GetGroupsUserBelongsTo(this IQuery queryContext, string username)
static bool UserCanExecute(this IQuery query, RoutineType routineType, Invoke invoke)
static void RevokeAllGrantsOn(this IQuery query, DbObjectType objectType, ObjectName objectName)
static void GrantToGroupOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string groupName, Privileges privileges, bool withOption=false)
static void CreateUserGroup(this IQuery query, string groupName)
Describes the name of an object within a database.
Definition: ObjectName.cs:44
static void GrantToUserOn(this IQuery query, ObjectName objectName, string grantee, Privileges privileges, bool withOption=false)
static void GrantToUserOnSchema(this IQuery query, string schemaName, string grantee, Privileges privileges, bool withOption=false)
static bool UserCanCreateSchema(this IQuery query)
static void RevokeAllGrantsOnTable(this IQuery query, ObjectName objectName)
static DataObject String(string s)
Definition: DataObject.cs:592
SqlExpressionType
All the possible type of SqlExpression supported
static bool UserCanManageUsers(this IQuery query)
A node element of a query plan tree. /summary>
static bool UserCanCreateInSchema(this IQuery query, string schemaName)
RoutineType
The type of routine program.
Definition: RoutineType.cs:23
static bool UserHasGrantOption(this IQuery query, DbObjectType objectType, ObjectName objectName, Privileges privileges)
static bool UserHasSecureAccess(this IQuery query)
static void SetUserGroups(this IQuery query, string userName, string[] groups)
static bool UserCanInsertIntoTable(this IQuery query, ObjectName tableName, params string[] columnNames)
const string UserManagerGroup
The name of the user manager group.
Definition: SystemGroups.cs:55
static bool UserCanAlterTable(this IQuery query, ObjectName tableName)
static bool UserCanDeleteFromTable(this IQuery query, ObjectName tableName)
static bool UserCanCreateObject(this IQuery query, DbObjectType objectType, ObjectName objectName)
static bool UserCanAddToGroup(this IQuery query, string groupName)
static bool UserCanCreateUsers(this IQuery query)
static void GrantToUserOn(this IQuery query, DbObjectType objectType, ObjectName objectName, string grantee, Privileges privileges, bool withOption=false)
static void GrantTo(this IQuery query, string groupOrUserName, DbObjectType objectType, ObjectName objectName, Privileges privileges, bool withOption=false)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
Definition: DataObject.cs:35
static bool UserBelongsToSecureGroup(this IQuery query)
The information about the invocation of a routine, including the full name and arguments (as SqlExpre...
Definition: Invoke.cs:30
static bool UserCanExecuteFunction(this IQuery query, Invoke invoke)
Provides utilities and properties for handling the SYSTEN schema of a database.
Definition: SystemSchema.cs:37
static bool UserHasTablePrivilege(this IQuery query, ObjectName tableName, Privileges privileges)
static User GetUser(this IQuery query, string userName)
string FullName
Gets the full reference name formatted.
Definition: ObjectName.cs:114
static bool UserExists(this IQuery query, string userName)
static bool UserCanDropUser(this IQuery query, string userToDrop)
static bool UserCanAlterInSchema(this IQuery query, string schemaName)
ObjectName Parent
Gets the parent reference of the current one, if any or null if none.
Definition: ObjectName.cs:99
static readonly ObjectName UserGrantsTableName
ObjectName RoutineName
Gets the fully qualified name of the routine to invoke.
Definition: Invoke.cs:58
static void RevokeAllGrantsOnView(this IQuery query, ObjectName objectName)
static bool UserCanUpdateTable(this IQuery query, ObjectName tableName, params string[] columnNames)
static bool UserBelongsToGroup(this IQuery queryContext, string group)
const string SecureGroup
THe name of the secure access group.
Definition: SystemGroups.cs:46
static bool UserCanSelectFromTable(this IQuery query, ObjectName tableName, params string[] columnNames)
Defines the base class for instances that represent SQL expression tree nodes.
static SqlConstantExpression Constant(object value)
static bool UserBelongsToGroup(this IQuery query, string username, string groupName)
DbObjectType
The kind of objects that can be handled by a database system and its managers
Definition: DbObjectType.cs:27
static bool DeleteUser(this IQuery query, string userName)
Provides the information for a user in a database system
Definition: User.cs:27
static bool UserCanExecuteProcedure(this IQuery query, Invoke invoke)
static bool UserCanReferenceTable(this IQuery query, ObjectName tableName)
static bool UserCanAlterUser(this IQuery query, string userName)
static bool UserCanAlterObject(this IQuery query, DbObjectType objectType, ObjectName objectName)
static void SetUserStatus(this IQuery queryContext, string username, UserStatus status)
static bool UserHasSchemaPrivilege(this IQuery query, string schemaName, Privileges privileges)
new IQueryContext Context
Definition: IQuery.cs:21
static UserStatus GetUserStatus(this IQuery queryContext, string userName)
The entity that holds the access control granted to an user or a group to a specific object in a data...
Definition: Grant.cs:26
const string SystemName
The name of the SYSTEM special user.
Definition: User.cs:52
static void CreatePublicUser(this IQuery query)