1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package waffle.mock;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import waffle.windows.auth.IWindowsAccount;
30 import waffle.windows.auth.IWindowsIdentity;
31 import waffle.windows.auth.IWindowsImpersonationContext;
32
33
34
35
36 public class MockWindowsIdentity implements IWindowsIdentity {
37
38
39 private final String fqn;
40
41
42 private final List<String> groups;
43
44
45
46
47
48
49
50
51
52 public MockWindowsIdentity(final String newFqn, final List<String> newGroups) {
53 this.fqn = newFqn;
54 this.groups = newGroups;
55 }
56
57 @Override
58 public String getFqn() {
59 return this.fqn;
60 }
61
62 @Override
63 public IWindowsAccount[] getGroups() {
64 final List<MockWindowsAccount> groupsList = new ArrayList<>();
65 for (final String group : this.groups) {
66 groupsList.add(new MockWindowsAccount(group));
67 }
68 return groupsList.toArray(new IWindowsAccount[0]);
69 }
70
71 @Override
72 public byte[] getSid() {
73 return new byte[0];
74 }
75
76 @Override
77 public String getSidString() {
78 return "S-" + this.fqn.hashCode();
79 }
80
81 @Override
82 public void dispose() {
83
84 }
85
86 @Override
87 public boolean isGuest() {
88 return "Guest".equals(this.fqn);
89 }
90
91 @Override
92 public IWindowsImpersonationContext impersonate() {
93 return new MockWindowsImpersonationContext();
94 }
95
96 }