JCIFS 如何在与所有人共享文件夹时进行身份验证? [英] JCIFS How to authenciate when folder is shared with Everyone?

查看:212
本文介绍了JCIFS 如何在与所有人共享文件夹时进行身份验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个场景,我们与组Everyone(我认为包括您域中的所有用户)共享一个文件夹

we have a scenario in which we are sharing a folder with group Everyone (which I think includes all users from your domain)

当我们在 Win+R 中使用 \\server-ip\sharedFolder 时,我们可以连接到该文件夹​​并无需任何密码即可浏览(我的计算机使用同一域中的用户登录)

when we are using \\server-ip\sharedFolder in Win+R we are able to connect to the folder and browse with out any password (my computer is logged in using a user on same domain)

当我使用这样的 File 类在 Java 应用程序中对其进行编码时

when I code it in java application using File class like this

File f = new File(\\server-ip\sharedFolder);

File f = new File(\\server-ip\sharedFolder );

它也能工作,但我想让我的应用程序也能在 mac/linux 上工作,所以我试图为此目的使用 JCIFS.但是,当访客帐户也无法显示时,我在验证应该使用什么作为用户名和密码时遇到问题.我试过

it works then also, But I want to make my application work on mac/linux also so I am trying to use JCIFS for this purpose. But I am having issues while authenticating what should I use as username and password when guest account is also out of picture. I tried

package test;

import java.net.MalformedURLException;

import jcifs.smb.NtlmAuthenticator;
import jcifs.smb.NtlmPasswordAuthentication;
import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

public class JCIFSTest {
    public static void main(String args[]){
        String user = "";
        String pass ="";

        String sharedFolder="sup";
        String path="smb://server-ip/"+sharedFolder+"/";
        //ntlm
//     NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
        try {
            SmbFile smbFile = new SmbFile(path,NtlmPasswordAuthentication.ANONYMOUS);
            if(smbFile.isDirectory()){
                for(SmbFile f: smbFile.listFiles()){
                    System.out.println(f.getName());
                    if(f.isDirectory()){
                        for(SmbFile g: f.listFiles()){
                            System.out.println(g.getName());
                        }
                    }
                }
            }
            //SmbFile.
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SmbException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

但这也会出现错误帐户已禁用",我猜它正在尝试禁用已禁用的用户访客.

but this is also giving error "Account Disabled" I guess its trying to user guest which is disabled.

因为当使用简单的 \\server-ip\sharedFolder 与 windows 连接时它可以工作,我认为会有办法做到这一点.我想弄清楚当我们这样做时,windows 是如何进行身份验证的???

since when connecting with windows using simple \\server-ip\sharedFolder it works, I think there will be a way to do this. I want to figure out how windows is authencating when we are doing this???

找到了方法.您不需要被添加到允许登录的用户列表中.如果您在所有人"列表中并且文件夹与所有人共享,则您需要在 NTLM 身份验证期间提供您的用户名和密码,然后才能访问与所有人共享的文件夹

Found the way to do it. You need not be added to the list of users who are allowed to login. If you are in the Everyone List and the folder is shared with Everyone you need to give your username and password during NTLM authentication and the folders that are shared with everyone can be accessed after that

推荐答案

但是这个回复晚了,但正如 Matheiu 指出的那样,我应该在这里写一个答案来帮助别人.

However this late reply, but as Matheiu pointed out I should probably write an answer here to help others.

无需更改代码.这更像是一个概念性的东西.

There was no code change required. It was more of a conceptual thing.

实际上,当您与所有人共享文件时,它实际上是与域中的所有人或来宾(如果启用了来宾帐户)共享.

Actually when you share your file with everyone it's actually shared with everyone on your DOMAIN or guest if the guest account is enabled.

当有人试图访问它时,您需要某种方式来进行身份验证.当你像这样访问它时\server-ip\sharedFolder 使用 windows 它使用您的登录用户进行身份验证,如果您是同一域的一部分,它会为您提供访问权限.

You need some way to authenticate when someone is trying to access it. When you access it like this \server-ip\sharedFolder using windows it authenticates itself using your logged-in user and if you are part of the same domain it gives you access.

当您使用 linux/mac 通过 JCIFS 连接时,您需要执行相同的操作.您需要提供您的用户名和密码,如果您的用户是该域的一部分,您将通过身份验证,并且您可以访问公开共享或与所有人共享的内容.

You need to do the same when you are connecting via JCIFS using linux/mac. You need to give your username and password and if your user is part of that domain you will be authenticated and you can access things that are shared publically or shared with everyone.

这篇关于JCIFS 如何在与所有人共享文件夹时进行身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆