Using impersonation I tried to read a file located on the network in a shared folder. But I got the error "Access is denied". My source code is given below ...
This works fine for local resources. But gives error when access network resources. line \sever\shared\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", "Xyz@123");
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();