Spring Boot Security + GWT,静态资源访问403错误

时间:2017-07-23 08:29:24

标签: spring gwt

我在gwt + spring安全简单应用程序中与css / js访问问题作斗争。所以,我有下一个方法的secutiy控制器:

@GetMapping(value = "/notes")
public ModelAndView index(ModelAndView modelAndView) {
    modelAndView.setViewName(VIEW_NOTES);
    return modelAndView;
}

顺便说一句,我根据这个article整合了这些技术。所以,多亏了这个控制器方法(我使用 RestController ),我们已经解析了视图(简单为****):

<!DOCTYPE html>
<html lang="en">
<head>
<title>Notes</title>
<link rel="stylesheet" type="text/css" media="all" 
href="../static/css/notes-main.css"></link>
</head>
<body>
<!-- This script tag is what actually loads the GWT module.  The -->
<!-- 'nocache.js' file (also called a "selection script") is     -->
<!-- produced by the GWT compiler in the module output directory -->
<!-- or generated automatically in development mode.             -->
<script language="javascript" src="notesgwtapp/notesgwtapp.nocache.js">
</script>
<!-- Include a history iframe to enable full GWT history support -->
<!-- (the id must be exactly as shown)                           -->
<iframe src="javascript:''" id="__gwt_historyFrame" 
style="width:0;height:0;border:0"></iframe>
<div id="notes"></div>
</body>
</html>

现在最有趣的是我有这两个错误: 获得http://localhost:8080/static/css/notes-main.css 403 获取http://localhost:8080/notesgwtapp/notesgwtapp.nocache.js 403

我没有解决其他视图的资源问题,顺便说一下。 请帮忙,我该怎么处理?如果我错过了一些重要的代码,我会添加它。请问。提前谢谢。

1 个答案:

答案 0 :(得分:1)

默认情况下,Sprint Boot允许对/js/**/css/**/images/**的所有访问权限。但是您尝试访问/static/**/notesgwtapp/**,这将导致403错误(请参阅here)。

有两种解决方案:

  1. 确保notesgwtapp.nocache.jsnotes-main.css文件最终位于上述某个文件夹中或
  2. 覆盖Spring Boot应用的SecurityConfig,并将/static/**/notesgwtapp/**文件夹添加到允许的位置。