【发布时间】:2017-12-30 12:42:01
【问题描述】:
在带有 spring-boot 的 vaadin 项目中使用 spring security 时遇到问题。所以我正在使用 PdfViewer 插件来显示 PDF 文件。但我收到以下错误消息:
error:"Not Found"
message:"No message available"
path:"/APP/PUBLISHED/pdf.worker.js"
status:404
我的 spring 安全配置如下所示:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.headers()
.defaultsDisabled()
.frameOptions().sameOrigin().and()
.csrf().disable() // Use Vaadin's CSRF protection
.authorizeRequests().antMatchers("/").permitAll()
.antMatchers("/vaadinServlet/HEARTBEAT/**").permitAll()
.antMatchers("/vaadinServlet/UIDL/**").permitAll()
.antMatchers("/vaadinServlet/APP/PUBLISHED/**").permitAll()
.antMatchers("login?debug").permitAll()
.antMatchers("/#!pwdreset/*").permitAll()
.antMatchers("/pwdreset/*").permitAll()
.and()
.authorizeRequests()
.and()
.formLogin().loginPage("/#!login").permitAll()
.and()
.logout().logoutUrl("/#!login?logout").logoutSuccessUrl("/").permitAll().and()
.sessionManagement().sessionFixation().newSession();
}
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/resources/**", "/VAADIN/**");
}
所以在 Chrome 中检查加载的文件时,我看到了一个文件夹 /vaadinServlet/APP/PUBLISHED/,里面有所有需要的文件。
在没有 Spring Security 的情况下使用插件可以正常工作,所以有人知道吗?
更新
它似乎与弹簧安全性无关,因为我在一个新的简单项目中测试插件时遇到了类似的行为。好像是spring boot的问题。
要重现此问题,您需要 (full project for download):
- 基本 Spring Boot + vaadin 应用程序框架
- 简单的PDF及以下
/webapp/files - PdfViewer add-on 在你的 pom 和 widgetset 中编译
- 下面的简单用户界面
@Theme("mytheme")
@SpringUI
@Widgetset("org.test.AppWidgetSet")
public class MyUI extends UI {
@Override
protected void init(VaadinRequest vaadinRequest) {
final VerticalLayout layout = new VerticalLayout();
String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath();
File file = new File(basepath.concat("/files/test.pdf"));
if (file.exists()) {
PdfViewer pdfViewer = new PdfViewer(file);
Label info = new Label("File was found!");
layout.addComponents(info, pdfViewer);
} else {
Label info = new Label("no file found!");
layout.addComponent(info);
}
setContent(layout);
}
}
- 在选中
Network选项卡的情况下打开 chrome 和开发人员工具,访问该应用,您应该会看到一个对pdf.worker.js的请求失败。
【问题讨论】:
-
您能否提供sscce 来重现您的问题?没什么特别的,只是产生此错误的最小 pom、UI、spring-boot 配置和启动器(主类)。我看不出您的配置有什么问题,也许您可以将所有静态资源路径移动到
configure方法中的ignore匹配器列表,但无论如何这应该不是问题。我有一个类似的设置,但我的工作正常,所以如果不复制它就很难理解(至少对我来说) -
@Morfic 我刚刚更新了我的问题,因为这似乎是 Spring Boot 的问题,与 Spring Security 无关。在创建示例时,我遇到了与我的项目中相同的错误。可能您对如何解决此问题有任何想法。
标签: java spring spring-boot spring-security vaadin