【发布时间】:2020-08-19 21:47:54
【问题描述】:
这是我的安全配置
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable()
.requestCache().requestCache(new CustomRequestCache())
.and().authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().hasAnyAuthority(Role.getAllRoles())
.and().formLogin().loginPage(LOGIN_URL).permitAll()
.loginProcessingUrl(LOGIN_PROCESSING_URL)
.failureUrl(LOGIN_FAILURE_URL)
.successHandler(new SavedRequestAwareAuthenticationSuccessHandler())
.and().logout().logoutSuccessUrl(LOGOUT_SUCCESS_URL);
}
问题是当我从 / 导航到受保护的 URL 时未调用 CustomRequestCache,因此 SavedRequestAwareAuthenticationSuccessHandler 在登录后不会重定向到请求的页面。
我认为这是因为 permitAll 创建了一个匿名用户。
我必须如何配置 Spring Security 才能使 SavedRequestAwareAuthenticationSuccessHandler 工作?
【问题讨论】:
-
我尝试在没有自定义登录/注销 URL 的情况下重新创建它,它对我有用。我导航到
/,然后尝试导航到/test,这会将我重定向到登录表单。登录后,我被重定向到/test。
标签: java spring spring-boot spring-security