public IActionResult CheckUserValidity(string username) { if (_bUser.IsValidUser(username)) { return(Ok()); } return(NotFound()); }
public bool IsUserGroupMember(string groupName, string username) { if (!IsValidGroup(groupName)) { return(false); } if (!_bUser.IsValidUser(username)) { return(false); } var groupList = new HashSet <string> { groupName }; while (groupList.Count > 0) { var currentGroup = groupList.First(); using (var ctx = new PrincipalContext(ContextType.Domain)) { var group = GroupPrincipal.FindByIdentity(ctx, currentGroup); if (group == null) { groupList.Remove(currentGroup); continue; } foreach (var principal in group.GetMembers()) { if (principal is UserPrincipal) { if (principal.SamAccountName == username) { return(true); } } else { groupList.Add(principal.SamAccountName); } } } groupList.Remove(currentGroup); } return(false); }