Created
December 16, 2008 01:48
-
-
Save hiredman/36217 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; need a java policy file that allows all or enabling the security manager will | |
;; lock you out | |
;; | |
;; grant { | |
;; permission java.security.AllPermission; | |
;; }; | |
(System/setSecurityManager (SecurityManager.)) | |
(defn sandbox [func] | |
(let [perms (java.security.Permissions.) | |
domain (java.security.ProtectionDomain. | |
(java.security.CodeSource. nil | |
(cast java.security.cert.Certificate nil)) | |
perms) | |
context (java.security.AccessControlContext. (into-array [domain])) | |
pA (proxy [java.security.PrivilegedAction] [] (run [] (func)))] | |
(java.security.AccessController/doPrivileged | |
pA context))) | |
;; this fails | |
(sandbox | |
#(doto (-> "foo.bar" java.io.File. java.io.FileWriter.) (.write "foo") .close)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment