Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import java.net.SocketAddress;
import java.net.URL;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Properties;
import java.util.regex.Matcher;
Expand All @@ -53,7 +54,6 @@
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.resource.Resource;
import org.apache.maven.wagon.shared.http.EncodingUtil;
import org.codehaus.plexus.util.Base64;

import static java.lang.Integer.parseInt;
import static org.apache.maven.wagon.shared.http.HttpMessageUtils.UNKNOWN_STATUS_CODE;
Expand Down Expand Up @@ -201,7 +201,7 @@ private void addHeaders(HttpURLConnection urlConnection) {
private void setAuthorization(HttpURLConnection urlConnection) {
if (preemptiveAuthentication && authenticationInfo != null && authenticationInfo.getUserName() != null) {
String credentials = authenticationInfo.getUserName() + ":" + authenticationInfo.getPassword();
String encoded = new String(Base64.encodeBase64(credentials.getBytes()));
String encoded = Base64.getEncoder().encodeToString(credentials.getBytes());
urlConnection.setRequestProperty("Authorization", "Basic " + encoded);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
package org.apache.maven.wagon.providers.ssh.knownhost;

import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;

import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.StringOutputStream;
import org.codehaus.plexus.util.StringUtils;

/**
Expand All @@ -38,18 +37,17 @@
public class StreamKnownHostsProvider extends AbstractKnownHostsProvider {

public StreamKnownHostsProvider(InputStream stream) throws IOException {
try {
StringOutputStream stringOutputStream = new StringOutputStream();
IOUtil.copy(stream, stringOutputStream);

stream.close();
stream = null;
try (InputStream in = stream) {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] chunk = new byte[4096];
int read;
while ((read = in.read(chunk)) != -1) {
buffer.write(chunk, 0, read);
}

this.contents = stringOutputStream.toString();
this.contents = buffer.toString();

this.knownHosts = this.loadKnownHosts(this.contents);
} finally {
IOUtil.close(stream);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand Down Expand Up @@ -73,7 +74,6 @@
import org.apache.maven.wagon.providers.ssh.knownhost.UnknownHostException;
import org.apache.maven.wagon.proxy.ProxyInfo;
import org.apache.maven.wagon.resource.Resource;
import org.codehaus.plexus.util.IOUtil;

/**
* AbstractJschWagon
Expand Down Expand Up @@ -371,14 +371,24 @@ public Streams executeCommand(String command, boolean ignoreStdErr, boolean igno
fireSessionDebug("Stderr results:" + streams.getErr());
}

IOUtil.close(stdoutReader);
IOUtil.close(stderrReader);
closeQuietly(stdoutReader);
closeQuietly(stderrReader);
if (channel != null) {
channel.disconnect();
}
}
}

private static void closeQuietly(Closeable closeable) {
if (closeable != null) {
try {
closeable.close();
} catch (IOException e) {
// ignored, as IOUtil.close did before
}
}
}

protected void handleGetException(Resource resource, Exception e) throws TransferFailedException {
fireTransferError(resource, e, TransferEvent.REQUEST_GET);

Expand Down
Loading