/** * Authenticate against the given request * * @param httpExchange request and response object * @return the result of the first authenticator that does succeed, or the last failure result. */ @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 last result, which is either SUCCESS for mode.ALL or FAILURE for mode.ANY return result; } }
/** * Authenticate against the given request * * @param httpExchange request and response object * @return the result of the first authenticator that does succeed, or the last failure result. */ @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 last resul, which is either SUCCESS for mode.ALL or FAILURE for mode.ANY return result; } }
/** * The filter's implementation, which is invoked by the server */ public void doFilter (HttpExchange t, Filter.Chain chain) throws IOException { if (authenticator != null) { Authenticator.Result r = authenticator.authenticate (t); if (r instanceof Authenticator.Success) { Authenticator.Success s = (Authenticator.Success)r; ExchangeImpl e = ExchangeImpl.get (t); e.setPrincipal (s.getPrincipal()); chain.doFilter (t); } else if (r instanceof Authenticator.Retry) { Authenticator.Retry ry = (Authenticator.Retry)r; consumeInput (t); t.sendResponseHeaders (ry.getResponseCode(), -1); } else if (r instanceof Authenticator.Failure) { Authenticator.Failure f = (Authenticator.Failure)r; consumeInput (t); t.sendResponseHeaders (f.getResponseCode(), -1); } } else { chain.doFilter (t); } } }