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 * User Principal.
21 *
22 * @author dblock[at]dblock[dot]org
23 */
24 public class UserPrincipal implements Principal, Serializable {
25
26 /** The Constant serialVersionUID. */
27 private static final long serialVersionUID = 1L;
28
29 /** The fqn. */
30 private final String fqn;
31
32 /**
33 * A user principal.
34 *
35 * @param newFqn
36 * Fully qualified username.
37 */
38 public UserPrincipal(final String newFqn) {
39 this.fqn = newFqn;
40 }
41
42 /**
43 * Fully qualified username.
44 *
45 * @return the name
46 */
47 @Override
48 public String getName() {
49 return this.fqn;
50 }
51
52 /* (non-Javadoc)
53 * @see java.lang.Object#equals(java.lang.Object)
54 */
55 @Override
56 public boolean equals(final Object o) {
57
58 if (this == o) {
59 return true;
60 }
61
62 if (o instanceof UserPrincipal) {
63 return this.getName().equals(((UserPrincipal) o).getName());
64 }
65
66 return false;
67 }
68
69 /* (non-Javadoc)
70 * @see java.lang.Object#hashCode()
71 */
72 @Override
73 public int hashCode() {
74 return this.getName().hashCode();
75 }
76 }