0
votes

I'm using JCIFS to create a directory on a Windows remote shared directory. It doesn't fail authentication, and proceeds to invoke mkdir() method. However, folder is being creating on linux file system at the root of tomcat installation foder and not at the Windows shared directory. Not getting any exceptions.

I'm using JCIFS SMB version 1.3.19. Java app is a servlet and runs on a linux box using Tomcat. When making SMB call, as shown in code block, the app creates the directory requested, but its being created at the root of Tomcat installation directory. I'm using NtlmPasswordAuthentication before invoking mkdir() method.

public void create() {
    try {
        String smbUrl = String.format("smb://WIN-2016-AD-DNS/profiles/" + userName);
        LOGGER.info("smbUrl = " + smbUrl);

        NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(domain, "jdoe", "password");
        SmbFile dir = new SmbFile(smbUrl, auth);
        if (dir.isDirectory()) {
            LOGGER.info("Directory already exists");
        } else {
            try {
                dir.mkdir();
                LOGGER.info("Successfully created folder on share");
            } catch (Exception e) {
                logExceptionError("Failed to create Directory with SMB mkdir", e, 0);
            }
        }
    } catch (Exception e) {
        logExceptionError("Failed to create Directory with SMB", e, 0);
    }
}

...

1

1 Answers

0
votes

I finally figured out the problem. I setup my entire Tomcat server environment on a Windows platform instead of Linux to see if I would have any better luck. As it turns out I found an entry in one of the Tomcat logs...

SEVERE [ajp-nio-8009-exec-10] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [ADuser] in context with path [] threw exception [Servlet execution threw an exception] with root cause
    java.lang.ClassNotFoundException: jcifs.smb.NtlmPasswordAuthentication

Why this exception wasn't caught in my application I have no idea. So I copied the jcifs libary to Tomcats 'lib' folder, restarted Tomcat and it worked. I went back to the Linux environment and did the same thing and it worked there as well.