Hi Florian,
To unpack your edn-acls I entered these expressions in a repl. Each
expression goes one step deeper, so it is only the last expression that you
need to unpack the acls. The other steps are included to illustrate the
process.
(for [acl edn-acls]
{:acl acl})
(for [acl edn-acls
[path rep-maps] acl
rep-map rep-maps]
{:path path :rep-map rep-map})
(for [acl edn-acls
[path rep-maps] acl
rep-map rep-maps
[rep privs] rep-map]
{:path path :rep rep :privs privs})
(for [acl edn-acls
[path rep-maps] acl
rep-map rep-maps
[rep privs] rep-map
priv privs]
{:path path :rep rep :priv priv})
(for [acl edn-acls
[path rep-maps] acl
rep-map rep-maps
[rep privs] rep-map
priv privs
[jcr groups] priv]
{:path path :rep rep :jcr jcr :groups groups})
(for [acl edn-acls
[path rep-maps] acl
rep-map rep-maps
[rep privs] rep-map
priv privs
[jcr groups] priv
group groups]
{:path path :rep rep :jcr jcr :group group})
Succes with your application.
On Friday, March 7, 2014 9:44:32 AM UTC+1, Florian Salihovic wrote:
>
> I am working on my first "real" Clojure application. I started building tools
> and looking use cases for my daily work, so i would
> have a direct benefit from using Clojure. The first application would be an
> unpacking of an edn definition of access control lists
> for Apache JackRabbit. The edn-acls vector represents such lists.
>
> Privileges (:privilege i.e. "jcr:read", "jcr:all") to a path (:path i.e.
> "/content") can be granted or denied (:primaryType "rep:GrantACE",
> "rep:DenyACE") for principals (:principalName i.e. "admin"
> "workflow-editors").
>
> I am currently stuck at the following questions:
>
> 1. How to (efficiently - that would be ) accumulate the data. It seems
> like i am not getting the data returned from unpack-aces-for-path into a list
> or vector. I tried to pass an accumulator to edn-acl-unpack but that didn't
> work out.
> 2. There are a bunch of zip methods already available, but i didn't find
> one which transforms a list/vector from a map {"jcr:read" ["anonymous"
> "workflow-users"] into [["jcr:read" "anonymous"] ["jcr:read"
> "workflow-users"]]. I didn't find an implementation in core, but i wonder if
> there was something like that already.
> 3. Getting more idiomatic ...
>
> The code ...
>
> (def edn-acls [{"/content"
> [{"rep:GrantACE"
> [{"jcr:read" ["anonymous" "workflow-users"]}
> {"jcr:all" ["admin" "workflow-editors"]}]}]}
> {"/etc"
> [{"rep:DenyACE"
> [{"jcr:all" ["anonymous" "workflow-users"]}]}
> {"rep:GrantACE"
> [{"jcr:read" ["anonymous" "workflow-users"]}]}
> {"rep:GrantACE"
> [{"jcr:all" ["admin" "workflow-editors"]}]}]}])
> (defn map-privileges-to-principals
> [primary-type
> privileges]
> (for [privilege-for-principals privileges
> [privilege principals] privilege-for-principals]
> (for [principal principals]
> (hash-map :primaryType primary-type
> :privilege privilege
> :principalName principal))))
> (defn unpack-aces
> [aces]
> (flatten
> (for [ace aces]
> (for [[primary-type privileges] ace]
> (map-privileges-to-principals primary-type privileges)))))
> (defn unpack-aces-for-path
> [aces-for-path]
> (for [[path aces] aces-for-path]
> (hash-map :path path
> :acls (unpack-aces aces))))
> (defn edn-acl-unpack
> [policies]
> (let [head (first policies)
> tail (rest policies)]
> (when (not (empty? head))
> (let [entry (unpack-aces-for-path head)]
> (when (not (empty? tail))
> (recur tail))))))
> (edn-acl-unpack edn-acls)
>
>
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.