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