| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 | [[creating-classic-plugins]]=== Creating classic pluginsClassic plugins provide {es} with mechanisms for custom authentication,authorization, scoring, and more.[IMPORTANT].Plugin release lifecycle==============================================Classic plugins require you to build a new version for each new {es} release.This version is checked when the plugin is installed and when it is loaded. {es}will refuse to start in the presence of plugins with the incorrect`elasticsearch.version`.==============================================[discrete]==== Classic plugin file structureClassis plugins are ZIP files composed of JAR files and<<plugin-descriptor-file-{plugin-type},a metadata file called`plugin-descriptor.properties`>>, a Java properties file that describes theplugin.Note that only JAR files at the root of the plugin are added to the classpathfor the plugin. If you need other resources, package them into a resources JAR.[discrete]==== Example pluginsThe {es} repository contains {es-repo}tree/main/plugins/examples[examples of plugins]. Some of these include:* a plugin with {es-repo}tree/main/plugins/examples/custom-settings[custom settings]* adding {es-repo}tree/main/plugins/examples/rest-handler[custom rest endpoints]* adding a {es-repo}tree/main/plugins/examples/rescore[custom rescorer]* a script {es-repo}tree/main/plugins/examples/script-expert-scoring[implemented in Java]These examples provide the bare bones needed to get started. For moreinformation about how to write a plugin, we recommend looking at the {es-repo}tree/main/plugins/[source code of existing plugins] for inspiration.[discrete]==== Testing your pluginUse `bin/elasticsearch-plugin install file:///path/to/your/plugin`to install your plugin for testing. The Java plugin is auto-loaded only if it's in the`plugins/` directory.[discrete][[plugin-authors-jsm]]==== Java Security permissionsSome plugins may need additional security permissions. A plugin can includethe optional `plugin-security.policy` file containing `grant` statements foradditional permissions. Any additional permissions will be displayed to the userwith a large warning, and they will have to confirm them when installing theplugin interactively. So if possible, it is best to avoid requesting anyspurious permissions!If you are using the {es} Gradle build system, place this file in`src/main/plugin-metadata` and it will be applied during unit tests as well.The Java security model is stack-based, and additionalpermissions are granted to the jars in your plugin, so you have towrite proper security code around operations requiring elevated privileges.You might add a check to prevent unprivileged code (such as scripts)from gaining escalated permissions. For example:[source,java]--------------------------------------------------// ES permission you should check before doPrivileged() blocksimport org.elasticsearch.SpecialPermission;SecurityManager sm = System.getSecurityManager();if (sm != null) {  // unprivileged code such as scripts do not have SpecialPermission  sm.checkPermission(new SpecialPermission());}AccessController.doPrivileged(  // sensitive operation);--------------------------------------------------Check https://www.oracle.com/technetwork/java/seccodeguide-139067.html[Secure Coding Guidelines for Java SE]for more information.[[plugin-descriptor-file-classic]]==== The plugin descriptor file for classic pluginsinclude::plugin-descriptor-file.asciidoc[]
 |