Thanks for the reply. I was able to create a basic plugin for the same in the following way..
My plugin class:
public class ESPlugin extends Plugin implements ActionPlugin {
public List<RestHandler> getRestHandlers(Settings settings, RestController restController,
ClusterSettings clusterSettings, IndexScopedSettings indexScopedSettings, SettingsFilter settingsFilter,
IndexNameExpressionResolver indexNameExpressionResolver, Supplier<DiscoveryNodes> nodesInCluster) {
return Arrays.asList(new AuthenticationHandler(settings, restController));
}
@Override
public List<Class<? extends RestHandler>> getRestHandlers() {
return Arrays.asList(AuthenticationHandler.class);
}
}
My Handler:
public class AuthenticationHandler extends BaseRestHandler {
@Inject
public AuthenticationHandler(Settings settings, RestController controller) {
super(settings);
controller.registerFilter(new AuthenticationFilter());
}
@Override
protected RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
return channel -> {
XContentBuilder builder = channel.newBuilder();
builder.startObject();
builder.endObject();
channel.sendResponse(new BytesRestResponse(RestStatus.OK, builder));
};
}
}
My authentication filter that does the actual work:
public class AuthenticationFilter extends RestFilter {
@Override
public void process(RestRequest request, RestChannel channel, NodeClient client, RestFilterChain filterChain)
throws Exception {
try {
if (authenticate(request)) {
filterChain.continueProcessing(request, channel, client);
} else {
final ElasticsearchException exception = new ElasticsearchException("Did not find authentication");
XContentBuilder s = XContentFactory.jsonBuilder().startObject().field(request.uri())
.field(request.rawPath()).endObject();
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, exception));
}
} catch (Exception e) {
channel.sendResponse(new BytesRestResponse(channel, RestStatus.FORBIDDEN, e));
return;
}
}
}