public ServiceConfiguration GetConfigurations()
        {
            ServiceConfiguration serviceConfiguration;

            LogExtension.EnterMethod(SettingsSecureFileStore.logger, MethodBase.GetCurrentMethod());
            try
            {
                string encXml = SerializationHelper.ReadFromFile(SettingsSecureFileStore.FilePath);
                serviceConfiguration = ServiceConfiguration.FromXml(CryptographyHelper.DecryptFromLocalMachine(encXml));
                return(serviceConfiguration);
            }
            catch (Exception exception)
            {
                Exception ex = exception;
                SettingsSecureFileStore.logger.Error(ex.Message, ex);
            }
            LogExtension.EnterMethod(SettingsSecureFileStore.logger, MethodBase.GetCurrentMethod());
            serviceConfiguration = null;
            return(serviceConfiguration);
        }
Esempio n. 2
0
 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);
            }
        }