BackwardsCompatibleTokenEndpointAuthenticationFilter implements Filter { public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException { final HttpServletRequest request = (HttpServletRequest) req; final HttpServletResponse response = (HttpServletResponse) res; try { Authentication userAuthentication = attemptTokenAuthentication(request, response); if (userAuthentication != null) { Authentication clientAuth = SecurityContextHolder.getContext().getAuthentication(); if (clientAuth == null) { throw new BadCredentialsException( "No client authentication found. Remember to put a filter upstream of the TokenEndpointAuthenticationFilter."); } Map<String, String> map = getSingleValueMap(request); map.put(OAuth2Utils.CLIENT_ID, clientAuth.getName()); SecurityContextHolder.getContext().setAuthentication(userAuthentication); AuthorizationRequest authorizationRequest = oAuth2RequestFactory.createAuthorizationRequest(map); if (clientAuth.isAuthenticated()) { authorizationRequest.setApproved(true); } OAuth2Request storedOAuth2Request = oAuth2RequestFactory.createOAuth2Request(authorizationRequest); SecurityContextHolder .getContext() .setAuthentication(new OAuth2Authentication(storedOAuth2Request, userAuthentication)); onSuccessfulAuthentication(request, response, userAuthentication); } } catch (AuthenticationException failed) { logger.debug("Authentication request failed: " + failed.getMessage()); onUnsuccessfulAuthentication(request, response, failed); authenticationEntryPoint.commence(request, response, failed); return; } catch (OAuth2Exception failed) { String message = failed.getMessage(); logger.debug("Authentication request failed with Oauth exception: " + message); InsufficientAuthenticationException ex = new InsufficientAuthenticationException (message, failed); onUnsuccessfulAuthentication(request, response, ex); authenticationEntryPoint.commence(request, response, ex); return; } chain.doFilter(request, response); } BackwardsCompatibleTokenEndpointAuthenticationFilter(AuthenticationManager authenticationManager,
                                                                OAuth2RequestFactory oAuth2RequestFactory);  BackwardsCompatibleTokenEndpointAuthenticationFilter(AuthenticationManager authenticationManager,
                                                                OAuth2RequestFactory oAuth2RequestFactory,
                                                                SAMLProcessingFilter samlAuthenticationFilter,
                                                                ExternalOAuthAuthenticationManager externalOAuthAuthenticationManager); void setAuthenticationEntryPoint(AuthenticationEntryPoint authenticationEntryPoint); void setAuthenticationDetailsSource(
        AuthenticationDetailsSource<HttpServletRequest, ?> authenticationDetailsSource); void doFilter(ServletRequest req, ServletResponse res, FilterChain chain); @Override void init(FilterConfig filterConfig); @Override void destroy();  }
@Test public void password_expired() throws Exception { UaaAuthentication uaaAuthentication = mock(UaaAuthentication.class); when(uaaAuthentication.isAuthenticated()).thenReturn(true); MockHttpSession httpSession = new MockHttpSession(); SessionUtils.setPasswordChangeRequired(httpSession, true); request.setSession(httpSession); when(passwordAuthManager.authenticate(any())).thenReturn(uaaAuthentication); request.addParameter(GRANT_TYPE, "password"); request.addParameter("username", "marissa"); request.addParameter("password", "koala"); filter.doFilter(request, response, chain); verify(entryPoint, times(1)).commence(same(request), same(response), any(PasswordChangeRequiredException.class)); }