VaadinSpring UIProvider

Hi,

I am trying to get a LoginScreen. Therefore i want to map two UIs to the root path:

LoginUI = /* (this is the initial UI)
MainUI = /* (This is UI ui after successful login in)

I have a lot of problems get this to work with spring-boot:

My UIProvider is ignored!

public class MyUIProvider extends UIProvider
@Override
public Class<? extends UI> getUIClass(UIClassSelectionEvent event) {
 return VaadinSession.getCurrent().getAttribute(LoginUI.LOGIN_USER_ID) == null ? LoginUI.class : MainUI.class;

}

@Override
public UI createInstance(UICreateEvent event) {
UI instance = new LoginUI();
springHelper.getCtx().getAutowireCapableBeanFactory().autowireBean(instance);
return instance;
}
}

SprngVaadinServler

@WebServlet(value = "/*", asyncSupported = true)
@VaadinServletConfiguration(productionMode = false, ui = LoginUI.class)
public class MySpringVaadinServlet extends SpringVaadinServlet implements SessionInitListener {

private static final Logger LOG = LoggerFactory.getLogger(CustomSpringVaadinServlet.class);

@Autowired
MyUIProvider uiProvider;


@Override

public void init(ServletConfig servletConfig) throws ServletException {
super.init(servletConfig);
AutowireCapableBeanFactory ctx =
((ApplicationContext) getServletContext().getAttribute("applicationContext"))
.getAutowireCapableBeanFactory();
ctx.autowireBean(this);
}

@Override
protected void servletInitialized() throws ServletException {
getService().addSessionInitListener(this);
}

@Override
public void sessionInit(SessionInitEvent event) throws ServiceException {
event.getSession().addUIProvider(uiProvider);
}

}

Hi @eggme
What is exactly the goal?
If you’re using Spring Security, you could also use the PostSuccessfulAuthenticationHandler. This way you have still one location in which you can decide to redirect the user to the desired URL. Otherwise I would go for having the application path set in the UI as
@SpringUI(path = “/app/*”)
and map the login UI to another one like
@SpringUI(path = “/login”).
When the login goes through, then redirect to “/app/”. But I ignore how you are securing the URL’s right now in terms of authorization.
Hope it helps
Fran