/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List <string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE_SYSTEMTABLE, DataClassInfo.OBJECT_TYPE_CUSTOMTABLE, DataClassInfo.OBJECT_TYPE_DOCUMENTTYPE, PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, "administrator", true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
/// <summary> /// Refreshes macro signatures in all object which can contain macros. /// </summary> private static void RefreshMacroSignatures() { // Get object types var objectTypes = new List <string> { TransformationInfo.OBJECT_TYPE, UIElementInfo.OBJECT_TYPE, FormUserControlInfo.OBJECT_TYPE, SettingsKeyInfo.OBJECT_TYPE, AlternativeFormInfo.OBJECT_TYPE, DataClassInfo.OBJECT_TYPE, // Process all data classes just through general object type to avoid duplicities PageTemplateInfo.OBJECT_TYPE, LayoutInfo.OBJECT_TYPE, CssStylesheetInfo.OBJECT_TYPE, WorkflowActionInfo.OBJECT_TYPE, }; var adminIdentityOption = MacroIdentityOption.FromUserInfo(UserInfoProvider.AdministratorUser); foreach (string type in objectTypes) { try { using (var context = new CMSActionContext()) { context.DisableLogging(); context.CreateVersion = false; context.LogIntegration = false; var infos = new InfoObjectCollection(type); foreach (var info in infos) { MacroSecurityProcessor.RefreshSecurityParameters(info, adminIdentityOption, true); } } } catch (Exception ex) { EventLogProvider.LogException(EventLogSource, "REFRESHMACROSIGNATURES", ex, 0, "Type: " + type); } } }
private void RefreshSecurityParams(IEnumerable <string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (var context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; var processingString = GetString("macros.refreshsecurityparams.processing"); foreach (var objectType in objectTypes) { var niceObjectType = GetNiceObjectTypeName(objectType); AddLog(string.Format(processingString, niceObjectType)); try { var infos = new InfoObjectCollection(objectType) { PageSize = 1000 }; var csi = infos.TypeInfo.ClassStructureInfo; var orderByIndex = FindOrderByIndex(csi); if (orderByIndex != null) { infos.OrderByColumns = orderByIndex.GetOrderBy(); } // Skip object types derived from general data class object type to avoid duplicities if ((infos.TypeInfo.OriginalObjectType == DataClassInfo.OBJECT_TYPE) && (infos.TypeInfo.ObjectType != DataClassInfo.OBJECT_TYPE)) { continue; } foreach (var info in infos) { try { bool refreshed; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { var identityOption = MacroIdentityOption.FromUserInfo(MembershipContext.AuthenticatedUser); if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, identityOption, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } } catch (Exception ex) { AddLog(ex.Message); using (var exceptionContext = new CMSActionContext()) { exceptionContext.LogEvents = true; EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", ex); } } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }
/// <summary> /// Refreshes the security parameters in macros for all the objects of the specified object types. /// Signs all the macros with the current user if the old salt is not specified. /// </summary> /// <param name="objectTypes">Object types</param> /// <param name="oldSalt">Old salt </param> /// <param name="newSalt">New salt</param> private void RefreshSecurityParams(IEnumerable <string> objectTypes, string oldSalt, string newSalt) { var oldSaltSpecified = !string.IsNullOrEmpty(oldSalt) && !chkRefreshAll.Checked; var newSaltSpecified = !string.IsNullOrEmpty(newSalt) && !chkUseCurrentSalt.Checked; processedObjects.Clear(); using (CMSActionContext context = new CMSActionContext()) { context.LogEvents = false; context.LogSynchronization = false; foreach (var objectType in objectTypes) { var objectTypeResourceKey = TypeHelper.GetObjectTypeResourceKey(objectType); var niceObjectType = GetString(objectTypeResourceKey); if (niceObjectType == objectTypeResourceKey) { if (objectType.StartsWithCSafe("bizformitem.bizform.", true)) { DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(objectType.Substring("bizformitem.".Length)); if (dci != null) { niceObjectType = "on-line form " + dci.ClassDisplayName; } } else { niceObjectType = objectType; } } LogContext.AppendLine(string.Format(GetString("macros.refreshsecurityparams.processing"), niceObjectType)); try { var infos = new InfoObjectCollection(objectType); foreach (var info in infos) { try { bool refreshed = false; if (oldSaltSpecified) { refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, oldSalt, newSaltSpecified ? newSalt : ValidationHelper.HashStringSalt, true); } else { if (chkRefreshAll.Checked && newSaltSpecified) { // Do not check integrity, but use new salt refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true, newSalt); } else { // Do not check integrity, sign everything with current user refreshed = MacroSecurityProcessor.RefreshSecurityParameters(info, MembershipContext.AuthenticatedUser.UserName, true); } } if (refreshed) { var objectName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(info.Generalized.ObjectDisplayName)); processedObjects.Add(niceObjectType, objectName); } } catch (Exception ex) { string message = "Signing " + TypeHelper.GetNiceObjectTypeName(info.TypeInfo.ObjectType) + " " + info.Generalized.ObjectDisplayName + " failed: " + ex.Message; EventLogProvider.LogEvent(EventType.ERROR, "Import", "MACROSECURITY", message); } } } catch (Exception e) { LogContext.AppendLine(e.Message); EventLogProvider.LogException(EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "ERROR", e); } } } EventLogProvider.LogEvent(EventType.INFORMATION, EVENTLOG_SOURCE_REFRESHSECURITYPARAMS, "PROCESSEDOBJECTS", GetProcessedObjectsForEventLog()); }