@Override
    public boolean authenticateHttpRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Boolean authenticated = applyAuthProcessor(
            providers,
            provider -> {
                try {
                    return provider.authenticateHttpRequest(request, response);
                } catch (Exception e) {
                    if (e instanceof AuthenticationException) {
                        throw (AuthenticationException) e;
                    } else {
                        throw new AuthenticationException("Failed to authentication http request");
                    }
                }
            }
        );
        return authenticated;
    }
@Test
    public void testAuthenticateHttpRequest() throws Exception {
        HttpServletRequest requestAA = mock(HttpServletRequest.class);
        when(requestAA.getRemoteAddr()).thenReturn("127.0.0.1");
        when(requestAA.getRemotePort()).thenReturn(8080);
        when(requestAA.getHeader("Authorization")).thenReturn("Bearer " + expiringTokenAA);
        boolean doFilterAA = authProvider.authenticateHttpRequest(requestAA, null);
        assertTrue(doFilterAA);
        verify(requestAA).setAttribute(eq(AuthenticatedRoleAttributeName), eq(SUBJECT_A));
        verify(requestAA).setAttribute(eq(AuthenticatedDataAttributeName), isA(AuthenticationDataSource.class));

        HttpServletRequest requestAB = mock(HttpServletRequest.class);
        when(requestAB.getRemoteAddr()).thenReturn("127.0.0.1");
        when(requestAB.getRemotePort()).thenReturn(8080);
        when(requestAB.getHeader("Authorization")).thenReturn("Bearer " + expiringTokenAB);
        boolean doFilterAB = authProvider.authenticateHttpRequest(requestAB, null);
        assertTrue(doFilterAB);
        verify(requestAB).setAttribute(eq(AuthenticatedRoleAttributeName), eq(SUBJECT_B));
        verify(requestAB).setAttribute(eq(AuthenticatedDataAttributeName), isA(AuthenticationDataSource.class));

        HttpServletRequest requestBA = mock(HttpServletRequest.class);
        when(requestBA.getRemoteAddr()).thenReturn("127.0.0.1");
        when(requestBA.getRemotePort()).thenReturn(8080);
        when(requestBA.getHeader("Authorization")).thenReturn("Bearer " + expiringTokenBA);
        boolean doFilterBA = authProvider.authenticateHttpRequest(requestBA, null);
        assertTrue(doFilterBA);
        verify(requestBA).setAttribute(eq(AuthenticatedRoleAttributeName), eq(SUBJECT_A));
        verify(requestBA).setAttribute(eq(AuthenticatedDataAttributeName), isA(AuthenticationDataSource.class));

        HttpServletRequest requestBB = mock(HttpServletRequest.class);
        when(requestBB.getRemoteAddr()).thenReturn("127.0.0.1");
        when(requestBB.getRemotePort()).thenReturn(8080);
        when(requestBB.getHeader("Authorization")).thenReturn("Bearer " + expiringTokenBB);
        boolean doFilterBB = authProvider.authenticateHttpRequest(requestBB, null);
        assertTrue(doFilterBB);
        verify(requestBB).setAttribute(eq(AuthenticatedRoleAttributeName), eq(SUBJECT_B));
        verify(requestBB).setAttribute(eq(AuthenticatedDataAttributeName), isA(AuthenticationDataSource.class));
    }