-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #21, Authentication not passed properly into wagon when using enc…
…ryption in settings.xml
- Loading branch information
Showing
16 changed files
with
314 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
invoker.goals = clean verify | ||
invoker.failureBehavior = fail-at-end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.honton.chas</groupId> | ||
<artifactId>exists-it-parent</artifactId> | ||
<version>0.2.0</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>exists-deploy-with-encrypted-auth-it</artifactId> | ||
|
||
<distributionManagement> | ||
|
||
<repository> | ||
<id>test</id> | ||
<url>http://localhost:${deploy.webserver.port}/repo</url> | ||
</repository> | ||
|
||
<snapshotRepository> | ||
<id>test</id> | ||
<url>http://localhost:${deploy.webserver.port}/repo</url> | ||
</snapshotRepository> | ||
|
||
</distributionManagement> | ||
|
||
<properties> | ||
<deploy.webserver.port>@deploy.webserver.port@</deploy.webserver.port> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.nanohttpd</groupId> | ||
<artifactId>nanohttpd</artifactId> | ||
<version>2.3.1</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
|
||
<plugin> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>classpath</id> | ||
<goals> | ||
<goal>build-classpath</goal> | ||
</goals> | ||
<phase>validate</phase> | ||
<configuration> | ||
<includeScope>runtime</includeScope> | ||
<outputProperty>runtime.classpath</outputProperty> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<artifactId>maven-deploy-plugin</artifactId> | ||
<executions> | ||
<!-- deploy in earlier than usual phase --> | ||
<execution> | ||
<goals> | ||
<goal>deploy</goal> | ||
</goals> | ||
<phase>integration-test</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.honton.chas</groupId> | ||
<artifactId>exists-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>before-installation-with-encrypted-auth</id> | ||
<goals> | ||
<goal>remote</goal> | ||
</goals> | ||
<phase>test</phase> | ||
<configuration> | ||
<repository>http://localhost:${deploy.webserver.port}/auth/repo</repository> | ||
<serverId>with-encrypted-auth</serverId> | ||
</configuration> | ||
</execution> | ||
|
||
<execution> | ||
<id>after-installation-with-encrypted-auth</id> | ||
<goals> | ||
<goal>remote</goal> | ||
</goals> | ||
<phase>integration-test</phase> | ||
<configuration> | ||
<repository>http://localhost:${deploy.webserver.port}/auth/repo</repository> | ||
<serverId>with-encrypted-auth</serverId> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.honton.chas</groupId> | ||
<artifactId>process-exec-maven-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>start</goal> | ||
</goals> | ||
<phase>process-test-classes</phase> | ||
<configuration> | ||
<waitAfterLaunch>2</waitAfterLaunch> | ||
<arguments> | ||
<argument>${java.home}/bin/java</argument> | ||
<argument>-classpath</argument> | ||
<argument>${runtime.classpath}${path.separator}${project.build.outputDirectory}</argument> | ||
<argument>org.honton.chas.exists.example.WebServer</argument> | ||
<argument>${deploy.webserver.port}</argument> | ||
</arguments> | ||
</configuration> | ||
</execution> | ||
|
||
<execution> | ||
<id>stop-all</id> | ||
<goals> | ||
<goal>stop-all</goal> | ||
</goals> | ||
<phase>post-integration-test</phase> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
|
||
</plugins> | ||
|
||
</build> | ||
|
||
</project> |
107 changes: 107 additions & 0 deletions
107
...it/deploy-with-encrypted-auth/src/main/java/org/honton/chas/exists/example/WebServer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package org.honton.chas.exists.example; | ||
|
||
import fi.iki.elonen.NanoHTTPD; | ||
import fi.iki.elonen.NanoHTTPD.Response.Status; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.logging.Logger; | ||
|
||
public class WebServer extends NanoHTTPD { | ||
private static final Logger LOG = Logger.getLogger(WebServer.class.getName()); | ||
|
||
private static final Map<String, String> TYPES = new HashMap<>(); | ||
static { | ||
TYPES.put("jar", "application/java-archive"); | ||
TYPES.put("asc", "text/plain"); | ||
TYPES.put("pom", "text/xml"); | ||
} | ||
|
||
private Map<String, byte[]> storage = new HashMap<>(); | ||
|
||
public WebServer(int port) throws IOException { | ||
super(port); | ||
LOG.fine("Server running on port " + port); | ||
start(NanoHTTPD.SOCKET_READ_TIMEOUT, false); | ||
} | ||
|
||
public static void main(String[] args) throws IOException { | ||
new WebServer(Integer.parseInt(args[0])); | ||
} | ||
|
||
byte[] getInput(IHTTPSession session) throws IOException { | ||
int length = Integer.parseInt(getHeader(session, "Content-Length")); | ||
byte[] content = new byte[length]; | ||
session.getInputStream().read(content); | ||
return content; | ||
} | ||
|
||
private String getHeader(IHTTPSession session, String key) { | ||
for(Map.Entry<String, String> header : session.getHeaders().entrySet()) { | ||
if(header.getKey().equalsIgnoreCase(key)) { | ||
return header.getValue(); | ||
} | ||
} return null; | ||
} | ||
|
||
@Override | ||
public Response serve(IHTTPSession session) { | ||
LOG.fine(session.getMethod() + " " + session.getUri()); | ||
Response response = generateResponse(session); | ||
LOG.fine("Response: " + response.getStatus()); | ||
return response; | ||
} | ||
|
||
private Response generateResponse(IHTTPSession session) { | ||
String uri = session.getUri(); | ||
if (uri.startsWith("/auth")) { | ||
String authorization = session.getHeaders().get("authorization"); | ||
if (authorization == null || !authorization.equals("Basic dXNlcjE6cGFzc3dvcmQxMjM=")) { | ||
Response response = NanoHTTPD.newFixedLengthResponse(Status.UNAUTHORIZED, "", null); | ||
response.addHeader("WWW-Authenticate", "Basic realm=\"Authentication needed\""); | ||
return response; | ||
} | ||
uri = uri.substring("/auth".length()); | ||
} | ||
String type = getType(uri); | ||
switch (session.getMethod()) { | ||
case HEAD: { | ||
if (!storage.containsKey(uri)) { | ||
return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, type, null); | ||
} | ||
return NanoHTTPD.newFixedLengthResponse(Status.OK, type, null); | ||
} | ||
case GET: { | ||
byte[] file = storage.get(uri); | ||
if (file == null) { | ||
return NanoHTTPD.newFixedLengthResponse(Status.NOT_FOUND, type, uri); | ||
} | ||
return newFixedLengthResponse(Status.OK, type, new ByteArrayInputStream(file), (long)file.length); | ||
} | ||
case PUT: { | ||
try { | ||
storage.put(uri, getInput(session)); | ||
return NanoHTTPD.newFixedLengthResponse(Status.OK, "", uri); | ||
} | ||
catch (IOException e) { | ||
return NanoHTTPD.newFixedLengthResponse(Status.INTERNAL_ERROR, "text/plain", e.getMessage()); | ||
} | ||
} | ||
default: | ||
return NanoHTTPD.newFixedLengthResponse(Status.NOT_IMPLEMENTED, "text/plain", session.getMethod() + " not supported"); | ||
} | ||
} | ||
|
||
private String getType(String uri) { | ||
int dot = uri.lastIndexOf('.'); | ||
if (dot == -1) { | ||
return "text/plain"; | ||
} else { | ||
String suffix = uri.substring(dot + 1); | ||
String type = TYPES.get(suffix); | ||
return type != null ? type : "text/" + suffix; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
|
||
void findLine(BufferedReader reader, String expected) { | ||
for(;;) { | ||
String line = reader.readLine(); | ||
if(line == null) { | ||
throw new IllegalStateException(expected + " not found"); | ||
} | ||
if(line.matches(expected)) { | ||
return; | ||
} | ||
} | ||
} | ||
|
||
File file = new File(basedir, "build.log" ); | ||
BufferedReader reader = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8); | ||
|
||
findLine(reader, "\\[INFO\\] --- exists-maven-plugin:[0-9\\.]*:remote \\(before-installation-with-encrypted-auth\\) @ exists-deploy-with-encrypted-auth-it ---"); | ||
findLine(reader, "\\[INFO\\] org.honton.chas:exists-deploy-with-encrypted-auth-it:[0-9\\.]* does not exist"); | ||
|
||
findLine(reader, "\\[INFO\\] --- exists-maven-plugin:[0-9\\.]*:remote \\(after-installation-with-encrypted-auth\\) @ exists-deploy-with-encrypted-auth-it ---"); | ||
findLine(reader, "\\[INFO\\] setting maven.deploy.skip=true"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.