首页 > 解决方案 > 无法使用 jcifs 连接到 unc 位置

问题描述

我有一些属于同一域的远程位置。当我从 Windows 访问远程位置时,它会在不要求凭据的情况下打开。但是如果我使用 java 代码(jcifs)访问该位置,那么它会给我这个异常

jcifs.smb.SmbAuthException:登录失败:未知用户名或密码错误

Java 代码是

String path=convertToSmb(loc);
        NtlmPasswordAuthentication auth=new NtlmPasswordAuthentication(path, userName, passwd);
        SmbFile sFile=null;
        try {
            sFile=new SmbFile(path,auth);
            sFile.connect();
            boolean sFileExists = sFile.exists();
            logger.info("checkUNCLocation [END] with :: sfileExists :: "+sFileExists);
            return sFileExists;
        } catch (MalformedURLException e) {
            logger.error(e.getMessage(), e);
            return Boolean.FALSE;
        } catch (IOException e) {
            logger.error(e.getMessage(), e);
            return UNCNetworkConnectionWrapper.connectUNCNetwork(loc, userName, passwd);
        }finally{

            sFile=null;
            //jcifs.Config.setProperty("jcifs.smb.client.disablePlainTextPasswords", Boolean.TRUE.toString());
        }

我尝试使用 net use delete 删除所有连接,但 Windows 仍然没有要求提供凭据

日志记录还显示正确的凭据。请指导应该是什么原因。

标签: javauncjcifs

解决方案


您是否尝试过设置userNamepassword

Windows 如何通过尝试使用当前凭据连接服务器来做到这一点,如果您与您的用户连接并且您尝试连接到同一域中的其他计算机,则连接将成功,因为您的凭据在此域中有效.

尝试使用您自己的凭据连接到“此”服务器。


推荐阅读