KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > security > auth > JPrincipal


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 1999-2004 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * 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,v 1.3 2004/05/25 15:13:29 benoitf Exp $
24  * --------------------------------------------------------------------------
25  */

26
27 package org.objectweb.jonas.security.auth;
28
29 import java.io.Serializable JavaDoc;
30 import java.security.Principal JavaDoc;
31
32 /**
33  * Define a JOnAS principal
34  * @author Florent Benoit
35  */

36 public class JPrincipal implements Principal JavaDoc, Serializable JavaDoc {
37
38
39     /**
40      * Name of this principal
41      */

42     private String JavaDoc name = null;
43
44     /**
45      * Constructor
46      * @param name the name of this principal
47      */

48     public JPrincipal(String JavaDoc name) {
49         this.name = name;
50     }
51
52     /**
53      * Compares this principal to the specified object. Returns true if the object passed in matches the principal represented by the implementation of this interface.
54      * @param another principal to compare with.
55      * @return true if the principal passed in is the same as that encapsulated by this principal, and false otherwise.
56      */

57     public boolean equals(Object JavaDoc another) {
58         if (!(another instanceof Principal JavaDoc)) {
59             return false;
60         }
61         // else
62
return name.equals(((Principal JavaDoc) another).getName());
63     }
64
65     /**
66      * Returns a string representation of this principal.
67      * @return a string representation of this principal.
68      */

69     public String JavaDoc toString() {
70         return "Principal[" + name + "]";
71     }
72
73
74     /**
75      * Returns a hashcode for this principal.
76      * @return a hashcode for this principal.
77      */

78     public int hashCode() {
79         return name.hashCode();
80     }
81
82     /**
83      * Returns the name of this principal.
84      * @return the name of this principal.
85      */

86     public String JavaDoc getName() {
87         return name;
88     }
89
90
91
92
93 }
94
Popular Tags