共享文件夹上的Java模拟访问被拒绝

时间:2018-10-25 09:16:39

标签: java jna impersonation waffle

我正在尝试使用Java控制台实施模拟,但是出现访问被拒绝错误。用户也具有管理员权限。

public class Impersionation {

/**
 * @param args the command line arguments
 */
public static void main(String[] args) throws Exception {
    // Create a provider that implements Windows authentication functions
    IWindowsAuthProvider prov = new WindowsAuthProviderImpl();

    // Logon using my UPN formatted Windows domain account. 
    IWindowsIdentity identity = prov.logonUser("asadj@domain.pk", "MyPassword");

    // Impersonate as userB@my.domain.com
    IWindowsImpersonationContext ctx = identity.impersonate();

    // As the impersonated user, userB, create a new file
    try{
    File file = new File("\\\\Shared\\Path\\" +  Advapi32Util.getUserName() + ".txt");
    if (file.createNewFile()){
                    System.out.println("File is created!");
                  }else{
                    System.out.println("File already exists.");
                  }
              } catch (IOException e) {
          System.out.println(e.getMessage());
                  e.printStackTrace();
            }    

    // Revert to the original user, userA
    ctx.revertToSelf();

    // As userA, create a new file
    File file1 = new File("\\\\Shared\\Path\\" + Advapi32Util.getUserName() + ".txt");
    file1.createNewFile();
    // Cleanup the Windows identity
    identity.dispose();
  }

}

用户 asadj 具有所有管理员权限。它在本地可用,但不适用于网络上的共享文件夹。

java-impersonation-using-jna-and-waffle获得的帮助。

谢谢

0 个答案:

没有答案