From 34344ba8edf8b5314eea1912768151d30b505c79 Mon Sep 17 00:00:00 2001 From: Framonti Date: Thu, 29 Apr 2021 15:51:27 +0200 Subject: [PATCH 1/4] update Elasticsearch dependencies to 7.12.0 --- README.md | 2 +- pom.xml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index e8802c2..8eb849b 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ There is no way to configure this on a per index basis. |-----------------------------|------------------------------| | v0.0.1 | 6.3.2 | | v0.1.0 | 7.6.0 | - +| v0.2.0 | 7.12.0 | ## Installation diff --git a/pom.xml b/pom.xml index 8067d0b..221c09b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 com.cleafy.elasticsearch elasticsearch-http-basic-auth-plugin - 0.1.0 + 0.2.0 jar Elasticsearch Http Basic plugin Adds HTTP Basic authentication (BA) to your Elasticsearch cluster @@ -21,14 +21,14 @@ org.elasticsearch elasticsearch - 7.6.0 + 7.12.0 provided org.elasticsearch.test framework - 7.6.0 + 7.12.0 test From decc34906f9f759e223c16a8e68abee336332e5a Mon Sep 17 00:00:00 2001 From: Framonti Date: Thu, 29 Apr 2021 16:37:35 +0200 Subject: [PATCH 2/4] various code clean-up --- .../elasticsearch/plugins/http/BasicRestFilter.java | 2 +- .../plugins/http/HttpBasicServerPlugin.java | 9 ++++----- .../plugins/http/auth/AuthCredentials.java | 11 ++++------- .../plugins/http/auth/HttpBasicAuthenticator.java | 7 ++----- 4 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/cleafy/elasticsearch/plugins/http/BasicRestFilter.java b/src/main/java/com/cleafy/elasticsearch/plugins/http/BasicRestFilter.java index 6b07b7e..3154b3c 100644 --- a/src/main/java/com/cleafy/elasticsearch/plugins/http/BasicRestFilter.java +++ b/src/main/java/com/cleafy/elasticsearch/plugins/http/BasicRestFilter.java @@ -12,7 +12,7 @@ public class BasicRestFilter { private final HttpBasicAuthenticator httpBasicAuthenticator; - private boolean isUnauthLogEnabled; + private final boolean isUnauthLogEnabled; public BasicRestFilter(final Settings settings) { super(); diff --git a/src/main/java/com/cleafy/elasticsearch/plugins/http/HttpBasicServerPlugin.java b/src/main/java/com/cleafy/elasticsearch/plugins/http/HttpBasicServerPlugin.java index 2f36f87..ea4283f 100644 --- a/src/main/java/com/cleafy/elasticsearch/plugins/http/HttpBasicServerPlugin.java +++ b/src/main/java/com/cleafy/elasticsearch/plugins/http/HttpBasicServerPlugin.java @@ -19,7 +19,7 @@ */ public class HttpBasicServerPlugin extends Plugin implements ActionPlugin { - private boolean enabledByDefault = false; + private final boolean enabledByDefault = false; private final Settings settings; BasicRestFilter basicFilter; @@ -40,9 +40,9 @@ public String description() { @Override public UnaryOperator getRestHandlerWrapper(final ThreadContext threadContext) { if (this.settings.getAsBoolean(Globals.SETTINGS_ENABLED, enabledByDefault)) { - return (rh) -> basicFilter.wrap(rh); + return rh -> basicFilter.wrap(rh); } - return (rh) -> rh; + return rh -> rh; } @Override @@ -58,9 +58,8 @@ public Settings additionalSettings() { @Override public List> getSettings() { - List> settings = new ArrayList>(); - settings.addAll(super.getSettings()); + List> settings = new ArrayList<>(super.getSettings()); settings.add(Setting.boolSetting(Globals.SETTINGS_ENABLED, enabledByDefault, Setting.Property.NodeScope, Setting.Property.Filtered)); settings.add(Setting.simpleString(Globals.SETTINGS_USERNAME, Setting.Property.NodeScope, Setting.Property.Filtered)); diff --git a/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/AuthCredentials.java b/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/AuthCredentials.java index bb1bee8..5e24c18 100644 --- a/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/AuthCredentials.java +++ b/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/AuthCredentials.java @@ -11,7 +11,7 @@ public class AuthCredentials { private final String username; private byte[] password; private Object nativeCredentials; - private final Set backendRoles = new HashSet(); + private final Set backendRoles = new HashSet<>(); private boolean complete; private final byte[] internalPasswordHash; private final Map attributes = new HashMap<>(); @@ -116,11 +116,8 @@ public boolean equals(Object obj) { if (internalPasswordHash == null || other.internalPasswordHash == null || !MessageDigest.isEqual(internalPasswordHash, other.internalPasswordHash)) return false; if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; + return other.username == null; + } else return username.equals(other.username); } @Override @@ -133,7 +130,7 @@ public String toString() { * @return Defensive copy of the roles this user is member of. */ public Set getBackendRoles() { - return new HashSet(backendRoles); + return new HashSet<>(backendRoles); } public boolean isComplete() { diff --git a/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/HttpBasicAuthenticator.java b/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/HttpBasicAuthenticator.java index 555e947..db5bec2 100644 --- a/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/HttpBasicAuthenticator.java +++ b/src/main/java/com/cleafy/elasticsearch/plugins/http/auth/HttpBasicAuthenticator.java @@ -4,7 +4,7 @@ import org.elasticsearch.rest.RestRequest; public class HttpBasicAuthenticator extends Authenticator { - private AuthCredentials credentials; + private final AuthCredentials credentials; public HttpBasicAuthenticator(Settings settings, AuthCredentials credentials) { super(settings); @@ -13,10 +13,7 @@ public HttpBasicAuthenticator(Settings settings, AuthCredentials credentials) { @Override public boolean authenticate(RestRequest request) { - if (this.extractCredentials(request).equals(credentials)) { - return true; - } - return false; + return this.extractCredentials(request).equals(credentials); } private AuthCredentials extractCredentials(final RestRequest request) { From 8fc81e6b85496da39d49fd6eb56f0c96b9c8b258 Mon Sep 17 00:00:00 2001 From: Framonti Date: Thu, 29 Apr 2021 16:37:59 +0200 Subject: [PATCH 3/4] update ES version in plugin-descriptor.properties --- src/main/resources/plugin-descriptor.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/resources/plugin-descriptor.properties b/src/main/resources/plugin-descriptor.properties index b9c36f7..46f438c 100644 --- a/src/main/resources/plugin-descriptor.properties +++ b/src/main/resources/plugin-descriptor.properties @@ -3,4 +3,4 @@ name=elasticsearch-http-basic-auth-plugin description=Plugin to enable HTTP basic authentication and/or Ip based authentication version=1.0.0 java.version=1.8 -elasticsearch.version=7.6.0 \ No newline at end of file +elasticsearch.version=7.12.0 \ No newline at end of file From 18d541d4bbf397ab33f7fe5d7e02aad134073c20 Mon Sep 17 00:00:00 2001 From: Framonti Date: Mon, 3 May 2021 11:48:37 +0200 Subject: [PATCH 4/4] update pom and plugin xmls --- pom.xml | 4 ++-- src/main/assemblies/plugin.xml | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 221c09b..cdc557e 100644 --- a/pom.xml +++ b/pom.xml @@ -15,6 +15,7 @@ 1 INFO + UTF-8 @@ -24,7 +25,6 @@ 7.12.0 provided - org.elasticsearch.test framework @@ -54,7 +54,7 @@ maven-assembly-plugin 2.6 - false + true ${project.build.directory}/releases/ ${basedir}/src/main/assemblies/plugin.xml diff --git a/src/main/assemblies/plugin.xml b/src/main/assemblies/plugin.xml index 2253aba..2c83876 100644 --- a/src/main/assemblies/plugin.xml +++ b/src/main/assemblies/plugin.xml @@ -1,10 +1,19 @@ - plugin + 0.2.0 zip false + + + / + src/main/resources + + *.properties + + + / @@ -19,7 +28,7 @@ true true - com.cleafy.elasticsearch:elasticsearch6-http-basic + com.cleafy.elasticsearch:elasticsearch-http-basic