01: /**
02: * EasyBeans
03: * Copyright (C) 2006 Bull S.A.S.
04: * Contact: easybeans@ow2.org
05: *
06: * This library is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU Lesser General Public
08: * License as published by the Free Software Foundation; either
09: * version 2.1 of the License, or any later version.
10: *
11: * This library is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * Lesser General Public License for more details.
15: *
16: * You should have received a copy of the GNU Lesser General Public
17: * License along with this library; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19: * USA
20: *
21: * --------------------------------------------------------------------------
22: * $Id: JPrincipal.java 1970 2007-10-16 11:49:25Z benoitf $
23: * --------------------------------------------------------------------------
24: */package org.ow2.easybeans.security.struct;
25:
26: import java.io.Serializable;
27: import java.security.Principal;
28:
29: /**
30: * Implementation of Principal class.
31: * @author Florent Benoit
32: */
33: public class JPrincipal implements Principal, Serializable {
34:
35: /**
36: * UID for serialization.
37: */
38: private static final long serialVersionUID = 5864848835776239991L;
39:
40: /**
41: * Name of this principal.
42: */
43: private String name = null;
44:
45: /**
46: * Constructor.
47: * @param name the name of this principal
48: */
49: public JPrincipal(final String name) {
50: this .name = name;
51: }
52:
53: /**
54: * Compares this principal to the specified object. Returns true if the
55: * object passed in matches the principal represented by the implementation
56: * of this interface.
57: * @param another principal to compare with.
58: * @return true if the principal passed in is the same as that encapsulated
59: * by this principal, and false otherwise.
60: */
61: @Override
62: public boolean equals(final Object another) {
63: if (!(another instanceof Principal)) {
64: return false;
65: }
66: // else
67: return name.equals(((Principal) another).getName());
68: }
69:
70: /**
71: * Returns a string representation of this principal.
72: * @return a string representation of this principal.
73: */
74: @Override
75: public String toString() {
76: return "Principal[" + name + "]";
77: }
78:
79: /**
80: * Returns a hashcode for this principal.
81: * @return a hashcode for this principal.
82: */
83: @Override
84: public int hashCode() {
85: return name.hashCode();
86: }
87:
88: /**
89: * Returns the name of this principal.
90: * @return the name of this principal.
91: */
92: public String getName() {
93: return name;
94: }
95:
96: }
|