protected override async Task ExecuteStatementAsync(StatementContext context) { var roleManager = context.GetRoleManager(); var userManager = context.GetUserManager(); if (!await roleManager.RoleExistsAsync(RoleName)) { throw new SqlStatementException($"The role '{RoleName}' does not exist."); } if (!await userManager.UserExistsAsync(UserName)) { throw new SqlStatementException($"The user '{UserName}' does not exist"); } if (await roleManager.IsUserInRoleAsync(UserName, RoleName)) { throw new SqlStatementException($"User '{UserName}' is already in role '{RoleName}'"); } if (!await roleManager.AddUserToRoleAsync(UserName, RoleName)) { throw new SqlStatementException($"It was not possible to assign the role '{RoleName}' to " + $"user '{UserName}' because of a system error"); } context.RaiseEvent(new RoleGrantedEvent(this, UserName, RoleName)); }
protected override async Task ExecuteStatementAsync(StatementContext context) { var roleManager = context.GetRoleManager(); var userManager = context.GetUserManager(); if (!await roleManager.RoleExistsAsync(RoleName)) { throw new SqlStatementException($"The role '{RoleName}' does not exist."); } if (!await userManager.UserExistsAsync(UserName)) { throw new SqlStatementException($"The user '{UserName}' does not exist"); } if (!await roleManager.IsUserInRoleAsync(UserName, RoleName)) { throw new SqlStatementException($"The user '{UserName}' is not in the role '{RoleName}'"); } if (!await roleManager.RemoveUserFromRoleAsync(UserName, RoleName)) { throw new SqlStatementException($"It was not possible to revoke the role '{RoleName}' from user '{UserName}'"); } context.RaiseEvent <RoleRevokedEvent>(UserName, RoleName); }
protected override async Task ExecuteStatementAsync(StatementContext context) { var userManager = context.GetUserManager(); if (!await userManager.UserExistsAsync(UserName)) { throw new SqlStatementException($"User {UserName} does not exist"); } try { if (!await Action.AlterUserAsync(UserName, context)) { throw new SqlStatementException($"The alter of the user {UserName} failed"); } } catch (SqlStatementException) { throw; } catch (Exception ex) { throw new SqlStatementException($"It was not possible to alter user {UserName} because of an error", ex); } }
protected override async Task ExecuteStatementAsync(StatementContext context) { if (!User.IsValidName(UserName)) { throw new SqlStatementException($"The specified name '{UserName}' is invalid for a user"); } var userManager = context.GetUserManager(); if (await userManager.UserExistsAsync(UserName)) { throw new SqlStatementException($"A user named '{UserName}' already exists."); } if (!await userManager.CreateUserAsync(UserName, IdentificationInfo)) { throw new SqlStatementException($"It was not possible to create the user '{UserName}' because of a system error."); } context.RaiseEvent(new UserCreatedEvent(this, UserName)); }
protected override async Task ExecuteStatementAsync(StatementContext context) { var userManager = context.GetUserManager(); var roleManager = context.GetRoleManager(); if (!await userManager.UserExistsAsync(UserName)) { throw new SqlStatementException($"A user named '{UserName}' does not exist."); } if (!await RevokeAllGrantedPrivileges(context, userManager, roleManager)) { throw new SqlStatementException($"It was not possible to revoke the privileges granted by '{UserName}'."); } if (!await userManager.DropUserAsync(UserName)) { throw new SqlStatementException($"It was not possible to delete the user '{UserName}' because of a system error"); } context.RaiseEvent(new UserDroppedEvent(this, UserName)); }
protected override async Task ExecuteStatementAsync(StatementContext context) { if (!await context.ObjectExistsAsync(ObjectName)) { throw new SqlStatementException($"The object '{ObjectName}' is not defined in this scope"); } var userManager = context.GetUserManager(); var roleManager = context.GetRoleManager(); var grantManager = context.GetGrantManager(); if (await userManager.UserExistsAsync(Grantee)) { if (!await grantManager.GrantToUserAsync(context.User().Name, Grantee, ObjectName, Privileges, WithGrantOption)) { throw new SqlStatementException("It was not possible to grant to user because of a system error"); } } else if (await roleManager.RoleExistsAsync(Grantee)) { if (WithGrantOption) { throw new SqlStatementException("Cannot set a grant option to a role"); } if (!await grantManager.GrantToRoleAsync(Grantee, ObjectName, Privileges)) { throw new SqlStatementException("It was not possible to grant to role because of a system error"); } } else { throw new SqlStatementException($"The grantee '{Grantee}' was not defined"); } context.RaiseEvent <ObjectPrivilegesGrantedEvent>(context.User().Name, Grantee, ObjectName, Privileges, WithGrantOption); }
async Task <bool> IAlterUserAction.AlterUserAsync(string userName, StatementContext context) { var securityManager = context.GetUserManager(); return(await securityManager.SetUserStatusAsync(userName, NewStatus)); }
async Task <bool> IAlterUserAction.AlterUserAsync(string userName, StatementContext context) { var securityManager = context.GetUserManager(); return(await securityManager.SetIdentificationAsync(userName, new PasswordIdentificationInfo(NewPassword))); }