public RestSqlAction(Settings settings, RestController restController) { super(settings); restController.registerHandler(RestRequest.Method.POST, "/_sql/_explain", this); restController.registerHandler(RestRequest.Method.GET, "/_sql/_explain", this); restController.registerHandler(RestRequest.Method.POST, "/_sql", this); restController.registerHandler(RestRequest.Method.GET, "/_sql", this); }
@Override public boolean reRequestAuthentication(final RestChannel channel, AuthCredentials creds) { final BytesRestResponse wwwAuthenticateResponse = new BytesRestResponse(RestStatus.UNAUTHORIZED, "Unauthorized"); wwwAuthenticateResponse.addHeader("WWW-Authenticate", "Basic realm=\"Search Guard\""); channel.sendResponse(wwwAuthenticateResponse); return true; }
/** * Register the REST handler */ public void onModule(RestModule module) { module.addRestAction(RestMongoDBRiverAction.class); }
public void sendResponse(RestChannel channel){ try { String json = ElasticUtils.hitsAsStringResult(results,metaResults); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, json); channel.sendResponse(bytesRestResponse); } catch (IOException e) { e.printStackTrace(); } }
private void list(RestRequest request, RestChannel channel, Client esClient) { try { Map<String, Object> rivers = getRivers(request.paramAsInt("page", 1), request.paramAsInt("count", 10), esClient); XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.value(rivers); channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder)); } catch (Throwable e) { errorResponse(request, channel, e); } }
private void respondSuccess(RestRequest request, RestChannel channel, RestStatus status) { try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("success", true); builder.endObject(); channel.sendResponse(new BytesRestResponse(status, builder)); } catch (IOException e) { errorResponse(request, channel, e); } }
@Override public AuthCredentials extractCredentials(final RestRequest request, ThreadContext threadContext) { final boolean forceLogin = request.paramAsBoolean("force_login", false); if(forceLogin) { return null; } final String authorizationHeader = request.header("Authorization"); return HTTPHelper.extractCredentials(authorizationHeader, log); }
public static XContentBuilder restContentBuilder(RestRequest request) throws IOException { // use the request body as the auto detect source (if it exists) return restContentBuilder(request, request.hasContent() ? request.content() : null); }
@Override public void dispatchRequest(RestRequest request, RestChannel channel, ThreadContext threadContext) { threadContext.putTransient(ConfigConstants.SG_INJECTED_USER, request.header(ConfigConstants.SG_INJECTED_USER)); originalDispatcher.dispatchRequest(request, channel, threadContext); }
@Override public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws Exception { org.apache.logging.log4j.ThreadContext.clearAll(); if(!checkAndAuthenticateRequest(request, channel, client)) { original.handleRequest(request, channel, client); } } };
@Override protected Set<String> responseParams() { Set<String> responseParams = new HashSet<>(super.responseParams()); responseParams.addAll(Arrays.asList("sql", "flat", "separator", "_score", "_type", "_id", "newLine", "format")); return responseParams; } }
private void sendDefaultResponse(SearchHits hits, RestChannel channel) { try { String json = ElasticUtils.hitsAsStringResult(hits, new MetaSearchResult()); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, json); channel.sendResponse(bytesRestResponse); } catch (IOException e) { e.printStackTrace(); } } }
public SearchGuardHealthAction(final Settings settings, final RestController controller, final BackendRegistry registry) { super(settings); this.registry = registry; controller.registerHandler(GET, "/_searchguard/health", this); controller.registerHandler(POST, "/_searchguard/health", this); }
private void respondError(RestRequest request, RestChannel channel, String error, RestStatus status) { try { XContentBuilder builder = RestXContentBuilder.restContentBuilder(request); builder.startObject(); builder.field("success", false); builder.field("error", error); builder.endObject(); channel.sendResponse(new BytesRestResponse(status, builder)); } catch (IOException e) { errorResponse(request, channel, e); } }
@Override public void dispatchBadRequest(RestRequest request, RestChannel channel, ThreadContext threadContext, Throwable cause) { threadContext.putTransient(ConfigConstants.SG_INJECTED_USER, request.header(ConfigConstants.SG_INJECTED_USER)); originalDispatcher.dispatchBadRequest(request, channel, threadContext, cause); } }
@Override public void execute(Client client, Map<String, String> params, QueryAction queryAction, RestChannel channel) throws Exception { Object queryResult = QueryActionElasticExecutor.executeAnyAction(client, queryAction); boolean flat = getBooleanOrDefault(params,"flat",false); String separator = ","; if(params.containsKey("separator")){ separator = params.get("separator"); } boolean includeScore = getBooleanOrDefault(params,"_score",false); boolean includeType = getBooleanOrDefault(params,"_type",false); boolean includeId = getBooleanOrDefault(params,"_id",false); CSVResult result = new CSVResultsExtractor(includeScore,includeType,includeId).extractResults(queryResult,flat,separator); String newLine = "\n"; if(params.containsKey("newLine")){ newLine = params.get("newLine"); } String csvString = buildString(separator, result, newLine); BytesRestResponse bytesRestResponse = new BytesRestResponse(RestStatus.OK, csvString); channel.sendResponse(bytesRestResponse); }
public SearchGuardLicenseAction(final Settings settings, final RestController controller) { super(settings); controller.registerHandler(GET, "/_searchguard/license", this); controller.registerHandler(POST, "/_searchguard/license", this); }
public SearchGuardInfoAction(final Settings settings, final RestController controller, final PrivilegesEvaluator evaluator, final ThreadPool threadPool) { super(settings); this.threadContext = threadPool.getThreadContext(); this.evaluator = evaluator; controller.registerHandler(GET, "/_searchguard/authinfo", this); controller.registerHandler(POST, "/_searchguard/authinfo", this); }
public KibanaInfoAction(final Settings settings, final RestController controller, final PrivilegesEvaluator evaluator, final ThreadPool threadPool) { super(settings); this.threadContext = threadPool.getThreadContext(); this.evaluator = evaluator; controller.registerHandler(GET, "/_searchguard/kibanainfo", this); controller.registerHandler(POST, "/_searchguard/kibanainfo", this); }
public TenantInfoAction(final Settings settings, final RestController controller, final PrivilegesEvaluator evaluator, final ThreadPool threadPool, final ClusterService clusterService, final AdminDNs adminDns) { super(settings); this.threadContext = threadPool.getThreadContext(); this.evaluator = evaluator; this.clusterService = clusterService; this.adminDns = adminDns; controller.registerHandler(GET, "/_searchguard/tenantinfo", this); controller.registerHandler(POST, "/_searchguard/tenantinfo", this); }