我试图公开一个REST-GET端点,它允许下载如下所示的文件。
@RequestMapping(value="/downloadFile", method = RequestMethod.GET)
@ResponseBody
public void downloadResource(HttpServletResponse response, @RequestParam("fileName") String name) {
downloadService.flushFile(response, name);
}
当前安全配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests().antMatchers("/", "/v1/**").permitAll()
.anyRequest().rememberMe();
http.httpBasic();
}
问题:
:如何启用硬编码令牌,以便客户端javascript可以在它发送的每个请求中包含它?
当前在调用GET服务时没有传递安全令牌。
window.open("http://localhost:8080/DownloadMS/v1/downloadFile?fileName=abc_test");
我试过在调用GET服务时使用用户名和密码,如下所示。这可能是不好的,因为在页面检查时可以清楚地看到密码(在所有浏览器中)。
window.open("http://username:password@localhost:8080/DownloadMS/v1/downloadFile?fileName=abc_test");