MultiAuthenticator extends Authenticator { @Override public Result authenticate(HttpExchange httpExchange) { Result result = null; for (Authenticator a : authenticators) { result = a.authenticate(httpExchange); if ((result instanceof Success && mode == Mode.ANY) || (!(result instanceof Success) && mode == Mode.ALL)) { return result; } } return result; } MultiAuthenticator(Mode mode, List<Authenticator> authenticators); @Override Result authenticate(HttpExchange httpExchange);  }
@Test public void anyPositive() throws Exception { MultiAuthenticator authenticator = new MultiAuthenticator(MultiAuthenticator.Mode.ANY, Arrays.asList(NEGATIVE_AUTHENTICATOR, POSITIVE_AUTHENTICATOR, NEGATIVE_AUTHENTICATOR)); assertTrue(authenticator.authenticate(null) instanceof Authenticator.Success); }
@Test public void anyNegative() throws Exception { MultiAuthenticator authenticator = new MultiAuthenticator(MultiAuthenticator.Mode.ANY, Arrays.asList(NEGATIVE_AUTHENTICATOR, NEGATIVE_AUTHENTICATOR, NEGATIVE_AUTHENTICATOR)); assertTrue(authenticator.authenticate(null) instanceof Authenticator.Failure); }
@Test public void allPositive() throws Exception { MultiAuthenticator authenticator = new MultiAuthenticator(MultiAuthenticator.Mode.ALL, Arrays.asList(POSITIVE_AUTHENTICATOR, POSITIVE_AUTHENTICATOR, POSITIVE_AUTHENTICATOR)); assertTrue(authenticator.authenticate(null) instanceof Authenticator.Success); }
@Test public void allNegative() throws Exception { MultiAuthenticator authenticator = new MultiAuthenticator(MultiAuthenticator.Mode.ALL, Arrays.asList(NEGATIVE_AUTHENTICATOR, POSITIVE_AUTHENTICATOR, NEGATIVE_AUTHENTICATOR)); assertTrue(authenticator.authenticate(null) instanceof Authenticator.Failure); }