spring icon indicating copy to clipboard operation
spring copied to clipboard

Vaadin UI in spring boot management port

Open linux-china opened this issue 8 years ago • 9 comments

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.

linux-china avatar Nov 02 '15 09:11 linux-china

Hi! Do you have the project available somewhere for testing?

samie avatar Nov 02 '15 09:11 samie

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.

linux-china avatar Nov 02 '15 10:11 linux-china

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.

linux-china avatar Nov 02 '15 10:11 linux-china

Excellent, we'll take a look

samie avatar Nov 02 '15 10:11 samie

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.

hesara avatar Nov 02 '15 13:11 hesara

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 avatar Nov 09 '15 12:11 elmot

@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 avatar Nov 10 '15 04:11 linux-china

@linux-china, now it's in our backlog https://dev.vaadin.com/ticket/19246#ticket

elmot avatar Nov 10 '15 14:11 elmot

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?

linux-china avatar Dec 06 '16 01:12 linux-china