Проблема возникает, когда пользователь выходит из системы. Если они попытаются войти снова, вместо того, чтобы быть перенаправленными на страницу входа в GitLab и просить ввести свои учетные данные, они будут возвращены прямо на домашнюю страницу без необходимости повторного входа в систему. Мне нужно приложение, которое заставит пользователя пройти повторную аутентификацию в GitLab после выхода из системы.
Моя первая попытка выглядит так:
Код: Выделить всё
@Configuration
public class SecurityConfig extends VaadinWebSecurity {
@Override
public void configure (HttpSecurity http) throws Exception {
http.authorizeHttpRequests(auth ->{
auth.requestMatchers("/login").permitAll();
auth.requestMatchers("/register").permitAll();
auth.requestMatchers("/oauth2/**").permitAll();
})
.csrf(csrf -> {
csrf.disable();
})
.oauth2Login(o2 ->{
o2.loginPage("/login");
o2.successHandler(new SimpleUrlAuthenticationSuccessHandler("/home"));
})
.logout(logout -> logout
.logoutUrl("/logout")
.logoutSuccessUrl("/")
.invalidateHttpSession(true)
.clearAuthentication(true)
.addLogoutHandler(new SecurityContextLogoutHandler()));
super.configure(http);
}
}
Код: Выделить всё
Icon icon = new Icon("vaadin", "power-off");
icon.setColor("white");
Anchor anchor = new Anchor("/logout", icon);
anchor.setRouterIgnore(true);
Затем я попытался выйти из системы «вручную», добавив контроллер, который выглядит так: это:
Код: Выделить всё
@Controller
public class AppController{
@RequestMapping("/logout")
public void exit(HttpServletRequest request, HttpServletResponse response) {
new SecurityContextLogoutHandler().logout(request, null, null);
try {
response.sendRedirect(request.getHeader("referer"));
} catch (IOException e) {
e.printStackTrace();
}
}
}
Есть предложения?
Подробнее здесь: https://stackoverflow.com/questions/790 ... pring-boot
Мобильная версия