title: Configure a CAS with Spring (Boot) without web.xml
body: <p>I'm porting a WebApp from Spring 3 to Spring 4 with Boot.</p>
  
  <p>The original web.xml below </p>
  
  <pre><code>&lt;listener&gt;
   &lt;listener-class&gt;org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  
  &lt;filter&gt;
   &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
   &lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;
   &lt;init-param&gt;
      &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
      &lt;param-value&gt;https://casserver/login&lt;/param-value&gt;
   &lt;/init-param&gt;
   &lt;init-param&gt;
      &lt;param-name&gt;serverName&lt;/param-name&gt;
      &lt;param-value&gt;http://myapp&lt;/param-value&gt;
   &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter&gt;
   &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
   &lt;filter-class&gt;org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter&lt;/filter-class&gt;
   &lt;init-param&gt;
      &lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;
      &lt;param-value&gt;https://casserver/login&lt;/param-value&gt;
   &lt;/init-param&gt;
   &lt;init-param&gt;
      &lt;param-name&gt;serverName&lt;/param-name&gt;
      &lt;param-value&gt;http://myapp&lt;/param-value&gt;
   &lt;/init-param&gt;
   &lt;init-param&gt;
      &lt;param-name&gt;encoding&lt;/param-name&gt;
      &lt;param-value&gt;UTF-8&lt;/param-value&gt;
   &lt;/init-param&gt;
  &lt;/filter&gt;
  
  &lt;filter&gt;
   &lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;
   &lt;filter-class&gt;org.jasig.cas.client.session.SingleSignOutFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
   &lt;filter-name&gt;CAS Single Sign Out Filter&lt;/filter-name&gt;
   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;filter-mapping&gt;
   &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  &lt;filter-mapping&gt;
   &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
   &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
  &lt;/filter-mapping&gt;
  
  &lt;session-config&gt;
   &lt;session-timeout&gt;90&lt;/session-timeout&gt;
  &lt;/session-config&gt;
  
  &lt;context-param&gt;
   &lt;param-name&gt;javax.servlet.jsp.jstl.fmt.localizationContext&lt;/param-name&gt;
   &lt;param-value&gt;messages&lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>I'm trying to register all filters, listeners and mappings inside my AppConfic class (below and NOT complete since it's already not working...)</p>
  
  <pre><code>@Configuration
  public class MyWebApplicationInitializer implements ServletContextInitializer  {
  
      @Override
      public void onStartup(ServletContext servletContext) {
          servletContext.addListener(new SingleSignOutHttpSessionListener());
  
          Cas20ProxyReceivingTicketValidationFilter cas20 = new Cas20ProxyReceivingTicketValidationFilter();
          cas20.setServerName("http://myapp");
  
          AuthenticationFilter authenticationFilter = new AuthenticationFilter();
          authenticationFilter.setCasServerLoginUrl("https://casserver");
          authenticationFilter.setServerName("http://myapp");
  
          servletContext.addFilter("CAS Authentication Filter", authenticationFilter);
          servletContext.addFilter("CAS Validation Filter", cas20);
          servletContext.addFilter("CAS Single Sign Out Filter", new SingleSignOutFilter());
      }
  }
  </code></pre>
  
  <p>1/ CAS20 instanciation problem</p>
  
  <p>I can't define cas20 casServerUrlPrefix... There's no setter ?!</p>
  
  <p>2/ AuthenticationFilter problem</p>
  
  <p>Even with serverName defined, during startup, the following error occurs :</p>
  
  <pre><code>java.lang.IllegalArgumentException: serverName or service must be set.
      at org.jasig.cas.client.util.CommonUtils.assertTrue(CommonUtils.java:116) ~[cas-client-core-3.2.1.jar:3.2.1]
      at org.jasig.cas.client.util.AbstractCasFilter.init(AbstractCasFilter.java:103) ~[cas-client-core-3.2.1.jar:3.2.1]
      at org.jasig.cas.client.authentication.AuthenticationFilter.init(AuthenticationFilter.java:96) ~[cas-client-core-3.2.1.jar:3.2.1]
      at org.jasig.cas.client.util.AbstractCasFilter.init(AbstractCasFilter.java:84) ~[cas-client-core-3.2.1.jar:3.2.1]
      at org.apache.catalina.core.ApplicationFilterConfig.initFilter(ApplicationFilterConfig.java:279) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
      at org.apache.catalina.core.ApplicationFilterConfig.&lt;init&gt;(ApplicationFilterConfig.java:109) ~[tomcat-embed-core-8.0.28.jar:8.0.28]
  </code></pre>
  
  <p>Is it possible to define inside a ServletContextInitializer this kind of filters ? Do I have to load a xml (dispatcher-servlet.xml like ?)</p>