How to secure access to static resources in Spring
spring, spring-mvc, spring-security
Solution
If you are using Spring Security you could add something like this to your Spring context file(s):
<sec:intercept-url pattern="/img_resources/**" access="isAuthenticated()" />
Problem
I am serving images from a folder outside a web application. I stored images inside C:\source\Pictures. I configured this resource as a static resource in spring's servlet context file: ``` <resources location="file:///C:/source/Pictures/" mapping="/img_resources/**"/> ``` I display images stored in that folder using ``` <img src="<spring:url value='/img_resources/guinnes_choc_cake.jpg/'/>"></img> ``` It work well for me. However, I have security concerns. I would not want to expose a directory in my server to the public.1 Is there a way to built security around this folder in Spring ?