imeshev
(Slava Imeshev)
July 5, 2024, 11:27am
1
Folks, is there a way to set Cookies upon a successful log in? I understand Vaadin sets it’s own VaadinSavedRequestAwareAuthenticationSuccessHandler, which effectively prevents setting using a custom AuthenticationSuccessHandler that could be used for accessing the servlet request to manage the cookies using httpSecurity.successHandler(…).
Tatu2
(Tatu Lund)
July 8, 2024, 11:40am
2
I have example of that in my Bookstore demo app, I am storing value to session attribute, and persisting the value to the cookie in a request handler.
In my case I have a language select in LoginView and the value is stored to cookie using this mechanism
loginInfoHeader = new H1(getTranslation(LOGIN_INFO));
loginInfoHeader.setWidth("100%");
loginInfoText = new Span(getTranslation(LOGIN_INFO_TEXT));
loginInfoText.setWidth("100%");
loginInformation.add(loginInfoHeader);
loginInformation.add(loginInfoText);
lang = new Select<>();
lang.setItems(CustomI18NProvider.locales);
lang.setItemLabelGenerator(item -> item.toString());
loginInformation.add(lang);
lang.addValueChangeListener(e -> {
if (e.isFromClient()) {
getUI().ifPresent(ui -> {
ui.getSession().setAttribute("locale",
e.getValue().getLanguage());
ui.setLocale(e.getValue());
logger.info("Changing locale to {}",
e.getValue().getLanguage());
});
}
});
imeshev
(Slava Imeshev)
July 10, 2024, 3:10pm
3
My challenge is manipulating cookies on a successful log in.
Matti
(Matti Tahvonen)
July 11, 2024, 7:48pm
4
If it is not an “httpOnly” cookie, I’d use BrowserCookie:
The commons library for Vaadin 10+. Uploads, downloads, Geolocation, forms, fieds, fluent API...
Tatu2
(Tatu Lund)
July 15, 2024, 7:01am
5
That is exactly the same use case I have in the demo app where user can select language in LoginView and I persist the value to cookie.
imeshev
(Slava Imeshev)
July 26, 2024, 12:54am
6
Understood. It looks like VaadinRequest.current()
is the way to go. Thanks!