Олицетворение Java Доступ запрещен в общей папке - PullRequest
0 голосов
/ 25 октября 2018

Я пытаюсь реализовать олицетворение с помощью консоли 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 .

Спасибо

...