@Override
    public AuthenticationState newAuthState(AuthData authData, SocketAddress remoteAddress, SSLSession sslSession)
        throws AuthenticationException {
        final List<AuthenticationState> states = new ArrayList<>(providers.size());

        AuthenticationException authenticationException = null;
        for (AuthenticationProvider provider : providers) {
            try {
                AuthenticationState state = provider.newAuthState(authData, remoteAddress, sslSession);
                states.add(state);
            } catch (AuthenticationException ae) {
                if (log.isDebugEnabled()) {
                    log.debug("Authentication failed for auth provider " + provider.getClass() + ": ", ae);
                }
                // Store the exception so we can throw it later instead of a generic one
                authenticationException = ae;
            }
        }
        if (states.isEmpty()) {
            log.debug("Failed to initialize a new auth state from {}", remoteAddress, authenticationException);
            if (authenticationException != null) {
                throw authenticationException;
            } else {
                throw new AuthenticationException("Failed to initialize a new auth state from " + remoteAddress);
            }
        } else {
            return new AuthenticationListState(states);
        }
    }
@Test
    public void testNewAuthState() throws Exception {
        AuthenticationState authStateAA = newAuthState(expiringTokenAA, SUBJECT_A);
        AuthenticationState authStateAB = newAuthState(expiringTokenAB, SUBJECT_B);
        AuthenticationState authStateBA = newAuthState(expiringTokenBA, SUBJECT_A);
        AuthenticationState authStateBB = newAuthState(expiringTokenBB, SUBJECT_B);

        Thread.sleep(TimeUnit.SECONDS.toMillis(6));

        verifyAuthStateExpired(authStateAA, SUBJECT_A);
        verifyAuthStateExpired(authStateAB, SUBJECT_B);
        verifyAuthStateExpired(authStateBA, SUBJECT_A);
        verifyAuthStateExpired(authStateBB, SUBJECT_B);

    }