1
使用模拟我试图读取共享文件夹中位于网络上的文件。但是我得到了“访问被拒绝”的错误。我的源代码如下:java中的用户模拟
这适用于本地资源。但在访问网络资源时会出错。线 \服务器\共享\的abc.txt
// Create a provider that implements Windows authentication functions
IWindowsAuthProvider prov = new WindowsAuthProviderImpl();
// Login using different user
IWindowsIdentity identity = prov.logonDomainUser("abc.jim","abc.com", "[email protected]");
IWindowsImpersonationContext context = identity.impersonate();
// Reading file using new user
readFile(); // It gives error - Access is denied
// Revert back to original logged user
context.revertToSelf();
readFile(); // It is working properly
// Cleanup the Windows identity
identity.dispose();