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.jaas;
15  
16  import java.io.Serializable;
17  import java.security.Principal;
18  
19  /**
20   * Role principal.
21   * 
22   * @author dblock[at]dblock[dot]org
23   */
24  public class RolePrincipal implements Principal, Serializable {
25  
26      private static final long serialVersionUID = 1L;
27      private final String            fqn;
28  
29      /**
30       * A windows principal.
31       * 
32       * @param newFqn
33       *            Fully qualified name.
34       */
35      public RolePrincipal(final String newFqn) {
36          this.fqn = newFqn;
37      }
38  
39      /**
40       * Role name (Windows Group).
41       */
42      @Override
43      public String getName() {
44          return this.fqn;
45      }
46  
47      /**
48       * Role Principal Equals for FQN.
49       * 
50       * @param o
51       *            Object used for Equality Check.
52       */
53      @Override
54      public boolean equals(final Object o) {
55  
56          if (this == o) {
57              return true;
58          }
59  
60          if (o instanceof RolePrincipal) {
61              return this.getName().equals(((RolePrincipal) o).getName());
62          }
63  
64          return false;
65      }
66  
67      /**
68       * Role Principal HashCode for FQN.
69       */
70      @Override
71      public int hashCode() {
72          return this.getName().hashCode();
73      }
74  
75  }