01: /**
02: * JOnAS: Java(TM) Open Application Server
03: * Copyright (C) 1999-2004 Bull S.A.
04: * Contact: jonas-team@objectweb.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 1any 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: * Initial developer: Florent BENOIT
22: * --------------------------------------------------------------------------
23: * $Id: JPrincipal.java 4804 2004-05-25 15:13:29Z benoitf $
24: * --------------------------------------------------------------------------
25: */package org.objectweb.jonas.security.auth;
26:
27: import java.io.Serializable;
28: import java.security.Principal;
29:
30: /**
31: * Define a JOnAS principal
32: * @author Florent Benoit
33: */
34: public class JPrincipal implements Principal, Serializable {
35:
36: /**
37: * Name of this principal
38: */
39: private String name = null;
40:
41: /**
42: * Constructor
43: * @param name the name of this principal
44: */
45: public JPrincipal(String name) {
46: this .name = name;
47: }
48:
49: /**
50: * Compares this principal to the specified object. Returns true if the object passed in matches the principal represented by the implementation of this interface.
51: * @param another principal to compare with.
52: * @return true if the principal passed in is the same as that encapsulated by this principal, and false otherwise.
53: */
54: public boolean equals(Object another) {
55: if (!(another instanceof Principal)) {
56: return false;
57: }
58: // else
59: return name.equals(((Principal) another).getName());
60: }
61:
62: /**
63: * Returns a string representation of this principal.
64: * @return a string representation of this principal.
65: */
66: public String toString() {
67: return "Principal[" + name + "]";
68: }
69:
70: /**
71: * Returns a hashcode for this principal.
72: * @return a hashcode for this principal.
73: */
74: public int hashCode() {
75: return name.hashCode();
76: }
77:
78: /**
79: * Returns the name of this principal.
80: * @return the name of this principal.
81: */
82: public String getName() {
83: return name;
84: }
85:
86: }
|