In Grails 2.x, to allow following symbolic links, we can add following in the scripts/_Events.groovy
:
eventConfigureTomcat = { tomcat ->
def ctx = tomcat.host.findChild("")
ctx.allowLinking = true // Follow soft links
}
How can we achieve the same in Grails 3? I've tried creating the same script file in src/main/scripts
directory in Grails 3 but didn't help.
Edit:
I also tried adding following line in Bootstrap.groovy
:
Holders.getServletContext().allowLinking = true
GitHub issue #10045
Finally, I've figured out the solution for following symbolic link in Grails 3 with the help of examples provided by graemerocher.
You just need to add the following to your ./grails-app/init/<package>/Application.groovy
:
@Bean
EmbeddedServletContainerFactory containerFactory() {
TomcatEmbeddedServletContainerFactory containerFactory = new TomcatEmbeddedServletContainerFactory()
containerFactory.addContextCustomizers(new TomcatContextCustomizer() {
@Override
void customize(Context context) {
StandardRoot root = new StandardRoot(context)
root.setAllowLinking(true)
context.setResources(root)
}
});
return containerFactory
}
Packages to import:
import org.apache.catalina.Context
import org.apache.catalina.webresources.StandardRoot
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
import org.springframework.context.annotation.Bean