title: How to correctly set the service URL in Spring's CAS service properties
body: <p>When working with Spring Security + CAS I keep hitting a small road block with the callback URL that is sent to CAS, ie the service property. I've looked at a bunch of examples such as <a href="http://code.google.com/p/click-cas/wiki/Intro" rel="noreferrer">this</a> and <a href="http://mattfleming.com/node/269" rel="noreferrer">this</a> but they all use hard coded URLs (even <a href="http://static.springsource.org/spring-security/site/docs/3.0.x/reference/cas.html" rel="noreferrer">Spring's CAS docs</a>). A typical snip looks something like this...</p>
  
  <pre><code>  &lt;bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties"&gt;
      &lt;property name="service" value="http://localhost:8080/click/j_spring_cas_security_check" /&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>First, I don't want to hard code the server name or the port since I want this WAR to be deployable anywhere and I don't want my application tied to a particular DNS entry at compile time. Second, I don't understand why Spring can't auto detect my application's context <strike>and the request's URL to automagically build the URL.</strike> The first part of that statement still stand but As Raghuram pointed out below with <a href="https://jira.springsource.org/browse/SEC-1374" rel="noreferrer">this link</a>, we can't trust the HTTP Host Header from the client for security reasons. </p>
  
  <p>Ideally I would like service URL to be exactly what the user requested (as long as the request is valid such as a sub domain of mycompany.com) so it is seamless or at the very least I would like to only specify some path relative my applications context root and have Spring determine the service URL on the fly. Something like the following...</p>
  
  <pre><code>  &lt;bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties"&gt;
      &lt;property name="service" value="/my_cas_callback" /&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>OR...</p>
  
  <pre><code>  &lt;bean id="serviceProperties" class="org.springframework.security.ui.cas.ServiceProperties"&gt;
      &lt;property name="service" value="${container.and.app.derived.value.here}" /&gt;
    &lt;/bean&gt;
  </code></pre>
  
  <p>Is any of this possible or easy or have I missed the obvious?</p>