Configuring security policy for FreeMarker
When FreeMarker is used in a Java virtual machine with a security manager installed, you have to grant it few permissions to ensure it operates properly. Most notably, you need these entries to your security policy file for freemarker.jar:
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
![](images/none.gif) |
grant codeBase "file:/path/to/freemarker.jar"
{
permission java.util.PropertyPermission "file.encoding", "read";
permission java.util.PropertyPermission "freemarker.*", "read";
} |
| ![](images/none.gif) |
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
Additionaly, if you are loading templates from a directory, you need to give FreeMarker permissions to read files from that directory using the following permission:
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
![](images/none.gif) |
grant codeBase "file:/path/to/freemarker.jar"
{
...
permission java.io.FilePermission "/path/to/templates/-", "read";
} |
| ![](images/none.gif) |
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
Finally, if you're just using the default template loading mechanism which loads templates from the current directory, then specify these permissions additionally: (note that the expression ${user.dir} will be evaluated at run time by the policy interpreter, pretty much as if it were a FreeMarker template)
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
![](images/none.gif) |
grant codeBase "file:/path/to/freemarker.jar"
{
...
permission java.util.PropertyPermission "user.dir", "read";
permission java.io.FilePermission "${user.dir}/-", "read";
} |
| ![](images/none.gif) |
![](images/none.gif) | ![](images/none.gif) | ![](images/none.gif) |
Naturally, if you're running under Windows, use double backslash instead of a single slash for separating directory components in paths.