View Javadoc
1   /**
2    * Waffle (https://github.com/dblock/waffle)
3    *
4    * Copyright (c) 2010 - 2015 Application Security, Inc.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of the Eclipse Public License v1.0
8    * which accompanies this distribution, and is available at
9    * http://www.eclipse.org/legal/epl-v10.html
10   *
11   * Contributors:
12   *     Application Security, Inc.
13   */
14  package waffle.shiro;
15  
16  import java.io.Serializable;
17  import java.util.Collections;
18  import java.util.HashSet;
19  import java.util.Set;
20  
21  import waffle.windows.auth.IWindowsAccount;
22  import waffle.windows.auth.IWindowsIdentity;
23  
24  /**
25   * The Class WaffleFqnPrincipal.
26   */
27  public class WaffleFqnPrincipal implements Serializable {
28      
29      /** The Constant serialVersionUID. */
30      private static final long serialVersionUID = 1;
31      
32      /** The fqn. */
33      private final String      fqn;
34      
35      /** The group fqns. */
36      private final Set<String> groupFqns        = new HashSet<String>();
37  
38      /**
39       * Instantiates a new waffle fqn principal.
40       *
41       * @param identity
42       *            the identity
43       */
44      WaffleFqnPrincipal(final IWindowsIdentity identity) {
45          this.fqn = identity.getFqn();
46          for (final IWindowsAccount group : identity.getGroups()) {
47              this.groupFqns.add(group.getFqn());
48          }
49      }
50  
51      /**
52       * Gets the fqn.
53       *
54       * @return the fully qualified name of the user
55       */
56      public String getFqn() {
57          return this.fqn;
58      }
59  
60      /**
61       * Gets the group fqns.
62       *
63       * @return the fully qualified names of all groups that the use belongs to
64       */
65      public Set<String> getGroupFqns() {
66          return Collections.unmodifiableSet(this.groupFqns);
67      }
68  
69      /* (non-Javadoc)
70       * @see java.lang.Object#equals(java.lang.Object)
71       */
72      @Override
73      public boolean equals(final Object obj) {
74          if (obj instanceof WaffleFqnPrincipal) {
75              return this.fqn.equals(((WaffleFqnPrincipal) obj).fqn);
76          }
77          return false;
78      }
79  
80      /* (non-Javadoc)
81       * @see java.lang.Object#hashCode()
82       */
83      @Override
84      public int hashCode() {
85          return this.fqn.hashCode();
86      }
87  
88      /* (non-Javadoc)
89       * @see java.lang.Object#toString()
90       */
91      @Override
92      public String toString() {
93          final StringBuilder stringBuilder = new StringBuilder();
94          stringBuilder.append("{");
95          stringBuilder.append(this.getClass().getSimpleName());
96          stringBuilder.append(":");
97          stringBuilder.append(this.fqn);
98          stringBuilder.append("}");
99          return stringBuilder.toString();
100     }
101 }