我需要实现一个虚拟文件系统,它将作为Windows共享进行访问.
似乎Alfresco JLan正在做这项工作.到目前为止,我从这个答案开始有一些有希望的结果:如何将alfresco jlan文件服务器设置为独立的java包?
现在,我似乎无法进行身份验证.我的虚拟实现总是成功,但是一旦我尝试验证密码,它就会失败.
一些信息:
CifsAuthenticator::validatePassword.getInstance("MD4")由MD4.getInstance()在JLan,因为它似乎是要走现代的Java平台的方式(MD4默认情况下不注册,如MD4类本身记录).如何再次检查我的密码?
我使用这两个库取得了巨大的成功。我能够对提供 SMB 共享的 Synology NAS 进行身份验证。
请注意,我使用的版本不必是最新的。
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>eu.agno3.jcifs</groupId>
<artifactId>jcifs-ng</artifactId>
<version>2.1.5</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
身份验证的代码可能如下所示:
final String smburl = ...;
final String username = ...;
final String password = ...;
final URI uri = new URI(smburl);
StaticUserAuthenticator auth = new StaticUserAuthenticator(null, username, password);
Properties jcifsProperties = new Properties();
// these settings are needed for 2.0.x to use anything but SMB1, 2.1.x enables by default and will ignore
jcifsProperties.setProperty("jcifs.smb.client.enableSMB2", "true");
jcifsProperties.setProperty("jcifs.smb.client.useSMB2Negotiation", "true");
CIFSContext jcifsContext = new BaseContext(new PropertyConfiguration(jcifsProperties));
FileSystemOptions options = new FileSystemOptions();
DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(options, auth);
SmbFileSystemConfigBuilder.getInstance().setCIFSContext(options, jcifsContext);
fsManager = VFS.getManager();
Run Code Online (Sandbox Code Playgroud)
最后使用 fsManager 将 URI 解析为 FileObjects 并执行所需的操作。
| 归档时间: |
|
| 查看次数: |
419 次 |
| 最近记录: |