ExecutionStateImplementation.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. using System.Collections.Generic;
  2. using Microsoft.InformationProtection;
  3. using Microsoft.InformationProtection.Policy;
  4. using Microsoft.InformationProtection.Policy.Actions;
  5. namespace AipGateway.AIP
  6. {
  7. public struct ExecutionStateOptions
  8. {
  9. //public List<KeyValuePair<string, string>> metadata;
  10. public Dictionary<string, string> metadata;
  11. public Microsoft.InformationProtection.Label newLabel;
  12. public string contentIdentifier;
  13. public ActionSource actionSource;
  14. public DataState dataState;
  15. public AssignmentMethod assignmentMethod;
  16. public bool isDowngradeJustified;
  17. public string templateId;
  18. public string contentFormat;
  19. //public ActionType supportedActions;
  20. public bool generateAuditEvent;
  21. public string downgradeJustification;
  22. }
  23. internal class ExecutionStateImplementation : ExecutionState
  24. {
  25. private ExecutionStateOptions _executionStateOptions;
  26. public ExecutionStateImplementation(ExecutionStateOptions executionStateOptions)
  27. {
  28. _executionStateOptions = executionStateOptions;
  29. }
  30. public override string GetContentFormat()
  31. {
  32. return _executionStateOptions.contentFormat;
  33. }
  34. public override string GetContentIdentifier()
  35. {
  36. return _executionStateOptions.contentIdentifier;
  37. }
  38. public override List<MetadataEntry> GetContentMetadata(List<string> names, List<string> namePrefixes)
  39. {
  40. Dictionary<string, string> filteredMetadata = new Dictionary<string, string>();
  41. foreach (var namePrefix in namePrefixes)
  42. {
  43. foreach (var prop in _executionStateOptions.metadata)
  44. {
  45. if (prop.Key.StartsWith(namePrefix))
  46. {
  47. filteredMetadata.Add(prop.Key, prop.Value);
  48. }
  49. }
  50. }
  51. foreach (var name in names)
  52. {
  53. string value = string.Empty;
  54. var itName = _executionStateOptions.metadata.TryGetValue(name, out value);
  55. if (value != null)
  56. {
  57. filteredMetadata.Add(name, value);
  58. }
  59. }
  60. List<MetadataEntry> result = new List<MetadataEntry>();
  61. foreach (var item in filteredMetadata)
  62. {
  63. result.Add(new MetadataEntry(item.Key, item.Value, new MetadataVersion(0, MetadataVersionFormat.DEFAULT)));
  64. }
  65. return result;
  66. }
  67. public override Microsoft.InformationProtection.Label GetNewLabel()
  68. {
  69. return _executionStateOptions.newLabel;
  70. }
  71. public override AssignmentMethod GetNewLabelAssignmentMethod()
  72. {
  73. return _executionStateOptions.assignmentMethod;
  74. }
  75. public override ProtectionDescriptor GetProtectionDescriptor()
  76. {
  77. return new ProtectionDescriptor(_executionStateOptions.templateId);
  78. }
  79. /// <summary>
  80. /// The UPE SDK will always notify client of 'JUSTIFY', 'METADATA', and 'REMOVE*' actions. However an application can
  81. /// choose not to support specific actions that may appear in a policy. (For instance, A policy may define a label to
  82. /// require both protection and a watermark, bcut the application could decide not to support watermarks by not
  83. /// including ADD_WATERMARK here. If that were the case, 'mip::PolicyEngine::ComputeActions' would never return
  84. /// AddWatermark actions.)
  85. /// </summary>
  86. /// <returns></returns>
  87. public override ActionType GetSupportedActions()
  88. {
  89. return ActionType.Metadata |
  90. ActionType.Custom |
  91. ActionType.ProtectAdhoc |
  92. ActionType.ProtectByTemplate |
  93. ActionType.ProtectDoNotForward |
  94. ActionType.RemoveProtection |
  95. ActionType.Justify |
  96. ActionType.RecommendLabel |
  97. ActionType.ApplyLabel;
  98. }
  99. public override bool IsDowngradeJustified(out string justificationMessage)
  100. {
  101. justificationMessage = _executionStateOptions.downgradeJustification;
  102. return _executionStateOptions.isDowngradeJustified;
  103. }
  104. }
  105. }