//OK public override string[] GetAllRoles() { string[] res = null; try { var ad = new ADAuthenticationHelper(this.domain, this.contextUsername, this.contextPassword); var groups = ad.GetAllGroups(); if (groups.Count == 0) res = new string[0]; else res = groups.ToArray(); } catch (Exception e) { throw new ProviderException("GetAllRoles() error in "+ providerName , e); } return res; }
public override MembershipUserCollection FindUsersByName(string usernameToMatch, int pageIndex, int pageSize, out int totalRecords) { var res = new MembershipUserCollection(); totalRecords = 0; //not filled try { var ad = new ADAuthenticationHelper( this.domain, this.contextUsername, this.contextPassword); var users = ad.FindUsers(usernameToMatch); int counter = 0; int startIndex = pageSize * pageIndex; int endIndex = startIndex + pageSize - 1; foreach (var user in users) { if (counter >= startIndex) { MembershipUser u = GetUser(user, true); res.Add(u); } if (endIndex > 0) { if (counter >= endIndex) { break; } } counter++; } } catch (Exception ex) { throw new ProviderException("FindUsersByName() error in " + providerName, ex); } return res; }
//OK public override bool ValidateUser(string username, string password) { bool result = false; try { var ad = new ADAuthenticationHelper( this.domain, this.contextUsername, this.contextPassword); result = ad.IsAuthenticated(this.domain, username, password); } catch (Exception ex) { throw new ProviderException("ValidateUser(string, string) error in " + providerFullName, ex); } return result; }
//OK public override bool RoleExists(string rolename) { bool exists = false; try { var ad = new ADAuthenticationHelper(this.domain, this.contextUsername, this.contextPassword); var list = ad.GetAllGroups(rolename); if (list.Count > 0) exists = true; } catch (Exception e) { throw new ProviderException("RoleExists(string) error in SidRoleProvider", e); } return exists; }
//OK public override bool IsUserInRole(string username, string rolename) { bool userIsInRole = false; try { var ad = new ADAuthenticationHelper(this.domain, this.contextUsername, this.contextPassword); var list = ad.GetUsersInGroup(rolename, true, username); //return PrincipalOperationException #87 with some roles //see http://support.microsoft.com/kb/2585635 if (list.Count > 0) userIsInRole = true; } catch (Exception e) { throw new ProviderException("IsUserInRole(string, string) error in " + providerName, e); } return userIsInRole; }
//OK public override string[] GetUsersInRole(string rolename) { string[] res = null; try { var ad = new ADAuthenticationHelper(this.domain, this.contextUsername, this.contextPassword); var list = ad.GetUsersInGroup(rolename, false); if (list.Count == 0) res = new string[0]; else res = list.ToArray(); } catch (Exception e) { throw new ProviderException("GetUsersInRole() error in " + providerName, e); } return res; }