Search in sources :

Example 1 with HttpPrincipal

use of com.sun.net.httpserver.HttpPrincipal in project jetty.project by eclipse.

the class HttpSpiContextHandler method handleAuthentication.

private void handleAuthentication(HttpServletResponse resp, HttpExchange httpExchange, Authenticator auth) throws IOException {
    Result result = auth.authenticate(httpExchange);
    if (result instanceof Authenticator.Failure) {
        int rc = ((Authenticator.Failure) result).getResponseCode();
        for (Map.Entry<String, List<String>> header : httpExchange.getResponseHeaders().entrySet()) {
            for (String value : header.getValue()) resp.addHeader(header.getKey(), value);
        }
        resp.sendError(rc);
    } else if (result instanceof Authenticator.Retry) {
        int rc = ((Authenticator.Retry) result).getResponseCode();
        for (Map.Entry<String, List<String>> header : httpExchange.getResponseHeaders().entrySet()) {
            for (String value : header.getValue()) resp.addHeader(header.getKey(), value);
        }
        resp.setStatus(rc);
        resp.flushBuffer();
    } else if (result instanceof Authenticator.Success) {
        HttpPrincipal principal = ((Authenticator.Success) result).getPrincipal();
        ((JettyExchange) httpExchange).setPrincipal(principal);
        _httpHandler.handle(httpExchange);
    }
}
Also used : HttpPrincipal(com.sun.net.httpserver.HttpPrincipal) Result(com.sun.net.httpserver.Authenticator.Result) List(java.util.List) Map(java.util.Map) Authenticator(com.sun.net.httpserver.Authenticator)

Aggregations

Authenticator (com.sun.net.httpserver.Authenticator)1 Result (com.sun.net.httpserver.Authenticator.Result)1 HttpPrincipal (com.sun.net.httpserver.HttpPrincipal)1 List (java.util.List)1 Map (java.util.Map)1