1
2
3
4
5
6
7 package waffle.windows.auth.impl;
8
9 import com.sun.jna.platform.win32.Advapi32Util;
10 import com.sun.jna.platform.win32.Advapi32Util.Account;
11 import com.sun.jna.platform.win32.Secur32.EXTENDED_NAME_FORMAT;
12 import com.sun.jna.platform.win32.Secur32Util;
13
14 import waffle.windows.auth.IWindowsAccount;
15
16
17
18
19 public class WindowsAccountImpl implements IWindowsAccount {
20
21
22 private final Account account;
23
24
25
26
27
28
29
30 public WindowsAccountImpl(final Account newAccount) {
31 this.account = newAccount;
32 }
33
34
35
36
37
38
39
40 public WindowsAccountImpl(final String userName) {
41 this(userName, null);
42 }
43
44
45
46
47
48
49
50
51
52 public WindowsAccountImpl(final String accountName, final String systemName) {
53 this(Advapi32Util.getAccountByName(systemName, accountName));
54 }
55
56
57
58
59
60
61 public static String getCurrentUsername() {
62 return Secur32Util.getUserNameEx(EXTENDED_NAME_FORMAT.NameSamCompatible);
63 }
64
65
66
67
68
69
70 @Override
71 public String getDomain() {
72 return this.account.domain;
73 }
74
75 @Override
76 public String getFqn() {
77 return this.account.fqn;
78 }
79
80
81
82
83
84
85 @Override
86 public String getName() {
87 return this.account.name;
88 }
89
90 @Override
91 public String getSidString() {
92 return this.account.sidString;
93 }
94
95 }