Search in sources :

Example 1 with Account

use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.

the class Advapi32UtilTest method testGetCurrentUserGroups.

public void testGetCurrentUserGroups() {
    Account[] groups = Advapi32Util.getCurrentUserGroups();
    assertTrue(groups.length > 0);
    for (Account group : groups) {
        assertTrue(group.name.length() > 0);
        assertTrue(group.sidString.length() > 0);
        assertTrue(group.sid.length > 0);
    }
}
Also used : Account(com.sun.jna.platform.win32.Advapi32Util.Account)

Example 2 with Account

use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.

the class Advapi32UtilTest method testGetAccountBySid.

public void testGetAccountBySid() {
    String accountName = Advapi32Util.getUserName();
    Account currentUser = Advapi32Util.getAccountByName(accountName);
    Account account = Advapi32Util.getAccountBySid(new PSID(currentUser.sid));
    assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
    assertEquals(currentUser.fqn.toLowerCase(), account.fqn.toLowerCase());
    assertEquals(currentUser.name.toLowerCase(), account.name.toLowerCase());
    assertEquals(currentUser.domain.toLowerCase(), account.domain.toLowerCase());
    assertEquals(currentUser.sidString, account.sidString);
}
Also used : Account(com.sun.jna.platform.win32.Advapi32Util.Account) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Example 3 with Account

use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.

the class Advapi32UtilTest method main.

public static void main(String[] args) {
    junit.textui.TestRunner.run(Advapi32UtilTest.class);
    String currentUserName = Advapi32Util.getUserName();
    System.out.println("GetUserName: " + currentUserName);
    for (Account group : Advapi32Util.getCurrentUserGroups()) {
        System.out.println(" " + group.fqn + " [" + group.sidString + "]");
    }
    Account accountByName = Advapi32Util.getAccountByName(currentUserName);
    System.out.println("AccountByName: " + currentUserName);
    System.out.println(" Fqn: " + accountByName.fqn);
    System.out.println(" Domain: " + accountByName.domain);
    System.out.println(" Sid: " + accountByName.sidString);
    Account accountBySid = Advapi32Util.getAccountBySid(new PSID(accountByName.sid));
    System.out.println("AccountBySid: " + accountByName.sidString);
    System.out.println(" Fqn: " + accountBySid.fqn);
    System.out.println(" Name: " + accountBySid.name);
    System.out.println(" Domain: " + accountBySid.domain);
}
Also used : Account(com.sun.jna.platform.win32.Advapi32Util.Account) PSID(com.sun.jna.platform.win32.WinNT.PSID)

Example 4 with Account

use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.

the class Advapi32UtilTest method testGetAccountByName.

public void testGetAccountByName() {
    String accountName = Advapi32Util.getUserName();
    Account account = Advapi32Util.getAccountByName(accountName);
    assertEquals(SID_NAME_USE.SidTypeUser, account.accountType);
}
Also used : Account(com.sun.jna.platform.win32.Advapi32Util.Account)

Example 5 with Account

use of com.sun.jna.platform.win32.Advapi32Util.Account in project jna by java-native-access.

the class Advapi32UtilTest method testGetUserAccount.

public void testGetUserAccount() {
    USER_INFO_1 userInfo = new USER_INFO_1();
    userInfo.usri1_name = "JNANetapi32TestUser";
    userInfo.usri1_password = "!JNAP$$Wrd0";
    userInfo.usri1_priv = LMAccess.USER_PRIV_USER;
    // ignore test if not able to add user (need to be administrator to do this).
    if (LMErr.NERR_Success != Netapi32.INSTANCE.NetUserAdd(null, 1, userInfo, null)) {
        return;
    }
    try {
        HANDLEByReference phUser = new HANDLEByReference();
        try {
            assertTrue(Advapi32.INSTANCE.LogonUser(userInfo.usri1_name.toString(), null, userInfo.usri1_password.toString(), WinBase.LOGON32_LOGON_NETWORK, WinBase.LOGON32_PROVIDER_DEFAULT, phUser));
            Advapi32Util.Account account = Advapi32Util.getTokenAccount(phUser.getValue());
            assertTrue(account.name.length() > 0);
            assertEquals(userInfo.usri1_name.toString(), account.name);
        } finally {
            HANDLE hUser = phUser.getValue();
            if (!WinBase.INVALID_HANDLE_VALUE.equals(hUser)) {
                Kernel32Util.closeHandle(hUser);
            }
        }
    } finally {
        assertEquals(LMErr.NERR_Success, Netapi32.INSTANCE.NetUserDel(null, userInfo.usri1_name.toString()));
    }
}
Also used : Account(com.sun.jna.platform.win32.Advapi32Util.Account) HANDLEByReference(com.sun.jna.platform.win32.WinNT.HANDLEByReference) USER_INFO_1(com.sun.jna.platform.win32.LMAccess.USER_INFO_1) HANDLE(com.sun.jna.platform.win32.WinNT.HANDLE)

Aggregations

Account (com.sun.jna.platform.win32.Advapi32Util.Account)6 PSID (com.sun.jna.platform.win32.WinNT.PSID)4 HANDLE (com.sun.jna.platform.win32.WinNT.HANDLE)3 HANDLEByReference (com.sun.jna.platform.win32.WinNT.HANDLEByReference)3 IntByReference (com.sun.jna.ptr.IntByReference)3 USER_INFO_1 (com.sun.jna.platform.win32.LMAccess.USER_INFO_1)2 PointerByReference (com.sun.jna.ptr.PointerByReference)2 UserModel (com.gitblit.models.UserModel)1 Memory (com.sun.jna.Memory)1 Win32Exception (com.sun.jna.platform.win32.Win32Exception)1 PSIDByReference (com.sun.jna.platform.win32.WinNT.PSIDByReference)1 SID_AND_ATTRIBUTES (com.sun.jna.platform.win32.WinNT.SID_AND_ATTRIBUTES)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 TreeSet (java.util.TreeSet)1 IWindowsAccount (waffle.windows.auth.IWindowsAccount)1 IWindowsIdentity (waffle.windows.auth.IWindowsIdentity)1