public void ProcessJob(TaskScheduling task) { ServicesAdministrationServiceClient adminClient = new ServicesAdministrationServiceClient(true); List <StoreType> storeTypes = adminClient.LoadAllStoreTypes(); adminClient.LoadAllIdentityStores().ForEach((IdentityStore store) => { if (store.get_StoreType() == null) { StoreType storeType = storeTypes.Find((StoreType st) => st.get_StoreTypeId() == store.get_StoreTypeId()); if (storeType != null) { store.set_StoreType(storeType); } } this.ReplicateStore(store); }); try { ActionResult result = (new ServicesAdministrationServiceClient(true)).EnsureSchemaLinkAttributeIsUptoDate(); Helper.LogDebugResults(SchemaReplicationProcessor.logger, result, "Schema link attribute update "); } catch (Exception exception1) { Exception exception = exception1; string message = string.Concat("Error occurred while updating the schema link attribute. Reason: ", exception.Message); LogExtension.LogException(SchemaReplicationProcessor.logger, message, exception); } SchemaReplicationProcessor.logger.InfoFormat("Job processed successfully.", Array.Empty <object>()); }
public virtual void ExtendEligibleGroupsLife() { ServicesSearchServiceClient searchServiceClient = new ServicesSearchServiceClient(false); FilterCriteria filterCriteria = this.GetEligibleGroupsFilter(); int totalFound = 0; Dictionary <string, bool> containers = null; if ((Helper.CurrentTask.get_Targets() == null ? false : Helper.CurrentTask.get_Targets().Count > 0)) { containers = Helper.CurrentTask.get_Targets().ToDictionary <SchedulingTarget, string, bool>((SchedulingTarget target) => target.get_Target(), (SchedulingTarget target) => false); } SearchFilter searchFilter1 = new SearchFilter(); searchFilter1.set_ExtensionDataCriteria(filterCriteria); searchFilter1.set_ProviderCriteria(new FilterCriteria()); SearchFilter searchFilter = searchFilter1; List <IdentityStoreObject> groupsToExtend = searchServiceClient.SearchEx(Helper.CurrentTask.get_IdentityStoreId(), 2, ref totalFound, searchFilter, containers, string.Empty, 1, -1, 20000, this.GetAttributesToLoad(), false); try { List <IdentityStoreObject> groupsOld = DeepCopyExtensionMethods.DeepCopy <List <IdentityStoreObject> >(groupsToExtend); List <string> reducedGroupsToNotify = new List <string>(); List <IdentityStoreObject> groupsToUpdate = this.PrepareGroupsForExtensions(groupsToExtend, ref reducedGroupsToNotify); ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false); List <IdentityStoreObject> groupsToUpdate1 = this.CloneObjectsForUpdate(new List <string>() { "XGroupExpirationPolicy", "XGroupExpirationDate" }, groupsToUpdate, groupsOld); if ((groupsToUpdate1 == null ? false : groupsToUpdate1.Any <IdentityStoreObject>())) { string compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate1); ActionResult result = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName); this.LogResults(result, "ExtendEligibleGroupsLife"); } if (reducedGroupsToNotify.Count > 0) { groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 37, reducedGroupsToNotify); } } catch (Exception exception) { Exception Ex = exception; LogExtension.LogException(GroupsProcessor.logger, string.Format("An error ocurred while expiring groups: {0}", Ex.Message), Ex); } }
protected virtual bool PrepareGroupForLifeExtension(IdentityStoreObject grp) { bool flag; try { if (!Helper.AppConfiguration.get_IsGroupAttestationEnabled()) { TimeSpan lastNotificationSpan = new TimeSpan(); string lastSentValue = this.GetAttributeValue("IMGLastSentExpireNotificationDate", grp.get_AttributesBusinessObject()).get_Value(); if (!string.IsNullOrEmpty(lastSentValue)) { DateTime lastSentDate = Helper.ParseDateTime(lastSentValue); if (lastSentDate.Date == DateTime.MinValue.Date) { GroupsProcessor.logger.ErrorFormat("PrepareGroupForLifeExtension: Invalid date format {0}", lastSentValue); } lastNotificationSpan = DateTime.Now.Subtract(lastSentDate); } else if ((Helper.AppConfiguration.get_GenerateSevenDaysToExpiryReport() ? true : Helper.AppConfiguration.get_GenerateOnedayToExpiryReport())) { DateTime date = DateTime.Now.AddDays(7); date = date.Date; this.SetAttributeValue("XGroupExpirationDate", date.ToString("yyyy MMMM dd HH:mm:ss"), grp.get_AttributesBusinessObject()); flag = true; return(flag); } } else { flag = false; return(flag); } } catch (Exception exception) { Exception ex = exception; LogExtension.LogException(GroupsProcessor.logger, string.Format("An Error occured while performing GLM Expiry operation on group: {0} Reason: {1}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_DisplayName(), grp.get_AttributesBusinessObject()).get_Value() ?? string.Empty, ex.Message), ex); } flag = false; return(flag); }
public void ProcessJob(TaskScheduling task) { try { ServicesAdministrationServiceClient adminClient = new ServicesAdministrationServiceClient(true); ServicesSearchServiceClient searchClient = new ServicesSearchServiceClient(false); IdentityStore store = adminClient.GetIdentityStoreById(task.get_IdentityStoreId(), true); KnownAttributes knownAttributes = searchClient.GetKnownAttributes(task.get_IdentityStoreId()); List <PermissionAnalyzerServer> servers = new List <PermissionAnalyzerServer>(); Dictionary <string, Dictionary <int, string> > configurations = this.LoadConfigurations(store, adminClient, servers, knownAttributes); List <Schema> schema = adminClient.GetIdentityStoreSchema(task.get_IdentityStoreId()); if (servers.Count > 0) { (new Imanami.PermissionReplicationService.PermissionReplicationService(store, configurations, schema, knownAttributes)).ReplicatePermissions(1, servers); } } catch (Exception exception) { LogExtension.LogException(PermissionAnalyzer.logger, "Error While Replicating Permissions.", exception); } PermissionAnalyzer.logger.InfoFormat("Job processed successfully.", Array.Empty <object>()); }
public Dictionary <string, Dictionary <int, string> > LoadConfigurations(IdentityStore store, ServicesAdministrationServiceClient _client, List <PermissionAnalyzerServer> servers, KnownAttributes knownAttributes) { Dictionary <string, Dictionary <int, string> > strs; try { try { PermissionAnalyzerConfigurationService permissionAnalyzerConfigurationService = new PermissionAnalyzerConfigurationService(store.get_IdentityStoreId()); Dictionary <string, Dictionary <int, string> > strs1 = new Dictionary <string, Dictionary <int, string> >(); IdentityStorePermissionAnalyzerConfiguration permissionConfigurations = permissionAnalyzerConfigurationService.GetPermissionConfigurations(); if ((permissionConfigurations == null || permissionConfigurations.get_Servers() == null ? false : permissionConfigurations.get_Servers().Count > 0)) { if (permissionConfigurations.get_IncludeFutureServers()) { List <PermissionAnalyzerServer> allServers = permissionAnalyzerConfigurationService.GetCriteriaBasedServers(permissionConfigurations); IEnumerable <string> strs2 = ( from x in allServers select x.get_ServerID()).Except <string>( from y in permissionConfigurations.get_Servers() select y.get_ServerID()); IEnumerable <PermissionAnalyzerServer> latestServers = from server in allServers where strs2.Any <string>((string id) => server.get_ServerID().Equals(id, StringComparison.InvariantCultureIgnoreCase)) select server; if ((latestServers == null ? false : latestServers.Count <PermissionAnalyzerServer>() > 0)) { permissionConfigurations.get_Servers().AddRange(latestServers); } } if ((Helper.CurrentTask.get_Targets() == null ? false : Helper.CurrentTask.get_Targets().Count > 0)) { permissionConfigurations.set_Servers(( from server in permissionConfigurations.get_Servers() where Helper.CurrentTask.get_Targets().Any <SchedulingTarget>((SchedulingTarget target) => target.get_Target().Equals(server.get_ServerID(), StringComparison.InvariantCultureIgnoreCase)) select server).ToList <PermissionAnalyzerServer>()); Helper.CurrentTask.get_Targets().Clear(); } permissionConfigurations.get_Servers().ForEach((PermissionAnalyzerServer server) => { if (permissionConfigurations.get_ExcludedServers() != null) { if (permissionConfigurations.get_ExcludedServers().Any <string>((string excludedServer) => excludedServer.Equals(server.get_ServerID(), StringComparison.InvariantCultureIgnoreCase))) { return; } } if (!string.IsNullOrEmpty(server.get_ScheduleJob())) { if (!server.get_ScheduleJob().Equals(PermissionAnalyzerConfigurationService.GetScheduleName())) { return; } } if (server.get_Credentials() == null) { server.set_Credentials(new PermissionAnalyzerServerCredentials()); } server.get_Credentials(); if (server.get_IsServiceAccountConfigured()) { server.get_Credentials().set_UserName(store.get_IdentityStoreConfigurationValues()["UserName"]); server.get_Credentials().set_Password(store.get_IdentityStoreConfigurationValues()["Password"]); } server.get_Credentials().set_ServerName(server.get_Server()); if ((server.get_FileShare() == null ? false : server.get_FileShare().get_Shares() != null)) { List <string> serverShares = new List <string>(); if (!server.get_IsServiceAccountConfigured()) { server.get_Credentials().set_Password(CryptographyHelper.DecryptFromLocalMachine(server.get_Credentials().get_Password())); } try { serverShares = permissionAnalyzerConfigurationService.GetNetworkShareResourcesList(server.get_Credentials()); } catch (Exception exception) { } if (!server.get_IsServiceAccountConfigured()) { server.get_Credentials().set_Password(CryptographyHelper.EncryptForLocalMachine(server.get_Credentials().get_Password())); } serverShares.ForEach((string latestShare) => { if (!server.get_FileShare().get_Shares().Any <PermissionAnalyzerServerShare>((PermissionAnalyzerServerShare x) => x.get_ShareID().Equals(latestShare, StringComparison.InvariantCultureIgnoreCase))) { List <PermissionAnalyzerServerShare> shares = server.get_FileShare().get_Shares(); PermissionAnalyzerServerShare permissionAnalyzerServerShare = new PermissionAnalyzerServerShare(); permissionAnalyzerServerShare.set_IsSelected(true); permissionAnalyzerServerShare.set_Share(latestShare); permissionAnalyzerServerShare.set_ShareID(latestShare); shares.Add(permissionAnalyzerServerShare); } }); } this.SetConfigurations(store, server, strs1); servers.Add(server); }); } strs = strs1; return(strs); } catch (Exception exception1) { Exception ex = exception1; LogExtension.LogException(PermissionAnalyzer.logger, ex.Message, ex); } } finally { (new ServicesSchedulingServiceClient(false)).Update(Helper.CurrentTask); } strs = new Dictionary <string, Dictionary <int, string> >(); return(strs); }
protected virtual bool ExtendLifeForGUS(IdentityStoreObject grp) { bool flag; DateTime today; if ((!Helper.AppConfiguration.get_GUSIsLifecycleEnabled() || !Helper.AppConfiguration.get_GUSExtendGroupsLife() ? true : !grp.get_AttributesBusinessObject().HasValue(Helper.KnownProviderAttributes.get_Alias()))) { flag = false; } else if (!Helper.AppConfiguration.get_IsGroupAttestationEnabled()) { try { string lastUsed = this.GetAttributeValue("IMGLastUsed", grp.get_AttributesBusinessObject()).get_Value(); if (string.IsNullOrEmpty(lastUsed)) { flag = false; return(flag); } else { DateTime lastUsedDate = Helper.ParseDateTime(lastUsed); if (lastUsedDate == DateTime.MinValue) { GroupsProcessor.logger.ErrorFormat("ExtendLifeForGUS: Invalid date format {0}", lastUsedDate); flag = false; return(flag); } else if ((DateTime.Now - lastUsedDate).Days > Helper.AppConfiguration.get_GUSUsedGroupsTime()) { flag = false; return(flag); } else { Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute policyDto = this.GetAttributeValue("XGroupExpirationPolicy", grp.get_AttributesBusinessObject()); int policy = -1; DateTime extendedDate = DateTime.MaxValue.Date; if (!int.TryParse(policyDto.get_Value() ?? string.Empty, out policy)) { policy = Helper.AppConfiguration.get_DefaultExpirationPolicy(); if (policy != 0) { today = DateTime.Today; today = today.AddDays((double)policy); extendedDate = today.Date; } } else if (policy != 0) { today = DateTime.Today; today = today.AddDays((double)policy); extendedDate = today.Date; } this.SetAttributeValue("XGroupExpirationDate", extendedDate.ToString("yyyy MMMM dd HH:mm:ss"), grp.get_AttributesBusinessObject()); today = DateTime.Now; this.SetAttributeValue("IMGLastRenewedDate", today.ToString(), grp.get_AttributesBusinessObject()); flag = true; return(flag); } } } catch (Exception exception) { Exception ex = exception; LogExtension.LogException(GroupsProcessor.logger, string.Format("An Error occured while performing GLM Extend life operation on group: {0} Reason: {1}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_DisplayName(), grp.get_AttributesBusinessObject()).get_Value() ?? string.Empty, ex.Message), ex); } flag = false; } else { flag = false; } return(flag); }
protected virtual bool ReduceLifeForGUS(IdentityStoreObject grp) { bool flag; DateTime date; if ((!Helper.AppConfiguration.get_GUSIsLifecycleEnabled() || !Helper.AppConfiguration.get_GUSReduceGroupsLife() ? true : !grp.get_AttributesBusinessObject().HasValue(Helper.KnownProviderAttributes.get_Alias()))) { flag = false; } else if (!Helper.AppConfiguration.get_IsGroupAttestationEnabled()) { try { string lastProcessed = this.GetAttributeValue("IMGLastProcessedDate", grp.get_AttributesBusinessObject()).get_Value(); string lastUsed = this.GetAttributeValue("IMGLastUsed", grp.get_AttributesBusinessObject()).get_Value(); if (!string.IsNullOrEmpty(lastProcessed)) { DateTime lastProcessedDate = Helper.ParseDateTime(lastProcessed); if (lastProcessedDate == DateTime.MinValue) { GroupsProcessor.logger.ErrorFormat("ReduceLifeForGUS: Invalid date format {0}", lastProcessedDate); flag = false; return(flag); } else if ((DateTime.Now - lastProcessedDate).Days > 30) { flag = false; return(flag); } else { DateTime lastUsedDate = DateTime.MinValue; if (!string.IsNullOrEmpty(lastUsed)) { lastUsedDate = Helper.ParseDateTime(lastUsed); } if (lastUsedDate == DateTime.MinValue) { string expiration = this.GetAttributeValue("XGroupExpirationDate", grp.get_AttributesBusinessObject()).get_Value(); if (string.IsNullOrEmpty(expiration)) { flag = false; return(flag); } else { DateTime expirationdDate = Helper.ParseDateTime(expiration); if (expirationdDate.Date == DateTime.MinValue.Date) { GroupsProcessor.logger.ErrorFormat("ReduceLifeForGUS: Invalid date format {0}", expirationdDate); flag = false; return(flag); } else if ((expirationdDate.Date - DateTime.Now.Date).Days <= 7) { flag = false; return(flag); } else { date = DateTime.Now.AddDays(7); date = date.Date; this.SetAttributeValue("XGroupExpirationDate", date.ToString("yyyy MMMM dd HH:mm:ss"), grp.get_AttributesBusinessObject()); date = DateTime.Now; this.SetAttributeValue("IMGLastRenewedDate", date.ToString(), grp.get_AttributesBusinessObject()); flag = true; return(flag); } } } else if ((DateTime.Now - lastUsedDate).Days >= Helper.AppConfiguration.get_GUSUnusedGroupsTime()) { string expiration = this.GetAttributeValue("XGroupExpirationDate", grp.get_AttributesBusinessObject()).get_Value(); if (string.IsNullOrEmpty(expiration)) { flag = false; return(flag); } else { DateTime expirationdDate = Helper.ParseDateTime(expiration); if (expirationdDate.Date == DateTime.MinValue.Date) { GroupsProcessor.logger.ErrorFormat("ReduceLifeForGUS: Invalid date format {0}", expirationdDate); flag = false; return(flag); } else if ((expirationdDate.Date - DateTime.Now.Date).Days <= 7) { flag = false; return(flag); } else { date = DateTime.Now.AddDays(7); date = date.Date; this.SetAttributeValue("XGroupExpirationDate", date.ToString("yyyy MMMM dd HH:mm:ss"), grp.get_AttributesBusinessObject()); date = DateTime.Now; this.SetAttributeValue("IMGLastRenewedDate", date.ToString(), grp.get_AttributesBusinessObject()); flag = true; return(flag); } } } } } flag = false; return(flag); } catch (Exception exception) { Exception ex = exception; LogExtension.LogException(GroupsProcessor.logger, string.Format("An Error occured while performing GLM Expiry operation on group: {0} Reason: {1}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_DisplayName(), grp.get_AttributesBusinessObject()).get_Value() ?? string.Empty, ex.Message), ex); } flag = false; } else { flag = false; } return(flag); }
public virtual List <IdentityStoreObject> PrepareGroupsForExtensions(List <IdentityStoreObject> groupsToExtend, ref List <string> reducedGroupsToNotify) { DateTime expirationDate; List <IdentityStoreObject> groupsToUpdate = new List <IdentityStoreObject>(); foreach (IdentityStoreObject group in groupsToExtend) { try { if (!this.IsGroup(group)) { GroupsProcessor.logger.DebugFormat("PrepareGroupsForExtensions. Object {0} is not a group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (this.IsSystemGroup(group)) { GroupsProcessor.logger.DebugFormat("PrepareGroupsForExtensions. Object {0} is a system group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (this.IsGlmBlankGroup(group)) { GroupsProcessor.logger.DebugFormat("PrepareGroupsForExtensions. Object {0} is glm blank group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (!this.ShouldExpireSecurityGroup(group)) { GroupsProcessor.logger.DebugFormat("PrepareGroupsForExtensions. Object {0} is a security group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (!this.IsGroupInExcludedContainer(group)) { Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute expirationDateDto = this.GetAttributeValue("XGroupExpirationDate", group.get_AttributesBusinessObject()); if (DateTime.TryParse(expirationDateDto.get_Value() ?? string.Empty, out expirationDate)) { if (DateTime.Now.Date.Subtract(expirationDate.Date).Days > 0) { } } if (this.ReduceLifeForGUS(group)) { groupsToUpdate.Add(group); reducedGroupsToNotify.Add(group.get_ObjectIdFromIdentityStore()); } if (this.ExtendLifeForGUS(group)) { groupsToUpdate.Add(group); this.ExtendedGroups.Add(group.get_ObjectIdFromIdentityStore()); } } else { Imanami.GroupID.DataTransferObjects.DataContracts.Services.Attribute policyDto = this.GetAttributeValue("XGroupExpirationPolicy", group.get_AttributesBusinessObject()); int policy = -1; if (int.TryParse(policyDto.get_Value() ?? string.Empty, out policy)) { if (policy != 0) { int num = 0; this.SetAttributeValue("XGroupExpirationPolicy", num.ToString(), group.get_AttributesBusinessObject()); DateTime date = DateTime.MaxValue.Date; this.SetAttributeValue("XGroupExpirationDate", date.ToString(), group.get_AttributesBusinessObject()); groupsToUpdate.Add(group); } } } } catch (Exception exception) { Exception Ex = exception; LogExtension.LogException(GroupsProcessor.logger, string.Format("An error ocurred while expiring groups: {0}", Ex.Message), Ex); } } return(groupsToUpdate); }
private static void Main(string[] args) { Console.Title = "Task Scheduler Runner"; args = new string[] { "0AA##0PV7M#AQAAANCMnd8BFdERjHoAwE/Cl+sBAAAABOimvGWmYk+OwElU3xgGewQAAAACAAAAAAADZgAAwAAAABAAAAA+yg5rxV+6laCj+NmjyzUUAAAAAASAAACgAAAAEAAAALBk/IjhAvXRv7AKRVRSFxIIAAAA0wsOxFN3pAAUAAAALS5bfTs3WJzAPK4Tn+V3EK5mLC8=Ukx5N0AlazM=" }; Console.WriteLine("Press any key to start..."); Console.ReadKey(false); try { try { Console.WriteLine("Program Started"); LogExtension.RegisterCustomLogLevels(); XmlConfigurator.Configure(); LogExtension.EnterMethod(Program.logger, MethodBase.GetCurrentMethod(), args); string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Schedules"); Console.WriteLine(string.Concat("Schedules Path: ", path)); int jobId = Convert.ToInt32(CryptographyHelper.DecryptFromLocalMachine(args[0])); Console.WriteLine(string.Format("Job ID: {0}", jobId)); path = Path.Combine(path, string.Concat("task", jobId.ToString(), ".txt")); if (!File.Exists(path)) { Console.WriteLine(string.Concat("Path ", path, " does not exists.")); Program.InitializeSystemSecurityContext(); Helper.IsSystemSecurityContext = true; } else { Console.WriteLine(string.Concat("Path ", path, " exists.")); using (StreamReader data = File.OpenText(path)) { string[] container = data.ReadToEnd().Split(new string[] { "<#!#>" }, StringSplitOptions.None); jobId = Convert.ToInt32(CryptographyHelper.DecryptFromLocalMachine(container[0])); Console.WriteLine(string.Format("Job ID from job file: {0}", jobId)); Program.InitializeSecurityContext(CryptographyHelper.DecryptFromLocalMachine(container[2])); Helper.IsSystemSecurityContext = false; } } Console.WriteLine("System security context initialized"); LicensingProvider licensingProvider = new LicensingProvider(); if ((licensingProvider.HasValidProductLicense(1) ? false : !licensingProvider.HasValidProductLicense(3))) { if (!licensingProvider.HasValidProductLicense(8)) { Console.WriteLine("License error. Returning..."); Program.logger.Error("Invalid License"); return; } else { TaskScheduling task = (new ServicesSchedulingServiceClient(true)).GetScheduledJob((long)jobId); if (task == null) { return; } else if (task.get_JobType() != 13) { Program.logger.Error("Invalid License"); Console.WriteLine("License error. Returning..."); return; } } } JobProcessor jobProcessor = new JobProcessor(); Console.WriteLine(string.Format("Ready to process job {0}", jobId)); jobProcessor.ProcessJob((long)jobId); Console.WriteLine(string.Format("Job {0} processed.", jobId)); } catch (CryptographicException cryptographicException1) { CryptographicException cryptographicException = cryptographicException1; string message = string.Concat(cryptographicException.Message, " Error in initializing security context for the Scheduled job. Possible reason may be, that a required windows service is not running. Please make sure that 'CNG Key Isolation' windows service is running."); Console.WriteLine(string.Format("Exception {0}: {1}. Details: {2}. Trace:", cryptographicException.GetType(), cryptographicException.Message, message)); Console.WriteLine(cryptographicException.StackTrace); LogExtension.LogException(Program.logger, message, cryptographicException, 1, "Logging.Const.LoggingConstants.jobUpdate"); } catch (Exception exception) { Exception ex = exception; Console.WriteLine(string.Format("Exception {0}: {1}. Trace:", ex.GetType(), ex.Message)); Console.WriteLine(ex.StackTrace); LogExtension.LogException(Program.logger, ex.Message, ex, 1, "Logging.Const.LoggingConstants.jobUpdate"); } } finally { LogExtension.ExitMethod(Program.logger, MethodBase.GetCurrentMethod(), args); } }
public virtual void DeleteExpiredGroups(List <IdentityStoreObject> groups) { LogExtension.EnterMethod(GroupsProcessor.logger, MethodBase.GetCurrentMethod(), new object[0]); List <string> groupsToNotify = new List <string>(); List <IdentityStoreObject> groupsToDelete = new List <IdentityStoreObject>(); try { foreach (IdentityStoreObject group in groups) { try { if (!this.IsGroup(group)) { GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is not a group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (this.IsSystemGroup(group)) { GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is a system group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (this.IsGroupInExcludedContainer(group)) { GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is in excluded containers.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } else if (this.ShouldExpireSecurityGroup(group)) { string expirationDateString = this.GetAttributeValue("XGroupExpirationDate", group.get_AttributesBusinessObject()).get_Value(); DateTime expirationDate = Helper.ParseDateTime(expirationDateString); if (expirationDate.Date == DateTime.MinValue.Date) { continue; } else if (DateTime.Now.Date.Subtract(expirationDate.Date).Days >= Helper.AppConfiguration.get_DeletionDaysAfterExpiry()) { this.SetAttributeValue("IMGIsDeleted", "true", group.get_AttributesBusinessObject()); string updatedDisplayName = this.GetUpdatedDisplayName(group); group.set_ObjectDisplayName(updatedDisplayName); this.SetAttributeValue(Helper.KnownProviderAttributes.get_DisplayName(), updatedDisplayName, group.get_AttributesBusinessObject()); groupsToNotify.Add(group.get_ObjectIdFromIdentityStore()); groupsToDelete.Add(group); GroupsProcessor.logger.InfoFormat("Group Deleted: {0}", group.get_ObjectDisplayName()); } else { continue; } } else { GroupsProcessor.logger.DebugFormat("DeleteExpiredGroups. Object {0} is a security group.", this.GetAttributeValue(Helper.KnownProviderAttributes.get_Name(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty); continue; } } catch (Exception exception) { Exception ex = exception; GroupsProcessor.logger.Error(string.Format("An Error occured while performing deletion operation on group: {0} Reason: {1}", this.GetAttributeValue(Helper.KnownProviderAttributes.get_DistinguishedName(), group.get_AttributesBusinessObject()).get_Value() ?? string.Empty, ex.Message), ex); } } ServicesGroupServiceClient groupServiceClient = new ServicesGroupServiceClient(false); if (groupsToDelete.Count > 0) { groupsToDelete.ForEach((IdentityStoreObject g) => this.SetAttributeValue("IMGLastSentExpireNotificationDate", DateTime.Now.Date.ToString("yyyy MMMM dd HH:mm:ss"), g.get_AttributesBusinessObject())); groupsToDelete.ForEach((IdentityStoreObject g) => this.SetAttributeValue("IMGIsDeleted", "TRUE", g.get_AttributesBusinessObject())); List <IdentityStoreObject> groupsToUpdate = this.CloneObjectsForUpdate(new List <string>() { "IMGLastSentExpireNotificationDate", "IMGIsDeleted", Helper.KnownProviderAttributes.get_DisplayName() }, groupsToDelete, null); string compressedString = DataCompressionHelper.CompressObjects <List <IdentityStoreObject> >(groupsToUpdate); ActionResult result = groupServiceClient.UpdateManyWithCompression(Helper.CurrentTask.get_IdentityStoreId(), compressedString, typeof(IdentityStoreObject).FullName); this.LogResults(result, "DeleteExpiredGroups"); } if (groupsToNotify.Count > 0) { ActionResult result = groupServiceClient.SendGlmNotification(Helper.CurrentTask.get_IdentityStoreId(), 29, groupsToNotify); this.LogResults(result, "DeleteExpiredGroups-Notifications"); } LogExtension.ExitMethod(GroupsProcessor.logger, MethodBase.GetCurrentMethod(), new object[0]); } catch (Exception exception1) { Exception Ex = exception1; LogExtension.LogException(GroupsProcessor.logger, string.Format("An error ocurred while deleting 30 days old expired groups: {0}", Ex.Message), Ex); } }