View Javadoc
1   /*
2    * SPDX-License-Identifier: MIT
3    * See LICENSE file for details.
4    *
5    * Copyright 2010-2026 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
6    */
7   package waffle.mock;
8   
9   import java.util.ArrayList;
10  import java.util.List;
11  
12  import waffle.windows.auth.IWindowsAccount;
13  import waffle.windows.auth.IWindowsIdentity;
14  import waffle.windows.auth.IWindowsImpersonationContext;
15  
16  /**
17   * A Mock windows identity.
18   */
19  public class MockWindowsIdentity implements IWindowsIdentity {
20  
21      /** The fqn. */
22      private final String fqn;
23  
24      /** The groups. */
25      private final List<String> groups;
26  
27      /**
28       * Instantiates a new mock windows identity.
29       *
30       * @param newFqn
31       *            the new fqn
32       * @param newGroups
33       *            the new groups
34       */
35      public MockWindowsIdentity(final String newFqn, final List<String> newGroups) {
36          this.fqn = newFqn;
37          this.groups = newGroups;
38      }
39  
40      @Override
41      public String getFqn() {
42          return this.fqn;
43      }
44  
45      @Override
46      public IWindowsAccount[] getGroups() {
47          final List<MockWindowsAccount> groupsList = new ArrayList<>();
48          for (final String group : this.groups) {
49              groupsList.add(new MockWindowsAccount(group));
50          }
51          return groupsList.toArray(new IWindowsAccount[0]);
52      }
53  
54      @Override
55      public byte[] getSid() {
56          return new byte[0];
57      }
58  
59      @Override
60      public String getSidString() {
61          return "S-" + this.fqn.hashCode();
62      }
63  
64      @Override
65      public void dispose() {
66          // Do Nothing
67      }
68  
69      @Override
70      public boolean isGuest() {
71          return "Guest".equals(this.fqn);
72      }
73  
74      @Override
75      public IWindowsImpersonationContext impersonate() {
76          return new MockWindowsImpersonationContext();
77      }
78  
79  }