Embedded Jetty doesn't recognise Spring MVC Security

后端 未结 1 2035
[愿得一人]
[愿得一人] 2021-02-06 13:36

I am developing a Spring application that starts an embedded Jetty Server. It then \"deploys\" a Spring MVC web app to this Jetty server.

All is working well with multip

相关标签:
1条回答
  • 2021-02-06 13:51

    Okay, so what I missed is that I need to add Spring's DelegatingFilterProxy to Jetty's ServletContextHandler. The usual Spring way is to extend AbstractSecurityWebApplicationInitializer, which will add the Filter Proxy. This unfortunately also didn't work with Jetty.

    One can add the Filter Proxy manually to Jetty, though, with a call explained in this comment:

    import static org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer.DEFAULT_FILTER_NAME;
    ...
    ServletContextHandler contextHandler = new ServletContextHandler();
    ...
    contextHandler.addFilter(
        new FilterHolder( new DelegatingFilterProxy( DEFAULT_FILTER_NAME ) ),
        "/*",
        EnumSet.allOf( DispatcherType.class ));
    

    I also had to enable Session-Handling in Jetty, but this is explained very well here.

    0 讨论(0)
提交回复
热议问题