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

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

@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("/");

}

回答:

您可以使用custom AuthenticationSuccessHandler并将其设置useReferertrue

@Bean

public AuthenticationSuccessHandler successHandler() {

SimpleUrlAuthenticationSuccessHandler handler = new SimpleUrlAuthenticationSuccessHandler();

handler.setUseReferer(true);

return handler;

}

在你的configure方法中:

http

.formLogin()

.loginPage("/login")

.successHandler(successHandler())

.permitAll()

.and()

以上是 成功登录后,Spring Boot重定向到当前页面 的全部内容, 来源链接: utcz.com/qa/433278.html

回到顶部