ExecutionStateImplementation.cs 4.4 KB

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