If request does not contain correct authentication, then use authentication already in SecurityContext.

It makes possible to use spring-security-cas plugin to login to application.

When main page is reached, then user is redirected to CAS to login. After succesful login, user is redirected back on main page, where ajax post request is made to /rest/login ( without username/password). And returned token is added to ajax headers.

Config.groovy:

String restFilters = 'JOINED_FILTERS,-casAuthenticationFilter,-exceptionTranslationFilter,-authenticationProcessingFilter,-securityContextPersistenceFilter'
String casFilters = 'JOINED_FILTERS,-restTokenValidationFilter,-restExceptionTranslationFilter'  
grails.plugin.springsecurity.filterChain.chainMap = [
	'/rest/login': 'JOINED_FILTERS',
	'/index.gsp': casFilters,
	'/j_spring_cas_security_check': casFilters,
	'/**': restFilters
]
This line throws a NPE. See https://travis-ci.org/alvarosanchez/grails-spring-security-rest/builds/32515130#L1758