【发布时间】:2017-05-24 17:52:21
【问题描述】:
我的前端基于 Angular 4,而我的后端基于带有 Spring Security 的 Spring Boot。 我将所有内容部署在一个 WAR 文件中。
我在 /src/main/resources 中创建了一个 static/landing 文件夹,然后将 Webpack 构建的 Angular 文件放入该文件夹中。
Angular 负责登录过程,因此我在 Spring Security 中创建了以下规则:
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Bean
public WebMvcConfigurerAdapter mappingIndex() {
return new WebMvcConfigurerAdapter() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("forward:/landing/index.html");
}
};
}
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
.addFilterBefore(new CORSFilter(),ChannelProcessingFilter.class)
.antMatchers(/"login/**").permitAll()
.anyRequest().authenticated();
不幸的是,当我尝试使用网络浏览器访问 /login 页面进行登录时,我总是收到 HTTP 状态代码 401(未经授权)。
如何实现以这种方式集成 Angular 应用程序?因为我的安全规则适用于 REST API。
【问题讨论】:
标签: spring-boot spring-security