我正在 Vaadin 24 中开发一个应用程序。我有一个使用默认登录组件的登录页面。使用此登录,我想将使用重定向到调用登录页面的 url,但登录后我总是重定向到根 url。
这是我的安全配置。我假设我必须传递某种重定向标头,因为登录页面不知道原始请求来自哪里。但我找不到任何有关如何执行此操作的来源。
希望你能帮助我。
@EnableWebSecurity
@Configuration
public class SecurityConfig extends VaadinWebSecurity {
private static final Logger logger = LoggerFactory.getLogger(SecurityConfig.class);
@Override
protected void configure(HttpSecurity http) throws Exception {
logger.debug("Security Config set...");
http.authorizeHttpRequests(auth -> auth
.requestMatchers(
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/icons/*.png"),
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/img/*.png")
).permitAll()
.requestMatchers(
AntPathRequestMatcher.antMatcher(HttpMethod.GET, "/login*")
).permitAll()
)
.formLogin(formLogin ->
formLogin.successHandler(new VaadinSavedRequestAwareAuthenticationSuccessHandler()
));
super.configure(http);
setLoginView(http, LoginView.class);
}
}
正如 brunovianarezende 建议的那样,删除对
formLogin()
的调用修复了误导性的重定向。