PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/GeneralPDP/Scenario/XacmlToDkalEndPoint.fs

#
F# | 100 lines | 80 code | 17 blank | 3 comment | 5 complexity | 3e4e4cf22bd9a808df14743091b51f2a MD5 | raw file
Possible License(s): Apache-2.0, GPL-3.0, LGPL-3.0, BSD-3-Clause
  1. namespace Microsoft.Research.GeneralPDP.Scenario
  2. open Microsoft.Research.GeneralPDP.XACML.Ast
  3. open Microsoft.Research.GeneralPDP.XACML.PDP.Engine
  4. open Microsoft.Research.GeneralPDP.Translations.ToDKAL.XacmlPolicyTranslator
  5. open Microsoft.Research.GeneralPDP.Translations.ToDKAL.XacmlRequestTranslator
  6. open Microsoft.Research.GeneralPDP.Translations.ToXACML.DkalResponseTranslator
  7. open Microsoft.Research.GeneralPDP.Translations.ToDKAL.Crawlers
  8. open Microsoft.Research.GeneralPDP.DKAL.Engine.ParsingCtxFactory
  9. open Microsoft.Research.DkalEngine.Ast
  10. open Microsoft.Research.DkalEngine.Util
  11. open Microsoft.Research.DkalEngine
  12. open Message
  13. open Basics
  14. open EndPoint
  15. open EndPointImageFactory
  16. open RequestInfo
  17. open Microsoft.Msagl.Drawing
  18. open System.Drawing
  19. open System.Collections.Generic
  20. module XacmlToDkalEndPoint =
  21. type XacmlToDkalEndPoint(id: EndPointId, dkalId: EndPointId, pctx: ParsingCtx) =
  22. inherit EndPoint(id)
  23. let attributesNeeded = new HashSet<AttributeDesignator>()
  24. let mutable nextRequestId = 3000
  25. let pendingRequests = new Dictionary<int, EndPointId * int>()
  26. let ppalMe = pctx.LookupOrAddPrincipal(id)
  27. let ppalDkal = pctx.LookupOrAddPrincipal(dkalId)
  28. // determines if policy translation is done to rules or to infons
  29. let mutable translateToRules = false
  30. member ep.TranslateToRules with get() = translateToRules and set (t) = translateToRules <- t
  31. override ep.Process(m: IMessage) =
  32. match m.Content with
  33. | XacmlRequestContent(req) ->
  34. ep.SendRequestToDkal(nextRequestId, req)
  35. pendingRequests.[nextRequestId] <- (m.Sender, req.Id)
  36. nextRequestId <- nextRequestId + 1
  37. | XacmlPolicyContent(pcy) ->
  38. attributesNeeded.Clear()
  39. attributesNeeded.UnionWith(attributesInPolicy pcy)
  40. ep.InstallPolicyOnDkal(pcy)
  41. | InfonContent(infon) ->
  42. let tr = DkalResponseTranslator()
  43. let pep, response = tr.TranslateResponse(infon)
  44. let found, t = pendingRequests.TryGetValue(response.Id)
  45. if pep <> id || not found then
  46. failwith (ep.Id + ": I received a response from DKAL to a request I didn't make")
  47. let reqSender, origId = t in
  48. pendingRequests.Remove(response.Id) |> ignore
  49. // adjust local request to original request number
  50. let response = ResponseContext(origId, response.Decision, response.Status, response.Obligations)
  51. ep.Send({sender= id;
  52. receiver= reqSender;
  53. content= XacmlResponseContent (response)})
  54. | _ -> "I don't understand content " + m.Content.ToString() |> ep.Fail
  55. override ep.StartUp() = ()
  56. override ep.CleanUp() = ()
  57. override ep.Image = Some (image (ep :> IEndPoint).Color EmptyDrawing)
  58. override ep.ApplyStyle (n: Node) =
  59. n.LabelText <- ep.Description
  60. member private ep.SendRequestToDkal (reqId: int, req: RequestContext) =
  61. let tr = XacmlRequestTranslator(pctx)
  62. let req = RequestContext(reqId, req.Attributes)
  63. let infon = tr.TranslateRequest id req attributesNeeded
  64. ep.Send({sender= ep.Id;
  65. receiver= dkalId;
  66. content= InfonContent(infon)})
  67. member private ep.InstallPolicyOnDkal (p: Policy) =
  68. let tr = XacmlPolicyTranslator(dkalId, id, pctx)
  69. // translate to rules or infons depending on setting
  70. if translateToRules then
  71. let dPolicy = tr.TranslatePolicyToCommRules p
  72. ep.Send({sender= ep.Id;
  73. receiver= dkalId;
  74. content= DkalPolicyContent(dPolicy)})
  75. else
  76. let infons = tr.TranslatePolicyToInfons p
  77. for infon in infons do
  78. let signature = App(pctx.LookupFunction("Ev.signedBy"), [Const(Principal(ppalMe)); infon; Const(Int(42))])
  79. let justified = App(pctx.LookupFunction("justified"), [infon; signature])
  80. ep.Send({sender= ep.Id;
  81. receiver= dkalId;
  82. content= InfonContent(justified)})
  83. override ep.Description = ep.Id + ": XACML->DKAL"