Note that there are some explanatory texts on larger screens.

plurals
  1. POConfigure Spring Security on embedded Jetty in Spring
    primarykey
    data
    text
    <p>I have a Spring beans definition file, as below</p> <pre><code>&lt;bean id="jettyZk" class="org.eclipse.jetty.server.Server" init-method="start" destroy-method="stop"&gt; &lt;!-- properties, threadPool, connectors --&gt; &lt;property name="handler"&gt; &lt;bean class="org.eclipse.jetty.servlet.ServletContextHandler"&gt; &lt;property name="eventListeners"&gt; &lt;list&gt; &lt;!-- my.ContextLoaderListener * An ApplicationContextAware ContextLoaderListener that allows for using the current ApplicationContext, * as determined by ApplicationContextAware, as the parent for the Root WebApplicationContext. * * Also provides for specifying the contextConfigLocation of the Root WebApplicationContext, because * Eclipse Jetty 7 ServletContextHandler does not expose a setInitParameters method. --&gt; &lt;bean class="my.ContextLoaderListener"&gt; &lt;property name="contextConfigLocation" value="/META-INF/spring/applicationContext-securityZk.xml"/&gt; &lt;/bean&gt; &lt;!-- not sure if this is needed, disabled for now --&gt; &lt;!-- &lt;bean class="org.springframework.web.context.request.RequestContextListener"/&gt; --&gt; &lt;/list&gt; &lt;/property&gt; &lt;property name="servletHandler"&gt; &lt;bean class="org.eclipse.jetty.servlet.ServletHandler"&gt; &lt;property name="filters"&gt; &lt;list&gt; &lt;bean class="org.eclipse.jetty.servlet.FilterHolder"&gt; &lt;property name="name" value="springSecurityFilterChain"/&gt; &lt;property name="filter"&gt; &lt;bean class="org.springframework.web.filter.DelegatingFilterProxy"/&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/list&gt; &lt;/property&gt; &lt;!-- filterMappings, servlets, servletMappings --&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; &lt;/property&gt; &lt;/bean&gt; </code></pre> <p>When trying to start the context, I get the following exception</p> <pre><code>Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: ServletContext must not be null Caused by: java.lang.IllegalArgumentException: ServletContext must not be null at org.springframework.util.Assert.notNull(Assert.java:112) at org.springframework.web.context.support.WebApplicationContextUtils.getWebApplicationContext(WebApplicationContextUtils.java:109) </code></pre> <p>This is using Spring 3.0.5.RELEASE</p> <p>The exception is understandable, looking at the code and JavaDocs for DelegatingFilterProxy#findWebApplicationContext, which says</p> <blockquote> <p>The WebApplicationContext must have already been loaded and stored in the ServletContext before this filter gets initialized (or invoked).</p> </blockquote> <p>because I'm trying to create the filter as a (sub)property of the context handler, so it seems sensible that the context has not yet been initialized and thus neither has the Spring WAC.</p> <p>What I'd like to know is how can I configure Spring Security in an embedded Jetty container that Spring itself is assembling?</p> <p>It seems like there's a catch 22 scenario that just needs a late initialisation, but I can't find a suitable flag to twiddle. I've tried setting <code>lazy-init="true"</code> onto the filter bean, but that didn't seem to achieve much, unsurprisingly.</p> <p>Related: <a href="https://stackoverflow.com/questions/3164092">How to embed Jetty into Spring and make it use the same AppContext it was embedded into?</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload