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