我正在尝试使用create-react-app启动我的spring-boot项目的前端。
我使用redis来存储会话。
由于某些原因,我实际上需要为匿名用户启用会话生成。
以下代码是我用于春季启动的安全性配置:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
//@formatter:off
http
.formLogin()
.loginPage("/login")
.permitAll()
.loginProcessingUrl("/form-login")
.and()
.cors()
.and()
.csrf()
.disable()
.authorizeRequests()
.antMatchers("/restricted/**")
.authenticated()
.antMatchers("/**")
.permitAll()
.and()
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.ALWAYS);
//@formatter:on
}
}
我已经通过在spring-boot项目下的“ static”文件夹中有一个非常简单的index.html进行了测试。然后我转到“ http:// localhost:8080 ”,然后看到了会话cookie。
然后,我删除了“ index.html”文件,并使用代理配置启动react应用。默认情况下,新的URL为“ http:// localhost:3000 ”。我确实看到了默认的reactjs启动页面,但是我再也没有得到任何会话cookie。
我的create-react-app在“ package.json”中的代理设置如下:
"proxy": "http://localhost:8080"
我还测试了仅当我直接转到“ http:// localhost:8080 ”而不是端口3000时,仍然可以获取会话cookie 。
任何帮助表示赞赏。提前非常感谢。
Cats萌萌
相关分类