尝试使用Java中的jCIFS库在Java中的Windows上读取文件。
当用户在Windows中启用了“本地登录”权限时,此部分代码可以很好地工作。但是,当我们实现密码的非过期属性时,我们的服务器团队将禁用该用户的“本地登录”权限。
现在,当我们手动浏览路径时,我们可以毫无问题地访问它。 当应用程序尝试访问路径时,在应用程序服务器上出现以下错误:
致命-jcifs.smb.SmbAuthException:登录失败:不允许用户登录到此计算机。
致命-错误消息:登录失败:不允许用户登录到此计算机。
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "domain\\"+this.userName, this.password);
String fileName = "";
String filePath = "";
while (result1.next()) {
for(int i=1; i<=columnsNumber1; i++) {
String name = rsmd1.getColumnName(i);
if(name.equals("FILE_PATH")) {
filePath = result1.getString(i);
} else if (name.equals("PDF_FILE_NAME")) {
fileName = result1.getString(i);
}
}
}
String newFilePath = filePath.replace('\\', '/');
String path = "smb:"+newFilePath+"/Stored/"+fileName;
SmbFile sFile = new SmbFile(path, auth);
try (SmbFileInputStream in = new SmbFileInputStream(sFile)) {
int bytesRead = 0;
do {
bytesRead = in.read(buffer);
}
while (bytesRead > 0);
}
byte[] encoded = Base64.getEncoder().encode(buffer);
在这种情况下,我们是否必须为NtlmPasswordAuthentication身份验证设置特定的属性? 请帮忙,卡在这里
答案 0 :(得分:0)
我找到了解决方案。如果可以帮助其他人,请在此处发布。 添加两个配置属性有助于-“ jcifs.netbios.hostname”和“ jcifs.netbios.wins”
Config.setProperty("jcifs.netbios.hostname", Messages.getString("Constants.serverHostName"));
Config.setProperty("jcifs.netbios.wins", Messages.getString("Constants.serverHostName"));
NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication(null, "edelcap\\"+this.reportUserName, this.reportPassword);