【发布时间】:2021-05-28 02:22:14
【问题描述】:
大家好,我是 spring boot 和 react 的新手,我正在开发简单的登录应用程序使用 react js 和 spring boot, 每当我尝试导航到不同的 API 调用(例如注销、欢迎)时,我都会收到以下消息 无法使用属性 [authenticated] 授权过滤器调用 [GET /welcome] 我认为这与 WebSecurityConfigurerAdapter 有关 寻找合适的解决方案
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable().sessionManagement().sessionFixation().migrateSession().and()
//.addFilterAfter(new AuthenticationFilter(), UsernamePasswordAuthenticationFilter.class).csrf().disable()
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and().formLogin().loginPage("/login").and()
.logout()
.logoutUrl("/logout").invalidateHttpSession(true).deleteCookies().clearAuthentication(true)
.permitAll()
.and()
.exceptionHandling().accessDeniedPage("/403").and().httpBasic();
}
handleDashboard() {
axios.get("http://localhost:8080/welcome",{ withCredentials: true }).then(res => {
if (res.data === "success") {
this.props.history.push("/");
} else {
alert("Authentication failure");
}
});
}
【问题讨论】:
标签: reactjs spring spring-boot servlets spring-security