【发布时间】:2019-05-05 23:58:14
【问题描述】:
我启动了 Spring Boot + Angular 应用程序,现在我想将整个东西部署为一个 jar。所以我创建了 maven 配置,其中 Angular 应用程序被构建,然后被复制到 /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 应用程序一起提供是错误的吗?
【问题讨论】:
-
@dur 我用最小的例子添加了一个回购链接。我需要在没有任何身份验证的情况下提供索引,以及身份验证后的任何其他请求。我知道我可以允许所有人,然后在例如之后确保某些路径/api 但这不是重点。
-
你的问题不清楚。如果您想允许所有 URL
/,那么您必须将该 URL 添加到您的配置中。 -
@dur 当我按如下方式配置它时:
http.authorizeRequests() .antMatchers("/").permitAll() .requestMatchers(PathRequest.toStaticResources().atCommonLocations()).permitAll() .anyRequest().authenticated() .and().httpBasic();index.html 是允许的,但对 css 的请求要求提供凭据。
标签: java spring angular spring-boot spring-security