Guest User

Untitled

a guest
Feb 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. ;; need a java policy file that allows all or enabling the security manager will
  2. ;; lock you out
  3. ;;
  4. ;; grant {
  5. ;; permission java.security.AllPermission;
  6. ;; };
  7.  
  8.  
  9. (System/setSecurityManager (SecurityManager.))
  10.  
  11. (defn sandbox [func]
  12. (let [perms (java.security.Permissions.)
  13. domain (java.security.ProtectionDomain.
  14. (java.security.CodeSource. nil
  15. (cast java.security.cert.Certificate nil))
  16. perms)
  17. context (java.security.AccessControlContext. (into-array [domain]))
  18. pA (proxy [java.security.PrivilegedAction] [] (run [] (func)))]
  19. (java.security.AccessController/doPrivileged
  20. pA context)))
  21.  
  22. ;; this fails
  23. (sandbox
  24. #(doto (-> "foo.bar" java.io.File. java.io.FileWriter.) (.write "foo") .close))
Add Comment
Please, Sign In to add comment