我启动了Spring Boot Angular应用程序,现在我想将整个东西部署为jar . 所以我创建了maven配置,在其中构建了角度应用程序,然后将其复制到/ target / classes / resources
但是每个root用户请求(localhost:8080)都会被安全性阻止 . 当我禁用它时,我可以看到页面,这意味着整个事情已正确部署,但不知何故 Spring 天不允许我看到它 . 这是我简单的安全配置,我希望静态资源不受保护,而任何其他请求都需要身份验证:
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll()
.anyRequest().authenticated()
.and().httpBasic();
}
}
编辑:我的问题的一个最小的例子是:https://gitlab.com/jnowacki/security-issue-demo
编辑2:我尝试了这篇文章中的所有内容:Serving static web resources in Spring Boot & Spring Security application我是否在概念层面做错了什么?与Spring Boot应用程序一起提供静态内容是不对的?
4 回答
试试下面 .
参考spring-securitys-antmatcher
添加此额外覆盖:
其中
AUTH_WHITELIST
将包含要忽略的路径 . 例如:根据
StaticResourceLocation
docs:将允许访问CSS,JS,ICO,图像和 NOT to html .
要允许
index.html
,您可以使用以下配置:使用此方法可以允许Spring安全性忽略静态资源