使用 Apache VFS 的 NTLM 身份验证

NTLM authentication with Apache VFS

我正在尝试使用 Apache VFS 读取安装为网络驱动器的 SharePoint 2013 中的文件。我使用下面的代码

        try {
        StandardFileSystemManager manager = new StandardFileSystemManager();
        manager.addProvider("http", new WebdavFileProvider());
        manager.setCacheStrategy(CacheStrategy.ON_CALL);
        manager.setFilesCache(new SoftRefFilesCache());
        FileObject fileObject = manager.resolveFile("http://sp2013w2k12r2/PuneetsLibrary/");
        System.out.println(fileObject.getFileSystem().hasCapability(Capability.LIST_CHILDREN));
        System.out.println(fileObject.isFolder());
    } catch (FileSystemException e) {
        e.printStackTrace();
    }

但我收到以下错误

org.apache.commons.httpclient.auth.AuthChallengeProcessor selectAuthScheme INFO: ntlm authentication scheme selected Aug 03, 2016 5:29:55 PM org.apache.commons.httpclient.HttpMethodDirector processWWWAuthChallenge INFO: No credentials available for NTLM @sp2013w2k12r2:80 org.apache.commons.vfs2.FileSystemException: Could not determine the type of file "http://sp2013w2k12r2/PuneetsLibrary". at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1526) at org.apache.commons.vfs2.provider.AbstractFileObject.isFolder(AbstractFileObject.java:1726) at org.apache.commons.vfs2.impl.DecoratedFileObject.isFolder(DecoratedFileObject.java:211) at SharePointVFSMain.main(SharePointVFSMain.java:18) Caused by: org.apache.commons.vfs2.FileSystemException: Unknown message with code "Unauthorized". at org.apache.commons.vfs2.provider.webdav.ExceptionConverter.generate(ExceptionConverter.java:88) at org.apache.commons.vfs2.provider.webdav.ExceptionConverter.generate(ExceptionConverter.java:41) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.execute(WebdavFileObject.java:594) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.getProperties(WebdavFileObject.java:632) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.getProperties(WebdavFileObject.java:620) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.getProperty(WebdavFileObject.java:664) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.getProperty(WebdavFileObject.java:671) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.isDirectory(WebdavFileObject.java:716) at org.apache.commons.vfs2.provider.webdav.WebdavFileObject.doGetType(WebdavFileObject.java:405) at org.apache.commons.vfs2.provider.AbstractFileObject.getType(AbstractFileObject.java:1517) ... 3 more

我意识到必须要做的事情。 java 进程如果 运行 具有对 SharePoint 站点具有权限的用户的凭据,则能够读取文档。