i cant find a way to get HttpServletRequest con my Vaadin 7.0.5 Application. There is a way to do that?? I need to grab a com.sun.security.auth.UserPrincipal and cant find a way to do that without HttpServletRequest.
Note that this method will work only if your code doesn’t need any Vaadin-isms and can rely on pure servlet code. It would be really helpful if there were some sort of callback to process a request after Vaadin has set up all of its threadlocals, but before it’s processed the specific request. We’d like to be able to call on VaadinSession.getCurrent().getUIs(), but it won’t work because if you put code before super.service(), it won’t be set up yet, and if put code after, the vaadin session info will have been cleared.
I’m trying to use VaadinServlet too. I’m able to grab UserPrincipal and redirect too my UI after that. Now i need a way to pass data from VaadinServlet to UI.
Maybe the changes in 7.1 will make this easier (see https://vaadin.com/forum#!/thread/3209316), but our hack for now is in our UI.init() we set a session attribute that represents our UI (we only have one per session AFAIK):
Of course you want to check that you have the attribute before you set anything as the service() method is called before your UI.init() will have been called to set it.
Use the service() method to override determining the a login is required and needs a redirect.
But instead of storing the UI instance in the session, just override the servletInitialized() method in you subclassed VaadinServlet, too, since you get then get UI, VaadinService, etc. at this point. It will then allow you to call your UI as needed. In our case, we use it twice, once to tell our application about a new request (we track user, IP, date/time etc), and also to configure system messages to our liking.
@Override
protected void servletInitialized() throws ServletException {
super.servletInitialized();
EsfVaadinUI ui = (EsfVaadinUI)UI.getCurrent();
if ( ui != null ) {
ui.setHttpRequest(VaadinService.getCurrentRequest());
}
getService().setSystemMessagesProvider(
new SystemMessagesProvider() {
private static final long serialVersionUID = 5776072298071825406L;
@Override
public SystemMessages getSystemMessages(SystemMessagesInfo systemMessagesInfo) {
CustomizedSystemMessages messages = new CustomizedSystemMessages();
EsfVaadinUI ui = (EsfVaadinUI)UI.getCurrent();
if ( ui != null ) {
ui.setCustomizedSystemMessages(messages);
}
return messages;
}
});
}
i will try this way too. But maybe it’s little different to what i need. I dont intialize UI first. So if i try to use VaadinSession in VadinServlet i have NullPointerException.
Done it with some triks, i dont know if this is the best way.
Or authentication system send username to LoginServlet (extend VaadinServlet). LogintServlet add the username in the session and redirect to our UI. In the UI i get username with: