From 202236d04012c39ec299866203864f69bbc61ab0 Mon Sep 17 00:00:00 2001 From: ThisaraWeerakoon Date: Thu, 1 Oct 2026 10:04:56 +0530 Subject: [PATCH] Mask credentials in remaining VFS transport log and fault messages. --- .../transport/vfs/VFSOutTransportInfo.java | 2 +- .../transport/vfs/VFSTransportListener.java | 64 +++++++++++-------- .../transport/vfs/VFSTransportSender.java | 5 +- .../synapse/transport/vfs/VFSUtils.java | 7 +- 4 files changed, 47 insertions(+), 31 deletions(-) diff --git a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSOutTransportInfo.java b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSOutTransportInfo.java index 7c2e0b889..b1d35b01a 100644 --- a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSOutTransportInfo.java +++ b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSOutTransportInfo.java @@ -94,7 +94,7 @@ public class VFSOutTransportInfo implements OutTransportInfo { } if (log.isDebugEnabled()) { - log.debug("Using the fileURI : " + this.outFileURI); + log.debug("Using the fileURI : " + VFSUtils.maskURLPassword(this.outFileURI)); log.debug("Using the maxRetryCount : " + maxRetryCount); log.debug("Using the reconnectionTimeout : " + reconnectTimeout); log.debug("Using the append : " + append); diff --git a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java index 881e9ba0b..4eb06cb21 100644 --- a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java +++ b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportListener.java @@ -244,7 +244,8 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { moveOrDeleteAfterProcessing(entry, fileObject); } catch (AxisFault axisFault) { - logException("File object '" + fileObject.getURL().toString() + "' " + + logException("File object '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + "' " + "cloud not be moved", axisFault); entry.setLastPollState(PollTableEntry.FAILED); String timeStamp = @@ -254,8 +255,10 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { if (entry.isFileLockingEnabled()) { VFSUtils.releaseLock(fsManager, fileObject); if (log.isDebugEnabled()) { - log.debug("Removed the lock file '" + fileObject.toString() + - ".lock' of the file '" + fileObject.toString()); + log.debug("Removed the lock file '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + + ".lock' of the file '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI())); } } } else if (log.isDebugEnabled()) { @@ -271,7 +274,9 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { workerPool.execute(new FileRemoveTask(entry, fileObject)); } if (log.isDebugEnabled()) { - log.debug("File '" + fileObject.getURL() + "' has been marked as a failed" + + log.debug("File '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + + "' has been marked as a failed" + " record, it will not process"); } } @@ -304,7 +309,8 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { //process the file try { if (log.isDebugEnabled()) { - log.debug("Processing file :" + child); + log.debug("Processing file :" + + VFSUtils.maskURLPassword(child.getName().getURI())); } processFile(entry, child); successCount++; @@ -324,7 +330,8 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { try { moveOrDeleteAfterProcessing(entry, child); } catch (AxisFault axisFault) { - logException("File object '" + child.getURL().toString() + + logException("File object '" + + VFSUtils.maskURLPassword(child.getName().getURI()) + "'cloud not be moved", axisFault); failCount++; entry.setLastPollState(PollTableEntry.FAILED); @@ -355,7 +362,8 @@ private void scanFileOrDirectory(final PollTableEntry entry, String fileURI) { workerPool.execute(new FileRemoveTask(entry, child)); } if (log.isDebugEnabled()) { - log.debug("File '" + fileObject.getURL() + + log.debug("File '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + "' has been marked as a failed record, it will not " + "process"); } @@ -430,27 +438,32 @@ private void moveOrDeleteAfterProcessing(final PollTableEntry entry, FileObject try { fileObject.moveTo(dest); } catch (FileSystemException e) { - handleException("Error moving file : " + fileObject + " to " + moveToDirectoryURI, e); + handleException("Error moving file : " + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + " to " + + VFSUtils.maskURLPassword(moveToDirectoryURI), e); } } else { try { if (log.isDebugEnabled()) { - log.debug("Deleting file :" + fileObject); + log.debug("Deleting file :" + + VFSUtils.maskURLPassword(fileObject.getName().getURI())); } fileObject.close(); if (!fileObject.delete()) { - String msg = "Cannot delete file : " + fileObject; + String msg = "Cannot delete file : " + + VFSUtils.maskURLPassword(fileObject.getName().getURI()); log.error(msg); throw new AxisFault(msg); } } catch (FileSystemException e) { - log.error("Error deleting file : " + fileObject, e); + log.error("Error deleting file : " + + VFSUtils.maskURLPassword(fileObject.getName().getURI()), e); } } } catch (FileSystemException e) { log.error("Error resolving directory to move after processing : " - + moveToDirectoryURI, e); + + VFSUtils.maskURLPassword(moveToDirectoryURI), e); } } @@ -576,11 +589,14 @@ private void processFile(PollTableEntry entry, FileObject file) throws AxisFault } if (log.isDebugEnabled()) { - log.debug("Processed file : " + file + " of Content-type : " + contentType); + log.debug("Processed file : " + + VFSUtils.maskURLPassword(file.getName().getURI()) + + " of Content-type : " + contentType); } } catch (FileSystemException e) { - handleException("Error reading file content or attributes : " + file, e); + handleException("Error reading file content or attributes : " + + VFSUtils.maskURLPassword(file.getName().getURI()), e); } finally { try { @@ -680,14 +696,10 @@ public void run() { removeTaskState = STATE_STOPPED; } catch (AxisFault axisFault) { removeTaskState = STATE_RUNNING; - try { - log.error("Remove attempt '" + (count++) + "' failed for the file '" + - failedFileObject.getURL().toString() + "', next re-try will be " + - "after '" + nextRetryDuration + "' milliseconds"); - } catch (FileSystemException e) { - log.error("Error while retrying the file url of the file object '" + - failedFileObject + "'"); - } + log.error("Remove attempt '" + (count++) + "' failed for the file '" + + VFSUtils.maskURLPassword(failedFileObject.getName().getURI()) + + "', next re-try will be after '" + nextRetryDuration + + "' milliseconds"); try { Thread.sleep(nextRetryDuration); } catch (InterruptedException ignore) { @@ -720,11 +732,13 @@ private synchronized void reTryFailedMove(PollTableEntry entry, FileObject fileO try { fileObject.moveTo(dest); } catch (FileSystemException e) { - handleException("Error moving the failed file : " + fileObject + " to " + - moveToDirectoryURI, e); + handleException("Error moving the failed file : " + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + " to " + + VFSUtils.maskURLPassword(moveToDirectoryURI), e); } } catch (FileSystemException e) { - handleException("Cloud not move the failed file object '" + fileObject + "'", e); + handleException("Cloud not move the failed file object '" + + VFSUtils.maskURLPassword(fileObject.getName().getURI()) + "'", e); } catch (IOException e) { handleException("Cloud not create the folder", e); } diff --git a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java index d2f30f4de..5b85f2c00 100644 --- a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java +++ b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSTransportSender.java @@ -211,7 +211,8 @@ public void sendMessage(MessageContext msgCtx, String targetAddress, } } else { handleException("Unsupported reply file type : " + replyFile.getType() + - " for file : " + vfsOutInfo.getOutFileURI()); + " for file : " + + VFSUtils.maskURLPassword(vfsOutInfo.getOutFileURI())); } } else { if (isUseTempFile) { @@ -237,7 +238,7 @@ public void sendMessage(MessageContext msgCtx, String targetAddress, } } catch (FileSystemException e) { handleException("Error resolving reply file : " + - vfsOutInfo.getOutFileURI(), e); + VFSUtils.maskURLPassword(vfsOutInfo.getOutFileURI()), e); } finally { if (replyFile != null) { try { diff --git a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java index b064ee7aa..a38507609 100644 --- a/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java +++ b/modules/transports/core/vfs/src/main/java/org/apache/synapse/transport/vfs/VFSUtils.java @@ -129,7 +129,8 @@ public synchronized static boolean acquireLock(FileSystemManager fsManager, File FileObject lockObject = fsManager.resolveFile(fullPath + ".lock"); if (lockObject.exists()) { log.debug("There seems to be an external lock, aborting the processing of the file " - + fo.getName() + ". This could possibly be due to some other party already " + + maskURLPassword(fo.getName().getURI()) + + ". This could possibly be due to some other party already " + "processing this file or the file is still being uploaded"); } else { @@ -144,7 +145,7 @@ public synchronized static boolean acquireLock(FileSystemManager fsManager, File } catch (IOException e) { lockObject.delete(); log.error("Couldn't create the lock file before processing the file " - + fullPath, e); + + maskURLPassword(fullPath), e); return false; } finally { lockObject.close(); @@ -191,7 +192,7 @@ public static void releaseLock(FileSystemManager fsManager, FileObject fo) { } } catch (FileSystemException e) { log.error("Couldn't release the lock for the file : " - + fo.getName() + " after processing"); + + maskURLPassword(fo.getName().getURI()) + " after processing"); } }