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 bool IsUserInRole(string username, string roleName) { if (string.IsNullOrEmpty(username)) { throw new ArgumentNullException("username"); } if (string.IsNullOrEmpty(roleName)) { throw new ArgumentNullException("roleName"); } global::SoftFluent.Samples.GED.Security.UserRole userRole = global::SoftFluent.Samples.GED.Security.UserRole.LoadByUserUserNameAndRoleName(username, roleName); return(userRole != null); }
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 } } } }