public async Task <IHttpActionResult> Register([FromBody] RbacRegisterUser user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (user.RbacId == 0) { return(BadRequest("Rbac id cannot be zero!")); } Rbac rbac = new Rbac(user.RbacId, ""); if (rbac == null) { return(BadRequest(string.Format("Rbac instance with rbac id '{0}' not found!", user.RbacId))); } RbacRole role = new RbacRole(user.RoleId); if (role == null) { return(BadRequest(string.Format("Role id '{0}' not found!", user.RoleId))); } RbacUser newUser = rbac.CreateUser(user.UserName, user.FullName, user.Email, user.Password, role); if ((newUser != null) && (newUser.UserId > 0)) { return(Ok()); } return(BadRequest("Cannot create user!")); }
public async Task <IHttpActionResult> AddNew([FromBody] RbacRegisterUser user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RbacUser dbUser = new RbacUser(user.UserName); if (dbUser != null) { return(BadRequest(string.Format("User '{0}' already exists!", user.UserName))); } RbacRole role = new RbacRole(user.RoleId); if (role == null) { return(BadRequest(string.Format("Role id '{0}' not found!", user.RoleId))); } RbacUser newUser = Rbac.CreateUser(user.UserName, user.FullName, user.Email, user.Password, role); if ((newUser != null) && (newUser.UserId > 0)) { return(Ok()); } return(BadRequest("Cannot create user!")); }
public void Setup() { Rbac rbac = new Rbac(); rbac = rbac.CreateNew("books", "books description", @"Data Source=LPT-03084856325\SQLEXPRESS;Initial Catalog=books;Integrated Security=True", File.ReadAllText(Path.Combine(_rootDir, "Books", "entitlement.xml"))); InsertRoles(rbac); GenericParserAdapter parser = new GenericParserAdapter(Path.Combine(_rootDir, "Books", "BooksUsers.csv")); parser.FirstRowHasHeader = true; DataTable table = parser.GetDataTable(); if (table.Rows.Count > 0) { foreach (DataRow dataRow in table.Rows) { RbacRole role = roles.Where(r => r.Name == dataRow["Role"].ToString()).SingleOrDefault(); if (role == null) { throw new Exception(dataRow["Role"].ToString() + " is not defined!"); } RbacUser user = Rbac.CreateUser(dataRow[0].ToString(), dataRow[1].ToString(), dataRow[2].ToString(), "password", role); if (role.Name == "role_city_mgr") { user.AddParameter("{CityNames}", "('New York','Charlotte')"); } else if (role.Name == "role_state_mgr") { user.AddParameter("{ShortNames}", "('NY','NC')"); } else if (role.Name == "role_country_mgr") { user.AddParameter("{CountryCodes}", "('IN','US')"); } } } }
public void Setup(Options options) { if (string.IsNullOrEmpty(options.ConnectionString)) { WriteErrorLine("Connection string is required. Please use -x <connection string>"); return; } Rbac rbac = new Rbac(); rbac = rbac.CreateNew("books", "books description", options.ConnectionString, File.ReadAllText(Path.Combine(_rootDir, "Books", "entitlement.xml"))); Console.Write("."); InsertRoles(rbac); GenericParserAdapter parser = new GenericParserAdapter(Path.Combine(_rootDir, "Books", "BooksUsers.csv")); parser.FirstRowHasHeader = true; DataTable table = parser.GetDataTable(); if (table.Rows.Count > 0) { foreach (DataRow dataRow in table.Rows) { RbacRole role = roles.Where(r => r.Name == dataRow["Role"].ToString()).SingleOrDefault(); if (role == null) { throw new Exception(dataRow["Role"].ToString() + " is not defined!"); } RbacUser user = Rbac.CreateUser(dataRow[0].ToString(), dataRow[1].ToString(), dataRow[2].ToString(), "password", role); if (role.Name == "role_city_mgr") { user.AddParameter("{CityNames}", "('New York','Charlotte')"); } else if (role.Name == "role_state_mgr") { user.AddParameter("{ShortNames}", "('NY','NC')"); } else if (role.Name == "role_country_mgr") { user.AddParameter("{CountryCodes}", "('IN','US')"); } if (role.Name == "role_guest_user") { user.AddParameter("{CityNames}", "('New York')"); } Console.Write("."); } } Console.WriteLine(); var rbacs = Rbac.GetRbacs(); if (rbacs != null) { WriteColor(ConsoleColor.Green, rbacs.Count + " rbac instance(s) created." + Environment.NewLine); } else { WriteErrorLine("rbac creation failed!"); } var vroles = Rbac.GetRoles(); if (vroles != null) { WriteColor(ConsoleColor.Green, vroles.Count + " role(s) created." + Environment.NewLine); } else { WriteErrorLine("role(s) creation failed!"); } var users = Rbac.GetUsers(); if (users != null) { WriteColor(ConsoleColor.Green, users.Count + " user(s) created." + Environment.NewLine); } else { WriteErrorLine("user(s) creation failed!"); } }