8000 added pom.xml · nibin/elasticsearch-http-basic@d753658 · GitHub
[go: up one dir, main page]

Skip to content

Commit d753658

Browse files
author
Peter
committed
added pom.xml
1 parent 8b94c87 commit d753658

File tree

6 files changed

+114
-34
lines changed

6 files changed

+114
-34
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
*.class
22
*.jar
33
*.zip
4+
/target/
5+
*~

pom.xml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.asquera.elasticsearch</groupId>
6+
<artifactId>http-basic</artifactId>
7+
<version>0.19.8-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>Basic Authentication Plugin</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
15+
<elasticsearch.version>0.19.8</elasticsearch.version>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.elasticsearch</groupId>
21+
<artifactId>elasticsearch</artifactId>
22+
<version>${elasticsearch.version}</version>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>org.testng</groupId>
27+
<artifactId>testng</artifactId>
28+
<version>6.8</version>
29+
<scope>test</scope>
30+
<exclusions>
31+
<exclusion>
32+
<groupId>org.hamcrest</groupId>
33+
<artifactId>hamcrest-core</artifactId>
34+
</exclusion>
35+
<exclusion>
36+
<groupId>junit</groupId>
37+
<artifactId>junit</artifactId>
38+
</exclusion>
39+
</exclusions>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.hamcrest</groupId>
43+
<artifactId>hamcrest-all</artifactId>
44+
<version>1.3</version>
45+
<scope>test</scope>
46+
</dependency>
47+
</dependencies>
48+
<build>
49+
<!-- Create a zip file according to elasticsearch naming scheme -->
50+
<plugins>
51+
<plugin>
52+
<groupId>org.apache.maven.plugins</groupId>
53+
<artifactId>maven-antrun-plugin</artifactId>
54+
<version>1.6</version>
55+
<executions>
56+
<execution>
57+
<id>zip</id>
58+
<phase>package</phase>
59+
<configuration>
60+
<target>
61+
<zip basedir="${project.build.directory}"
62+
includes="${project.build.finalName}.jar"
63+
destfile="${project.build.directory}/elasticsearch-${project.artifactId}-${elasticsearch.version}.zip" />
64+
</target>
65+
</configuration>
66+
<goals>
67+
<goal>run</goal>
68+
</goals>
69+
</execution>
70+
</executions>
71+
</plugin>
72+
</plugins>
73+
74+
<pluginManagement>
75+
<plugins>
76+
<plugin>
77+
<groupId>org.apache.maven.plugins</groupId>
78+
<artifactId>maven-compiler-plugin</artifactId>
79+
<configuration>
80+
<source>1.6</source>
81+
<target>1.6</target>
82+
</configuration>
83+
</plugin>
84+
</plugins>
85+
</pluginManagement>
86+
</build>
87+
</project>

reinstall.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
ES=/usr/share/elasticsearch
2+
sudo $ES/bin/plugin remove http-basic
3+
mvn -DskipTests clean package
4+
FILE=`ls ./target/elasticsearch-*zip`
5+
sudo $ES/bin/plugin -url file:$FILE -install http-basic
6+
sudo service elasticsearch restart

src/main/java/com/asquera/elasticsearch/plugins/http/HttpBasicServer.java

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,20 @@
1919
* @author Florian Gilcher (florian.gilcher@asquera.de)
2020
*/
2121
public class HttpBasicServer extends HttpServer {
22+
2223
private final String user;
2324
private final String password;
24-
25+
2526
@Inject public HttpBasicServer(Settings settings, Environment environment, HttpServerTransport transport,
26-
RestController restController,
27-
NodeService nodeService) {
28-
super(settings, environment, transport, restController, nodeService);
29-
27+
RestController restController,
28+
NodeService nodeService) {
29+
super(settings, environment, transport, restController, nodeService);
30+
3031
this.user = settings.get("http.basic.user");
3132
this.password = settings.get("http.basic.password");
3233
}
33-
34+
35+
@Override
3436
public void internalDispatchRequest(final HttpRequest request, final HttpChannel channel) {
3537
if (shouldLetPass(request) || authBasic(request)) {
3638
super.internalDispatchRequest(request, channel);
@@ -42,38 +44,27 @@ public void internalDispatchRequest(final HttpRequest request, final HttpChannel
4244
private boolean shouldLetPass(final HttpRequest request) {
4345
return (request.method() == RestRequest.Method.GET) && request.path().equals("/");
4446
}
45-
46-
private boolean authBasic(final HttpRequest request){
47+
48+
private boolean authBasic(final HttpRequest request) {
4749
String authHeader = request.header("Authorization");
48-
49-
if (authHeader == null) {
50+
if (authHeader == null)
5051
return false;
51-
}
52-
53-
String[] split = authHeader.split(" ");
5452

55-
if (!split[0].equals("Basic")){
53+
String[] split = authHeader.split(" ");
54+
if (split.length < 1 || !split[0].equals("Basic"))
5655
return false;
57-
}
5856

59-
String decoded = null;
60-
57+
String decoded;
6158
try {
6259
decoded = new String(Base64.decode(split[1]));
6360
} catch (IOException e) {
6461
logger.warn("Decoding of basic auth failed.");
6562
return false;
6663
}
67-
68-
String[] user_and_password = decoded.split(":");
69-
String given_user = user_and_password[0];
70-
String given_pass = user_and_password[1];
71-
72-
if (this.user.equals(given_user) &&
73-
this.password.equals(given_pass)) {
74-
return true;
75-
} else {
76-
return false;
77-
}
64+
65+
String[] userAndPassword = decoded.split(":");
66+
String givenUser = userAndPassword[0];
67+
String givenPass = userAndPassword[1];
68+
return this.user.equals(givenUser) && this.password.equals(givenPass);
7869
}
7970
}

src/main/java/com/asquera/elasticsearch/plugins/http/HttpBasicServerModule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.asquera.elasticsearch.plugins.http;
22

3-
import org.elasticsearch.common.inject.AbstractModule;
4-
import com.asquera.elasticsearch.plugins.http.HttpBasicServer;
53
import org.elasticsearch.http.HttpServerModule;
64
import org.elasticsearch.common.settings.Settings;
75

src/main/java/com/asquera/elasticsearch/plugins/http/HttpBasicServerPlugin.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
import org.elasticsearch.common.inject.Module;
55
import org.elasticsearch.common.settings.Settings;
66
import org.elasticsearch.plugins.AbstractPlugin;
7-
import org.elasticsearch.http.HttpServerModule;
8-
import org.elasticsearch.http.HttpServer;
9-
import com.asquera.elasticsearch.plugins.http.HttpBasicServer;
10-
import com.asquera.elasticsearch.plugins.http.HttpBasicServerModule;
117
import org.elasticsearch.common.component.LifecycleComponent;
128
import org.elasticsearch.common.settings.ImmutableSettings;
139

0 commit comments

Comments
 (0)
0