public override void AddUsersToRoles(string[] usernames, string[] roleNames) { if (usernames == null) { throw new ArgumentNullException("usernames"); } if (roleNames == null) { throw new ArgumentNullException("roleNames"); } List <global::SoftFluent.Samples.GED.Security.User> users = new List <global::SoftFluent.Samples.GED.Security.User>(usernames.Length); foreach (string username in usernames) { if (username == null) { continue; } global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("UserNotFound", "User '{0}' was not found.", new object[] { username })); } users.Add(user); } foreach (string roleName in roleNames) { if (roleName == null) { continue; } global::SoftFluent.Samples.GED.Security.Role role = global::SoftFluent.Samples.GED.Security.Role.LoadByName(roleName); if (role == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleNotFound", "Role '{0}' was not found.", new object[] { roleName })); } foreach (global::SoftFluent.Samples.GED.Security.User user in users) { global::SoftFluent.Samples.GED.Security.UserRole userRole = new global::SoftFluent.Samples.GED.Security.UserRole(); userRole.User = user; userRole.Role = role; try { userRole.Save(); } catch (CodeFluent.Runtime.CodeFluentDuplicateException) { // do nothing } } } }
public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames) { if (usernames == null) { throw new ArgumentNullException("usernames"); } if (roleNames == null) { throw new ArgumentNullException("roleNames"); } List <global::SoftFluent.Samples.GED.Security.User> users = new List <global::SoftFluent.Samples.GED.Security.User>(usernames.Length); foreach (string username in usernames) { if (username == null) { continue; } global::SoftFluent.Samples.GED.Security.User user = global::SoftFluent.Samples.GED.Security.User.LoadByUserName(username); if (user == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("UserNotFound", "User '{0}' was not found.", new object[] { username })); } users.Add(user); } foreach (string roleName in roleNames) { if (roleName == null) { continue; } global::SoftFluent.Samples.GED.Security.Role role = global::SoftFluent.Samples.GED.Security.Role.LoadByName(roleName); if (role == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleNotFound", "Role '{0}' was not found.", new object[] { roleName })); } foreach (global::SoftFluent.Samples.GED.Security.User user in users) { global::SoftFluent.Samples.GED.Security.UserRole userRole = global::SoftFluent.Samples.GED.Security.UserRole.LoadByUserUserNameAndRoleName(user.UserName, role.Name); if (userRole != null) { userRole.Delete(); } } } }
public override string[] GetUsersInRole(string roleName) { if (string.IsNullOrEmpty(roleName)) { throw new ArgumentNullException("roleName"); } global::SoftFluent.Samples.GED.Security.Role role = global::SoftFluent.Samples.GED.Security.Role.LoadByName(roleName); if (role == null) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleNotFound", "Role was not found.")); } return(GetUserNames(role.Users)); }
public override void CreateRole(string roleName) { if (string.IsNullOrEmpty(roleName)) { throw new ArgumentNullException("roleName"); } global::SoftFluent.Samples.GED.Security.Role role = new global::SoftFluent.Samples.GED.Security.Role(); role.Name = roleName; try { role.Save(); } catch (CodeFluent.Runtime.CodeFluentDuplicateException) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleAlreadyExists", "Role '{0}' already exists.", new object[] { roleName })); } }
public override bool DeleteRole(string roleName, bool throwOnPopulatedRole) { if (string.IsNullOrEmpty(roleName)) { throw new ArgumentNullException("roleName"); } global::SoftFluent.Samples.GED.Security.Role role = global::SoftFluent.Samples.GED.Security.Role.LoadByName(roleName); if (role == null) { return(false); } if (throwOnPopulatedRole) { if (role.Users.Count > 0) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleHasUsers", "Role has associated users.")); } } return(role.Delete()); }
public override void CreateRole(string roleName) { if (string.IsNullOrEmpty(roleName)) throw new ArgumentNullException("roleName"); global::SoftFluent.Samples.GED.Security.Role role = new global::SoftFluent.Samples.GED.Security.Role(); role.Name = roleName; try { role.Save(); } catch(CodeFluent.Runtime.CodeFluentDuplicateException) { throw new ProviderException(SoftFluent.Samples.GED.Resources.Manager.GetStringWithDefault("RoleAlreadyExists", "Role '{0}' already exists.", new object[]{roleName})); } }