spring
spring copied to clipboard
Vaadin UI in spring boot management port
I want to create UI for admin on management port for security reason, and I create a custom UI and implement MvcEndpoint interface as following code:
@SpringUI(path = "/index")
@Title("Vaadin Demo")
@Theme("valo")
public class MyVaadinUI extends UI implements MvcEndpoint
After startup, "Caused by: java.lang.IllegalStateException: No VaadinSession bound to current thread" thrown. Any plan to fix this problem.
Hi! Do you have the project available somewhere for testing?
Hi Samie, yes, now I use server.port for end user through Nginx, and management.port for admin because of security protection, and I don't want the end user to access the admin UI. I use Vaadin to build admin UI, and you know it's very easy to build admin UI with Vaadin. I want to access Vaadin UI from the management port.
I created a demo at https://github.com/linux-china/vaadin-demo please take a look at AdminVaadinUI class, and I really want to use Vaadin UI through management port and enjoy some admin operations.
Excellent, we'll take a look
I'm afraid we have not really tried this in the past. I did give your sample project a spin and tried to dig a bit into how Spring Boot handles MvcEndpoints.
First some background:
Vaadin itself isn't Spring MVC based. However, a ServletForwardingController is normally used by the auto-configuration in vaadin-spring-boot to forward requests made for the root of a UI, whereas internally a Vaadin servlet is mapped to another path. The generated UI bootstrap javascript for the main page is set up to make any internal requests directly to the servlet.
As for the approach you tried to make an admin UI visible at the management port, there are a few problems at the moment:
- The UI scope that is normally used for @SpringUI isn't available yet when the system looks for MvcEndpoint beans.
- You can get around this by making the endpoint a separate bean in your configuration. Similar issues can also occur when certain Spring MVC beans are used as the endpoint implementation (I believe that e.g. implementing MvcEndpoint in a Controller class can lead to duplicate mappings).
- The real Vaadin servlet is only mapped to the main port in Vaadin Spring auto-configuration.
- You could duplicate the appropriate parts of the servlet configuration and perhaps register another servlet instance at a suitable path on the management port. I haven't tried this yet and I'm not sure how to register the servlet at that port, but can try to dig into this.
- Finally, the mappings made by VaadinServletConfiguration (vaadin-spring-boot auto-configuration) do not take into account any MvcEndpoint mappings but in this case seem to add the admin UI mapping also for the main servlet.
- I'm not sure if Spring MVC and ServletForwardingController should normally take care of this, but they don't seem to do so at least without any customization.
I can try to dig deeper and perhaps make an example on how to achieve what you want, and then make a feature request about making this easy in Vaadin Spring.
Hi, I made a prototype based on https://github.com/linux-china/vaadin-demo, not well-tested, not analyzed for security, but it looks working. https://github.com/elmot/vaadin-demo
@elmot yes, it works. Could your guys make it simple? Such as a new annotation or implement VaadinMvcEndpoint, scan these UI Components and make them automatically wired. :)
@linux-china, now it's in our backlog https://dev.vaadin.com/ticket/19246#ticket
any idea to integration https://github.com/spring-cloud/spring-cloud-netflix/blob/master/spring-cloud-netflix-core/src/main/java/org/springframework/cloud/netflix/endpoint/ServletWrappingEndpoint.java to make UI on management port?