|
1 | 1 | package com.asquera.elasticsearch.plugins.http;
|
2 | 2 |
|
3 |
| -import org.elasticsearch.http.*; |
| 3 | +import com.asquera.elasticsearch.plugins.http.auth.Client; |
| 4 | +import com.asquera.elasticsearch.plugins.http.auth.InetAddressWhitelist; |
| 5 | +import com.asquera.elasticsearch.plugins.http.auth.ProxyChains; |
| 6 | +import com.asquera.elasticsearch.plugins.http.auth.XForwardedFor; |
| 7 | +import org.elasticsearch.common.Base64; |
| 8 | +import org.elasticsearch.common.inject.Inject; |
| 9 | +import org.elasticsearch.common.logging.Loggers; |
4 | 10 | import org.elasticsearch.common.settings.Settings;
|
5 | 11 | import org.elasticsearch.env.Environment;
|
| 12 | +import org.elasticsearch.http.HttpChannel; |
| 13 | +import org.elasticsearch.http.HttpRequest; |
| 14 | +import org.elasticsearch.http.HttpServer; |
| 15 | +import org.elasticsearch.http.HttpServerTransport; |
6 | 16 | import org.elasticsearch.node.service.NodeService;
|
| 17 | +import org.elasticsearch.rest.BytesRestResponse; |
7 | 18 | import org.elasticsearch.rest.RestController;
|
8 |
| -import org.elasticsearch.common.inject.Inject; |
9 |
| -import org.elasticsearch.common.Base64; |
10 | 19 | import org.elasticsearch.rest.RestRequest;
|
11 |
| - |
12 |
| -import static org.elasticsearch.rest.RestStatus.*; |
| 20 | +import org.elasticsearch.rest.RestRequest.Method; |
13 | 21 |
|
14 | 22 | import java.io.IOException;
|
15 | 23 | import java.net.InetAddress;
|
16 | 24 | import java.net.InetSocketAddress;
|
17 | 25 |
|
18 |
| -import org.elasticsearch.common.logging.Loggers; |
19 |
| -import org.elasticsearch.rest.BytesRestResponse; |
20 |
| -import org.elasticsearch.rest.RestRequest.Method; |
21 |
| - |
22 |
| -import com.asquera.elasticsearch.plugins.http.auth.Client; |
23 |
| -import com.asquera.elasticsearch.plugins.http.auth.InetAddressWhitelist; |
24 |
| -import com.asquera.elasticsearch.plugins.http.auth.ProxyChains; |
25 |
| -import com.asquera.elasticsearch.plugins.http.auth.XForwardedFor; |
| 26 | +import static org.elasticsearch.rest.RestStatus.OK; |
| 27 | +import static org.elasticsearch.rest.RestStatus.UNAUTHORIZED; |
26 | 28 |
|
27 | 29 | // # possible http config
|
28 | 30 | // http.basic.user: admin
|
@@ -71,18 +73,18 @@ public class HttpBasicServer extends HttpServer {
|
71 | 73 | @Override
|
72 | 74 | public void internalDispatchRequest(final HttpRequest request, final HttpChannel channel) {
|
73 | 75 | if (log) {
|
74 |
| - logRequest(request); |
| 76 | + logRequest(request); |
75 | 77 | }
|
76 |
| - // allow health check even without authorization |
77 |
| - if (healthCheck(request)) { |
78 |
| - channel.sendResponse(new BytesRestResponse(OK, "{\"OK\":{}}")); |
79 |
| - } else if (authorized(request)) { |
| 78 | + |
| 79 | + if (authorized(request)) { |
80 | 80 | super.internalDispatchRequest(request, channel);
|
| 81 | + } else if (healthCheck(request)) { // display custom health check page when unauthorized (do not display too much server info) |
| 82 | + channel.sendResponse(new BytesRestResponse(OK, "{\"OK\":{}}")); |
81 | 83 | } else {
|
82 |
| - logUnAuthorizedRequest(request); |
83 |
| - BytesRestResponse response = new BytesRestResponse(UNAUTHORIZED, "Authentication Required"); |
84 |
| - response.addHeader("WWW-Authenticate", "Basic realm=\"Restricted\""); |
85 |
| - channel.sendResponse(response); |
| 84 | + logUnAuthorizedRequest(request); |
| 85 | + BytesRestResponse response = new BytesRestResponse(UNAUTHORIZED, "Authentication Required"); |
| 86 | + response.addHeader("WWW-Authenticate", "Basic realm=\"Restricted\""); |
| 87 | + channel.sendResponse(response); |
86 | 88 | }
|
87 | 89 | }
|
88 | 90 |
|
|
0 commit comments