I'm experiencing an issue with accessing an SMB share in both a Java application and a Node.js script. When I connect to the SMB share via CMD using a specific service account (username and password), it works flawlessly. However, when trying to access the same SMB share in my Java (using JCIFS) and Node.js applications with the same service account credentials, I encounter an "Access is Denied" error.
Here's what I've tried so far:
- Confirmed the correctness of username, password, and domain in the Java and Node.js applications.
- Checked SMB server permissions for the service account.
- Increased logging level in JCIFS to gather more details, but couldn't pinpoint the issue.
- Looked through JCIFS documentation for any potential misconfigurations.
It's puzzling why the access is successful via CMD but fails in both Java and Node.js. I'm attaching screenshots of the error and relevant code snippets for clarity. Any insights or suggestions on what might be causing this issue and how to resolve it would be greatly appreciated.
Thank you!
public FichierService() {
try {
Properties smbProps = new Properties();
smbProps.put("jcifs.smb.client.username", "XXXXXXXXXX");
smbProps.put("jcifs.smb.client.password", "XXXXXXX");
smbProps.put("jcifs.smb.client.domain", "xxxxx.com");
Configuration config = new PropertyConfiguration(smbProps);
cifsContext = new BaseContext(config);
System.out.println("CIFS context initialized");
} catch (CIFSException e) {
e.printStackTrace();
}
}
public byte[] recupererFichiersZip(List<Long> audrosIds) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ZipOutputStream zos = new ZipOutputStream(baos);
System.out.println("Starting to process files...");
for (Long audrosId : audrosIds) {
List<Object[]> resultList = repository.findFilesByIdAttach(Collections.singletonList(audrosId));
if (!resultList.isEmpty()) {
Object[] fileData = resultList.get(0);
String chemin = (String) fileData[0];
String namefile= "236973_NSA_2110_H.pdf";
String smbPath = "smb://srvptzxx.xxxx/Test_partage/xxxx/" + namefile;
System.out.println(smbPath);
try {
SmbFile smbFile = new SmbFile(smbPath, cifsContext);
System.out.println(smbFile);
if (smbFile.exists()) {
System.out.println("File exists: " + smbPath);
SmbFileInputStream smbStream = new SmbFileInputStream(smbFile);
ZipEntry entry = new ZipEntry(nomfich);
zos.putNextEntry(entry);
byte[] buffer = new byte[1024];
int length;
while ((length = smbStream.read(buffer)) > 0) {
zos.write(buffer, 0, length);
}
zos.closeEntry();
smbStream.close();
} else {
System.out.println("Le fichier n'existe pas ou ne peut pas être lu : " + smbPath);
}
} catch (Exception e) {
System.out.println("Erreur lors de l'accès au fichier : " + smbPath);
e.printStackTrace();
}
}
}
try {
zos.close();
} catch (IOException e) {
System.out.println("Erreur lors de la fermeture du flux ZipOutputStream.");
e.printStackTrace();
}
return baos.toByteArray();
}
and here the log
I have no more ideas to solve this problem I tried with or without domain name