我正在尝试让Spring Security允许用户从服务器下载一些静态文件,但是,我可以看到它对JS,CSS和图像文件的作用。
当我尝试从同一个文件夹中获取文件.msi或.pkg时,spring security会向我显示404页面。
有人知道如何防止这种或我在这里缺少哪种配置?
我已经覆盖了如下配置方法,但它不适用于.msi和.pgk文件
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**");
web.ignoring().antMatchers("/resources/**.msi");
web.ignoring().antMatchers("/resources/**.pkg");
}
更新
我正在尝试访问https://dev.server.com/app/resources/dummy/installers/XYZ.msi,当我访问以下https://dev.server.com/app/resources/dummy/css/main.css时,我没有任何问题。
对我来说,它可能是与SimpleUrlHandlerMapping有关的东西,我不知道如何为.msi或.pkg文件添加映射,因为我看到'资源'下的所有文件都暴露但它必须是比如js,css和images。
这是应用程序启动时的日志:
2017-02-23 17:44:37.178 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.js] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.178 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.css] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.179 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.png] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.179 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.ico] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.180 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.gif] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.180 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.jpg] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.181 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.ttf] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.181 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.woff] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2017-02-23 17:44:37.182 INFO 10948 --- [localhost-startStop-1] SimpleUrlHandlerMapping(registerHandler:354) : Mapped URL path [/resources/**/*.woff2] onto handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
答案 0 :(得分:0)
在找到多个解决方案之后,我发现我需要添加扩展覆盖' addResourceHandler',请检查以下方法
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**/*.js", "/resources/**/*.css", "/resources/**/*.png",
"/resources/**/*.ico", "/resources/**/*.gif", "/resources/**/*.jpg", "/resources/**/*.ttf",
"/resources/**/*.woff", "/resources/**/*.woff2", "/resources/**/*.msi", "/resources/**/*.pkg").addResourceLocations("/resources/");
}