gpt4 book ai didi

Spring Boot 登录成功后重定向到当前页面

转载 作者:IT老高 更新时间:2023-10-28 13:44:55 26 4
gpt4 key购买 nike

我在模式窗口中有登录表单。成功登录后,用户被重定向到 / 页面。我正在尝试找到一种在登录后留在联系页面或其他页面上的方法。这个怎么做?我的代码是:

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**","/js/**","/fonts/**","/images/**","/home","/","/kontakt").permitAll()
.antMatchers("/userlist").hasRole("ADMIN")
.anyRequest().authenticated();
http
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/");
}

最佳答案

您可以使用自定义 AuthenticationSuccessHandler 并将 useReferer 设置为 true

@Bean
public AuthenticationSuccessHandler successHandler() {
SimpleUrlAuthenticationSuccessHandler handler = new SimpleUrlAuthenticationSuccessHandler();
handler.setUseReferer(true);
return handler;
}

在你的 configure 方法中:

http
.formLogin()
.loginPage("/login")
.successHandler(successHandler())
.permitAll()
.and()

关于Spring Boot 登录成功后重定向到当前页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26833452/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com