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.shiro;
8   
9   import java.io.Serializable;
10  import java.util.Collections;
11  import java.util.HashSet;
12  import java.util.Set;
13  
14  import waffle.windows.auth.IWindowsAccount;
15  import waffle.windows.auth.IWindowsIdentity;
16  
17  /**
18   * The Class WaffleFqnPrincipal.
19   */
20  public class WaffleFqnPrincipal implements Serializable {
21  
22      /** The Constant serialVersionUID. */
23      private static final long serialVersionUID = 1;
24  
25      /** The fqn. */
26      private final String fqn;
27  
28      /** The group fqns. */
29      private final Set<String> groupFqns = new HashSet<>();
30  
31      /**
32       * Instantiates a new waffle fqn principal.
33       *
34       * @param identity
35       *            the identity
36       */
37      WaffleFqnPrincipal(final IWindowsIdentity identity) {
38          this.fqn = identity.getFqn();
39          for (final IWindowsAccount group : identity.getGroups()) {
40              this.groupFqns.add(group.getFqn());
41          }
42      }
43  
44      /**
45       * Gets the fqn.
46       *
47       * @return the fully qualified name of the user
48       */
49      public String getFqn() {
50          return this.fqn;
51      }
52  
53      /**
54       * Gets the group fqns.
55       *
56       * @return the fully qualified names of all groups that the use belongs to
57       */
58      public Set<String> getGroupFqns() {
59          return Collections.unmodifiableSet(this.groupFqns);
60      }
61  
62      @Override
63      public boolean equals(final Object obj) {
64          if (obj instanceof WaffleFqnPrincipal) {
65              return this.fqn.equals(((WaffleFqnPrincipal) obj).fqn);
66          }
67          return false;
68      }
69  
70      @Override
71      public int hashCode() {
72          return this.fqn.hashCode();
73      }
74  
75      @Override
76      public String toString() {
77          final StringBuilder stringBuilder = new StringBuilder();
78          stringBuilder.append("{");
79          stringBuilder.append(this.getClass().getSimpleName());
80          stringBuilder.append(":");
81          stringBuilder.append(this.fqn);
82          stringBuilder.append("}");
83          return stringBuilder.toString();
84      }
85  
86  }