爪哇 - 用户认证Access文件 [英] Java - Access file with user authentication
问题描述
我有,我有一个数据库和文件使用的Java应用程序运行的服务器。
当我开始我的应用我给出关于使用到服务器文件访问报告:
I have a server where I work with a database and files using a java app. When I start my app I give a report regarding file access to the server using:
public static boolean folderExists(String folderPath) {
File folderToCheck = new File(folderPath);
return folderToCheck.exists();
}
每当我开始我的应用程序(我的电脑的全新重启后)
我得到一个错误的反应,即使服务器上。
究其原因是因为我必须给一个认证为其他用户。
我要做的就是通过Windows访问服务器
在那里我被要求输入用户名/密码,
之后,我得到关于向服务器文件访问一个真正的响应。
Every time I start my app (after a fresh restart of my computer) I get a false response, even though the server is on. The reason is because I must give an authentication as another user. What I do is access the server through Windows where I am being asked for username/password, and after that I get a true response regarding file access to the server.
有通过Java 办法给认证用户名/密码,
而不是通过Windows?
Is there a way to give the authentication username/password through Java, and not through Windows?
感谢您
推荐答案
在Windows的原生的Java IO(例如java.io.File中)总是继承运行JVM进程的用户的安全上下文。例如,您可以运行的Java应用程序与正确的凭据为Windows服务。
On Windows 'native' Java IO (e.g. java.io.File) always inherits the security context of the user running the JVM process. For example, you could run the Java app as a Windows service with the correct credentials.
该项目JCIFS实现 CIFS (在Windows SMB文件服务器协议),并允许您直接指定用户名/密码。
The JCIFS project implements CIFS (the Windows SMB file server protocol) and allows you to directly specify the username/password.
查看 API 的例子。
这篇关于爪哇 - 用户认证Access文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!