private static List <SensitivityLabelModel> MergeSensitivityLabels(
            List <SensitivityLabelModel> existingLabels,
            List <SensitivityLabelModel> newLabels,
            InformationProtectionPolicy informationProtectionPolicy)
        {
            List <SensitivityLabelModel> mergedLabels = new List <SensitivityLabelModel>();

            if (newLabels == null)
            {
                return(mergedLabels);
            }

            if (existingLabels == null)
            {
                return(newLabels);
            }

            IComparer <SensitivityLabelModel> comparer = new SortComparer();

            existingLabels.Sort(comparer);
            newLabels.Sort(comparer);


            int existingLabelsIndex = 0;
            int existingLabelsCount = existingLabels.Count();

            int newLabelsIndex = 0;
            int newLabelsCount = newLabels.Count();

            while (existingLabelsIndex < existingLabelsCount && newLabelsIndex < newLabelsCount)
            {
                SensitivityLabelModel existingLabel = existingLabels.ElementAt(existingLabelsIndex);
                SensitivityLabelModel newLabel      = newLabels.ElementAt(newLabelsIndex);
                int labelsCompared = comparer.Compare(existingLabel, newLabel);
                if (labelsCompared < 0)
                {
                    existingLabelsIndex++;
                }
                else if (labelsCompared > 0)
                {
                    mergedLabels.Add(newLabel);
                    newLabelsIndex++;
                }
                else
                {
                    existingLabel.ApplyModel(newLabel, informationProtectionPolicy);
                    mergedLabels.Add(existingLabel);
                    existingLabelsIndex++;
                    newLabelsIndex++;
                }
            }

            while (newLabelsIndex < newLabelsCount)
            {
                mergedLabels.Add(newLabels.ElementAt(newLabelsIndex++));
            }

            return(mergedLabels);
        }
예제 #2
0
        internal void ApplyInput(string informationType, string sensitivityLabel, InformationProtectionPolicy informationProtectionPolicy)
        {
            if (string.IsNullOrEmpty(informationType) && string.IsNullOrEmpty(sensitivityLabel))
            {
                throw new Exception("Value is not specified neither for InformationType parameter nor for SensitivityLabel parameter");
            }

            ApplyInformationType(informationType, informationProtectionPolicy);
            ApplySensitivityLabel(sensitivityLabel, informationProtectionPolicy);
        }
예제 #3
0
        public static InformationProtectionPolicy ToInformationProtectionPolicy(JToken policyToken)
        {
            InformationProtectionPolicy policy = new InformationProtectionPolicy();
            JToken propertiesToken             = policyToken["properties"];

            IDictionary <string, JToken> dictionary = (JObject)propertiesToken["informationTypes"];

            policy.InformationTypes = dictionary.ToDictionary(pair => pair.Value["displayName"].ToString(), pair => Guid.Parse(pair.Key));

            dictionary = (JObject)propertiesToken["labels"];
            policy.SensitivityLabels = dictionary.ToDictionary(
                pair => pair.Value["displayName"].ToString(),
                pair => Tuple.Create(Guid.Parse(pair.Key), (SensitivityRank)Enum.Parse(typeof(SensitivityRank), pair.Value["rank"]?.ToString())));

            return(policy);
        }
예제 #4
0
 private void ApplyInformationType(string newInformationType, InformationProtectionPolicy informationProtectionPolicy)
 {
     if (!string.IsNullOrEmpty(newInformationType) &&
         !string.Equals(InformationType, newInformationType))
     {
         if (informationProtectionPolicy.InformationTypes.TryGetValue(newInformationType, out Guid informationTypeId))
         {
             InformationType   = newInformationType;
             InformationTypeId = informationTypeId.ToString();
         }
         else
         {
             throw new Exception($"Information Type '{newInformationType}' is not part of Information Protection Policy. Please add '{newInformationType}' to the Information Protection Policy, or use one of the following: {ToString(informationProtectionPolicy.InformationTypes.Keys)}");
         }
     }
 }
예제 #5
0
 private void ApplySensitivityLabel(string newSensitivityLabel, InformationProtectionPolicy informationProtectionPolicy)
 {
     if (!string.IsNullOrEmpty(newSensitivityLabel) &&
         !string.Equals(SensitivityLabel, newSensitivityLabel))
     {
         if (informationProtectionPolicy.SensitivityLabels.TryGetValue(newSensitivityLabel, out Tuple <Guid, SensitivityRank> idRankTuple))
         {
             SensitivityLabel   = newSensitivityLabel;
             SensitivityLabelId = idRankTuple.Item1.ToString();
             Rank = idRankTuple.Item2;
         }
         else
         {
             throw new Exception($"Sensitivity Label '{newSensitivityLabel}' is not part of Information Protection Policy. Please add '{newSensitivityLabel}' to the Information Protection Policy, or use one of the following: {ToString(informationProtectionPolicy.SensitivityLabels.Keys)}");
         }
     }
 }
 internal void ApplyModel(SensitivityClassificationModel model, InformationProtectionPolicy policy)
 {
     SensitivityLabels = MergeSensitivityLabels(SensitivityLabels, model.SensitivityLabels, policy);
 }
예제 #7
0
 internal void ApplyModel(SensitivityLabelModel sensitivityLabel, InformationProtectionPolicy informationProtectionPolicy)
 {
     ApplyInput(sensitivityLabel.InformationType, sensitivityLabel.SensitivityLabel, informationProtectionPolicy);
 }