### Question:
KeycloakAuthenticationProcessingFilter extends AbstractAuthenticationProcessingFilter implements ApplicationContextAware { @Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { if (authResult instanceof KeycloakAuthenticationToken && ((KeycloakAuthenticationToken) authResult).isInteractive()) { super.successfulAuthentication(request, response, chain, authResult); return; } if (log.isDebugEnabled()) { log.debug("Authentication success using bearer token/basic authentication. Updating SecurityContextHolder to contain: {}", authResult); } SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(authResult); SecurityContextHolder.setContext(context); try { if (this.eventPublisher != null) { eventPublisher.publishEvent(new InteractiveAuthenticationSuccessEvent(authResult, this.getClass())); } chain.doFilter(request, response); } finally { SecurityContextHolder.clearContext(); } } KeycloakAuthenticationProcessingFilter(AuthenticationManager authenticationManager);  KeycloakAuthenticationProcessingFilter(AuthenticationManager authenticationManager, RequestMatcher
            requiresAuthenticationRequestMatcher); @Override void afterPropertiesSet(); @Override Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response); @Override void setApplicationContext(ApplicationContext applicationContext); void setAdapterTokenStoreFactory(AdapterTokenStoreFactory adapterTokenStoreFactory); @Override final void setAllowSessionCreation(boolean allowSessionCreation); @Override final void setContinueChainBeforeSuccessfulAuthentication(boolean continueChainBeforeSuccessfulAuthentication); void setRequestAuthenticatorFactory(RequestAuthenticatorFactory requestAuthenticatorFactory); static final String AUTHORIZATION_HEADER; static final RequestMatcher DEFAULT_REQUEST_MATCHER; }### Answer:
@Test public void testSuccessfulAuthenticationInteractive() throws Exception { request.setRequestURI("http: Authentication authentication = new KeycloakAuthenticationToken(keycloakAccount, true, authorities); filter.successfulAuthentication(request, response, chain, authentication); verify(successHandler).onAuthenticationSuccess(eq(request), eq(response), eq(authentication)); verify(chain, never()).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class)); }
@Test public void testSuccessfulAuthenticationBearer() throws Exception { Authentication authentication = new KeycloakAuthenticationToken(keycloakAccount, false, authorities); this.setBearerAuthHeader(request); filter.successfulAuthentication(request, response, chain, authentication); verify(chain).doFilter(eq(request), eq(response)); verify(successHandler, never()).onAuthenticationSuccess(any(HttpServletRequest.class), any(HttpServletResponse.class), any(Authentication.class)); }
@Test public void testSuccessfulAuthenticationBasicAuth() throws Exception { Authentication authentication = new KeycloakAuthenticationToken(keycloakAccount, false, authorities); this.setBasicAuthHeader(request); filter.successfulAuthentication(request, response, chain, authentication); verify(chain).doFilter(eq(request), eq(response)); verify(successHandler, never()).onAuthenticationSuccess(any(HttpServletRequest.class), any(HttpServletResponse.class), any(Authentication.class)); }