title: Ticket does not match the supplied service error using Grails, CAS, and LDAP
body: <p>I have an app with Grails 2.2.3 that uses the plugins Spring Security Core 1.2.7.3, Spring Security CAS 1.0.5, and Spring Security LDAP 1.0.6.</p>
  
  <p>I am using LDAP for roles, user storage and user info, and CAS for single sign on. When I authenticate the first time I get a <code>BadCredentials</code> exception (the one that says "not able to find a user with that username and password."), but if I try the second time it authenticates correctly.</p>
  
  <p>When I debug that exception, it is actually caused by the error:</p>
  
  <pre><code>org.jasig.cas.client.validation.TicketValidationException: 
      ticket 'my-ticket' does not match supplied service
  </code></pre>
  
  <p>Does anyone know what is causing this error or how to fix it? Here are the settings in resources.groovy:</p>
  
  <pre><code>initialDirContextFactory(DefaultSpringSecurityContextSource, "ldap://ldap.company.com:389") {
      userDn = "CN=Admin,OU=Users,DC=company,DC=com"
      password = "password"
  }
  
  ldapUserSearch(FilterBasedLdapUserSearch,
                 "OU=Users,DC=company,DC=com",
                 "employeeId={0}",
                 initialDirContextFactory) { }
  
  ldapUserDetailsMapper(MyLdapUserDetailsContextMapper) { }
  
  ldapAuthoritiesPopulator(DefaultLdapAuthoritiesPopulator,
                           initialDirContextFactory,
                           "ou=Groups,OU=Users,DC=company,DC=com") {
      groupRoleAttribute = "cn"
      groupSearchFilter = "member={0}"
      rolePrefix = ""
      searchSubtree = true
      convertToUpperCase = true
      ignorePartialResultException = true
  }
  
  userDetailsService(LdapUserDetailsService, ldapUserSearch, ldapAuthoritiesPopulator) {
      userDetailsMapper = ref('ldapUserDetailsMapper')
  }
  </code></pre>
  
  <p>And my settings in config.groovy:</p>
  
  <pre><code>grails.plugins.springsecurity.cas.serverUrlPrefix = 'https://cas.company.com/cas'
  grails.plugins.springsecurity.cas.loginUri = "/login"
  grails.plugins.springsecurity.cas.serviceUrl = "${grails.serverURL}/j_spring_cas_security_check"
  
  grails.plugins.springsecurity.providerNames = ['casAuthenticationProvider']
  
  grails.plugins.springsecurity.defaultTargetUrl = '/'
  grails.plugins.springsecurity.alwaysUseDefault = false
  </code></pre>