Hi,
I am trying to write simple custom authentication plugin for elasticsearch v5.4.1. In previous versions before 5.4.2, it could be done with Restfilters. But now they are not present. Somewhere i read that use RestHandlers for the same. However , I am not able to get code executed inside my custom handler.
What i am trying to achieve is that i will get a header having authentication information in my rest request. Will validate that information using external services inside my custom handler and if authenticated, execute the call else throw excecption.
My custom handler looks like below:-
public class AuthenticationHandler implements RestHandler {
public AuthenticationHandler(Settings settings, RestController controller) {
super();
controller.registerHandler(Method.GET, "/shakespeare", this);
}
@Override
public void handleRequest(RestRequest request, RestChannel channel, NodeClient client) throws IOException {
System.out.println("AuthenticationHandler is running");
List<String> header = request.getHeaders().get("auth");
if (authenticate(header)) {
// execute the actual request
} else
throw new RuntimeException("authentication failed");
}
private boolean authenticate(List<String> header) {
// TODO Use external services to authenticate further
return true;
}
}
My plugin class looks like below:-
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));
}
}
However, my custom code is not being executed.
Can someone help me out in this regards?