in plugin-rest/spring-security-rest/src/main/groovy/grails/plugin/springsecurity/rest/RestTokenValidationFilter.groovy [67:100]
void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpRequest = request as HttpServletRequest
HttpServletResponse httpResponse = response as HttpServletResponse
AccessToken accessToken
try {
accessToken = tokenReader.findToken(httpRequest)
if (accessToken) {
log.debug "Token found: ${accessToken.accessToken}"
log.debug "Trying to authenticate the token"
accessToken = restAuthenticationProvider.authenticate(accessToken) as AccessToken
if (accessToken.authenticated) {
log.debug "Token authenticated. Storing the authentication result in the security context"
log.debug "Authentication result: ${accessToken}"
SecurityContextHolder.context.setAuthentication(accessToken)
authenticationEventPublisher.publishAuthenticationSuccess(accessToken)
processFilterChain(request, response, chain, accessToken)
}
} else {
log.debug "Token not found"
processFilterChain(request, response, chain, accessToken)
}
} catch (AuthenticationException ae) {
log.debug "Authentication failed: ${ae.message}"
authenticationEventPublisher.publishAuthenticationFailure(ae, accessToken)
authenticationFailureHandler.onAuthenticationFailure(httpRequest, httpResponse, ae)
}
}