1 /*
2 * MIT License
3 *
4 * Copyright (c) 2010-2020 The Waffle Project Contributors: https://github.com/Waffle/waffle/graphs/contributors
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in all
14 * copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24 package waffle.shiro;
25
26 import java.io.Serializable;
27 import java.util.Collections;
28 import java.util.HashSet;
29 import java.util.Set;
30
31 import waffle.windows.auth.IWindowsAccount;
32 import waffle.windows.auth.IWindowsIdentity;
33
34 /**
35 * The Class WaffleFqnPrincipal.
36 */
37 public class WaffleFqnPrincipal implements Serializable {
38
39 /** The Constant serialVersionUID. */
40 private static final long serialVersionUID = 1;
41
42 /** The fqn. */
43 private final String fqn;
44
45 /** The group fqns. */
46 private final Set<String> groupFqns = new HashSet<>();
47
48 /**
49 * Instantiates a new waffle fqn principal.
50 *
51 * @param identity
52 * the identity
53 */
54 WaffleFqnPrincipal(final IWindowsIdentity identity) {
55 this.fqn = identity.getFqn();
56 for (final IWindowsAccount group : identity.getGroups()) {
57 this.groupFqns.add(group.getFqn());
58 }
59 }
60
61 /**
62 * Gets the fqn.
63 *
64 * @return the fully qualified name of the user
65 */
66 public String getFqn() {
67 return this.fqn;
68 }
69
70 /**
71 * Gets the group fqns.
72 *
73 * @return the fully qualified names of all groups that the use belongs to
74 */
75 public Set<String> getGroupFqns() {
76 return Collections.unmodifiableSet(this.groupFqns);
77 }
78
79 @Override
80 public boolean equals(final Object obj) {
81 if (obj instanceof WaffleFqnPrincipal) {
82 return this.fqn.equals(((WaffleFqnPrincipal) obj).fqn);
83 }
84 return false;
85 }
86
87 @Override
88 public int hashCode() {
89 return this.fqn.hashCode();
90 }
91
92 @Override
93 public String toString() {
94 final StringBuilder stringBuilder = new StringBuilder();
95 stringBuilder.append("{");
96 stringBuilder.append(this.getClass().getSimpleName());
97 stringBuilder.append(":");
98 stringBuilder.append(this.fqn);
99 stringBuilder.append("}");
100 return stringBuilder.toString();
101 }
102
103 }