10000 W-18470687 | Fixes sonarr issues by kartik-sharma-sf · Pull Request #648 · mulesoft/mule-sftp-connector · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

W-18470687 | Fixes sonarr issues #648

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occas 8000 ionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 13, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

# Maven
target/
dependency-reduced-pom.xml


# Eclipse files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
package org.mule.extension.sftp.internal.auth;

import java.io.Closeable;
import java.io.IOException;

import org.ietf.jgss.GSSException;

/**
* An {@code AuthenticationHandler} encapsulates a possibly multi-step
Expand Down Expand Up @@ -43,18 +46,18 @@ public interface AuthenticationHandler<ParameterType, TokenType>
* Produces the initial authentication token that can be then retrieved via
* {@link #getToken()}.
*
* @throws Exception
* @throws GSSException
* if an error occurs
*/
void start() throws Exception;
void start() throws GSSException;

/**
* Produces the next authentication token, if any.
*
* @throws Exception
* if an error occurs
* @throws IOException if an error occurs
* @throws GSSException if an error occurs
*/
void process() throws Exception;
void process() throws IOException, GSSException;

/**
* Sets the parameters for the next token generation via {@link #start()} or
Expand All @@ -69,10 +72,10 @@ public interface AuthenticationHandler<ParameterType, TokenType>
* Retrieves the last token generated.
*
* @return the token, or {@code null} if there is none
* @throws Exception
* @throws IOException
* if an error occurs
*/
TokenType getToken() throws Exception;
TokenType getToken() throws IOException;

/**
* Tells whether is authentication mechanism is done (successfully or
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import static java.nio.charset.StandardCharsets.UTF_8;

import java.io.IOException;
import java.net.Authenticator;
import java.net.Authenticator.RequestorType;
import java.net.InetSocketAddress;
Expand All @@ -20,7 +21,6 @@
import java.util.Arrays;
import java.util.concurrent.CancellationException;


/**
* An abstract implementation of a username-password authentication. It can be
* given an initial known username-password pair; if so, this will be tried
Expand Down Expand Up @@ -92,7 +92,7 @@ public final void close() {
}

@Override
public final void start() throws Exception {
public final void start() {
if ((user != null && !user.isEmpty())
|| (password != null && password.length > 0)) {
return;
Expand All @@ -101,7 +101,7 @@ public final void start() throws Exception {
}

@Override
public void process() throws Exception {
public void process() throws IOException {
askCredentials();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.net.InetSocketAddress;

import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;

/**
* An abstract implementation of a GSS-API multi-round authentication.
Expand Down Expand Up @@ -49,7 +50,7 @@ public void close() {
}

@Override
public final void start() throws Exception {
public final void start() throws GSSException {
try {
context = createContext();
context.requestMutualAuth(true);
Expand All @@ -64,7 +65,7 @@ public final void start() throws Exception {
}

@Override
public final void process() throws Exception {
public final void process() throws IOException, GSSException {
if (context == null) {
throw new IOException(format("Cannot authenticate to proxy %s", proxy));
}
Expand All @@ -78,7 +79,7 @@ public final void process() throws Exception {
}
}

private void checkDone() throws Exception {
private void checkDone() throws GSSException {
done = context.isEstablished();
if (done) {
context.dispose();
Expand All @@ -90,20 +91,18 @@ private void checkDone() throws Exception {
* Creates the {@link org.ietf.jgss.GSSContext} to use.
*
* @return a fresh {@link org.ietf.jgss.GSSContext} to use
* @throws Exception
* if the context cannot be created
*/
protected abstract GSSContext createContext() throws Exception;
protected abstract GSSContext createContext();

/**
* Extracts the token from the last set parameters.
*
* @param input
* to extract the token from
* @return the extracted token, or {@code null} if none
* @throws Exception
* @throws IOException
* if an error occurs
*/
protected abstract byte[] extractToken(ParameterType input)
throws Exception;
throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;

import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;

/**
* Simple HTTP proxy connector using Basic Authentication.
Expand Down Expand Up @@ -108,7 +109,7 @@ private void close() {

@Override
public void sendClientProxyMetadata(ClientSession sshSession)
throws Exception {
throws ProxyConnectionException, IOException, GSSException {
init(sshSession);
IoSession session = sshSession.getIoSession();
session.addCloseFutureListener(f -> close());
Expand Down Expand Up @@ -244,7 +245,7 @@ private void handleMessage(IoSession session, List<String> reply)
private HttpAuthenticationHandler selectProtocol(
List<AuthenticationChallenge> challenges,
HttpAuthenticationHandler current)
throws Exception {
throws IOException, GSSException {
if (current != null && !current.isDone()) {
AuthenticationChallenge challenge = getByName(challenges,
current.getName());
Expand Down Expand Up @@ -318,7 +319,7 @@ protected void askCredentials() {
}

@Override
public String getToken() throws Exception {
public String getToken() throws IOException {
if (user.indexOf(':') >= 0) {
throw new IOException(format(
"HTTP Proxy connection to {0} failed with code {1}: {2}", proxy, user));
Expand Down Expand Up @@ -354,19 +355,18 @@ public String getName() {
}

@Override
public String getToken() throws Exception {
public String getToken() throws IOException {
return getName() + ' ' + Base64.encodeBytes(token);
}

@Override
protected GSSContext createContext() throws Exception {
protected GSSContext createContext() {
return GssApiMechanisms.createContext(GssApiMechanisms.SPNEGO,
GssApiMechanisms.getCanonicalName(proxyAddress));
}

@Override
protected byte[] extractToken(AuthenticationChallenge input)
throws Exception {
protected byte[] extractToken(AuthenticationChallenge input) {
String received = input.getToken();
if (received == null) {
return new byte[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.sshd.common.util.buffer.ByteArrayBuffer;

import org.ietf.jgss.GSSContext;
import org.ietf.jgss.GSSException;

/**
* A {@link AbstractClientProxyConnector} to connect through a SOCKS5 proxy.
Expand All @@ -38,12 +39,9 @@
@SuppressWarnings("java:S112")
public class Socks5ClientConnector extends AbstractClientProxyConnector {

// private static final byte SOCKS_VERSION_4 = 4;
private static final byte SOCKS_VERSION_5 = 5;

private static final byte SOCKS_CMD_CONNECT = 1;
// private static final byte SOCKS5_CMD_BIND = 2;
// private static final byte SOCKS5_CMD_UDP_ASSOCIATE = 3;

// Address types

Expand Down Expand Up @@ -255,7 +253,7 @@ private byte[] getAuthenticationProposals() {
return result;
}

private void sendConnectInfo(IoSession session) throws Exception {
private void sendConnectInfo(IoSession session) throws IOException {
GssApiMechanisms.closeContextSilently(context);

byte[] rawAddress = getRawAddress(remoteAddress);
Expand Down Expand Up @@ -323,7 +321,7 @@ private void close() {
}
}

private void startAuth(IoSession session) throws Exception {
private void startAuth(IoSession session) throws IOException, GSSException {
Buffer buffer = null;
try {
authenticator.setParams(null);
Expand Down Expand Up @@ -430,7 +428,7 @@ public void messageReceived(IoSession session, Readable buffer)
}
}

private void versionCheck(byte version) throws Exception {
private void versionCheck(byte version) throws IOException {
if (version != SOCKS_VERSION_5) {
throw new IOException(
format("Expected SOCKS version 5, got {0}",
Expand Down Expand Up @@ -484,7 +482,7 @@ public SocksBasicAuthentication() {
}

@Override
public void process() throws Exception {
public void process() throws IOException {
// Retries impossible. RFC 1929 specifies that the server MUST
// close the connection if authentication is unsuccessful.
done = true;
Expand Down Expand Up @@ -551,12 +549,12 @@ public SocksGssApiAuthentication() {
}

@Override
protected GSSContext createContext() throws Exception {
protected GSSContext createContext() {
return context;
}

@Override
public Buffer getToken() throws Exception {
public Buffer getToken() {
if (token == null) {
return null;
}
Expand All @@ -570,9 +568,9 @@ public Buffer getToken() throws Exception {
}

@Override
protected byte[] extractToken(Buffer input) throws Exception {
protected byte[] extractToken(Buffer input) throws IOException {
if (context == null) {
return null;
return new byte[0];
}
int version = input.getUByte();
if (version != SOCKS5_GSSAPI_VERSION) {
Expand All @@ -585,7 +583,7 @@ protected byte[] extractToken(Buffer input) throws Exception {
throw new IOException(format("Cannot authenticate with GSS-API to SOCKS5 proxy {0}", remoteAddress));
} else if (msgType != SOCKS5_GSSAPI_TOKEN) {
throw new IOException(format(
"",
"Connection failed to {0} with message type 0x{1}",
remoteAddress, Integer.toHexString(msgType & 0xFF)));
}
if (input.available() >= 2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void validateSelf() throws IllegalArgumentException {
}
}

public void apply(AbstractFileSystem fileSystem, FileAttributes fileAttributes, FileConnectorConfig config) {
public void apply(AbstractFileSystem<FileAttributes> fileSystem, FileAttributes fileAttributes, FileConnectorConfig config) {
logTraceValidation();

boolean movedOrRenamed = false;
Expand Down
C3B7
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public void poll(PollContext<InputStream, SftpFileAttributes> pollContext) {
}
SftpFileSystemConnection fileSystem;
try {
fileSystem = openConnection(pollContext);
fileSystem = openConnection();
} catch (Exception e) {
LOGGER.error(format("Could not obtain connection while trying to poll directory '%s'. %s", directoryUri.getPath(),
e.getMessage()),
Expand Down Expand Up @@ -314,20 +314,10 @@ private void refreshMatcher() {
fileAttributePredicate = predicateBuilder != null ? predicateBuilder.build() : new NullFilePayloadPredicate<>();
}

private SftpFileSystemConnection openConnection(PollContext pollContext) throws Exception {

private SftpFileSystemConnection openConnection()
throws ConnectionException {
SftpFileSystemConnection fileSystem = fileSystemProvider.connect();
try {
fileSystem.changeToBaseDir();
} catch (Exception e) {
LOGGER.debug("Exception while trying to open connection. Cause: {} . Message: {}", e.getCause(), e.getMessage());
if (extractConnectionException(e).isPresent()) {
extractConnectionException(e).ifPresent(pollContext::onConnectionException);
} else {
fileSystemProvider.disconnect(fileSystem);
}
throw e;
}
fileSystem.changeToBaseDir();
return fileSystem;
}

Expand All @@ -341,25 +331,17 @@ private PollItemStatus processFile(Result<InputStream, SftpFileAttributes> file,
}
PollItemStatus status = pollContext.accept(item -> {
final SourceCallbackContext ctx = item.getSourceCallbackContext();
Result result = null;

try {
ctx.addVariable(ATTRIBUTES_CONTEXT_VAR, attributes);
item.setResult(file).setId(attributes.getPath());

if (watermarkEnabled) {
item.setWatermark(attributes.getTimestamp());
}
} catch (Throwable t) {
LOGGER.error(format("Found file '%s' but found exception trying to dispatch it for processing. %s",
fullPath, t.getMessage()),
t);

if (result != null) {
onRejectedItem(result, ctx);
}

throw new MuleRuntimeException(t);
} catch (Exception e) {
I18nMessage message =
createStaticMessage(format("Found file '%s' but found exception trying to dispatch it for processing", fullPath));
throw new MuleRuntimeException(message, e);
}
});

Expand Down Expand Up @@ -411,7 +393,6 @@ private URI resolveRootPath() {
I18nMessage message = createStaticMessage(
format("Could not resolve path to directory '%s'. %s",
directory, e.getMessage()));
LOGGER.error(message.getMessage(), e);
throw new MuleRuntimeException(message, e);
}
}
Expand Down Expand Up @@ -441,11 +422,11 @@ private void updateConnectionMaps(String filepath, SftpFileSystemConnection file
private SftpFileSystemConnection cleanUpAndReconnectFilesystem(
PollContext<InputStream, SftpFileAttributes> pollContext,
SftpFileSystemConnection fileSystem)
throws Exception {
throws ConnectionException {
LOGGER.warn("SFTP channel is closed. Attempting to reconnect and retry...");
// Disconnect and cleanup
fileSystem.disconnect();
// Get a new connection and return it
return openConnection(pollContext);
return openConnection();
}
}
Loading
0