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 clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
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 clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to