public override object GetParametersInstance() { ActiveDirectoryHandlerParameters parms = new ActiveDirectoryHandlerParameters(); parms.Users = new List <AdUser>(); AdUser user = new AdUser(); user.Identity = "cn=mfox,ou=FamousActors,dc=sandbox,dc=local"; parms.Users.Add(user); parms.Groups = new List <AdGroup>(); AdGroup group = new AdGroup(); group.Identity = "cn=BackToTheFuture,ou=Movies,dc=sandbox,dc=local"; parms.Groups.Add(group); parms.OrganizationalUnits = new List <AdOrganizationalUnit>(); AdOrganizationalUnit ou = new AdOrganizationalUnit(); ou.Identity = "ou=Movies,dc=sandbox,dc=local"; parms.OrganizationalUnits.Add(ou); parms.SearchRequests = new List <AdSearchRequest>(); AdSearchRequest search = new AdSearchRequest(); search.SearchBase = "ou=Synapse,dc=sandbox,dc=local"; search.Filter = "(objectClass=User)"; search.ReturnAttributes = new List <string>(); search.ReturnAttributes.Add("Name"); search.ReturnAttributes.Add("objectGUID"); parms.SearchRequests.Add(search); return(parms); }
public ActiveDirectoryHandlerResults Search(AdSearchRequest request) { string planName = config.Plans.Search; StartPlanEnvelope pe = GetPlanEnvelope(request); return(CallPlan(planName, pe)); }
// Base Envelope for Generically Defined ActiveDirectory Searches private StartPlanEnvelope GetPlanEnvelope(AdSearchRequest request) { StartPlanEnvelope pe = new StartPlanEnvelope() { DynamicParameters = new Dictionary <string, string>() }; pe.DynamicParameters.Add(@"filter", request.Filter); if (request.SearchBase != null) { pe.DynamicParameters.Add(@"searchbase", request.SearchBase); } if (request.ResultsFile != null) { pe.DynamicParameters.Add(@"resultsfile", request.ResultsFile); } string attributes = YamlHelpers.Serialize(request.ReturnAttributes, true, false); if (attributes != null) { pe.DynamicParameters.Add(@"attributes", attributes); } return(pe); }
private void ProcessSearchRequest(AdSearchRequest request) { ActiveDirectoryStatus status = new ActiveDirectoryStatus() { Action = ActionType.Search, Status = AdStatusType.Success, Message = "Success", }; ActiveDirectoryObjectResult result = new ActiveDirectoryObjectResult() { Type = AdObjectType.SearchResults, }; try { string searchBase = request.SearchBase; if (String.IsNullOrWhiteSpace(request.SearchBase)) { searchBase = DirectoryServices.GetDomainDistinguishedName(); } roleManager.CanPerformActionOrException(requestUser, ActionType.Search, searchBase); String filter = request.Filter; if (request.Parameters != null) { foreach (RegexParameters param in request.Parameters) { filter = Regex.Replace(filter, param.Find, param.ReplaceWith); } } OnLogMessage("ProcessSearchRequest", $"Executing Search. Filter String: [{filter}]. Search Base: [{searchBase}]."); SearchResultsObject searchResults = DirectoryServices.Search(searchBase, filter, request.ReturnAttributes?.ToArray()); result.Object = searchResults; result.Statuses.Add(status); } catch (AdException ade) { ProcessActiveDirectoryException(result, ade, ActionType.Search); } results.Add(result); }