KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > security > SimplePrincipal


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7
8 package org.jboss.security;
9
10 import java.security.Principal JavaDoc;
11
12 /**
13  * A simple String based implementation of Principal. Typically a
14  * SimplePrincipal is created given a userID which is used as the Principal
15  * name.
16  * @author <a HREF="on@ibis.odessa.ua">Oleg Nitz</a>
17  * @author Scott.Stark@jboss.org
18  * @version $Revision: 1.7.26.1 $
19  */

20 public class SimplePrincipal implements Principal JavaDoc, java.io.Serializable JavaDoc
21 {
22    static final long serialVersionUID = 7701951188631723261L;
23    private String JavaDoc name;
24
25    public SimplePrincipal(String JavaDoc name)
26    {
27       this.name = name;
28    }
29
30    /**
31     * Compare this SimplePrincipal's name against another Principal
32     * @return true if name equals another.getName();
33     */

34    public boolean equals(Object JavaDoc another)
35    {
36       if (!(another instanceof Principal JavaDoc))
37          return false;
38       String JavaDoc anotherName = ((Principal JavaDoc) another).getName();
39       boolean equals = false;
40       if (name == null)
41          equals = anotherName == null;
42       else
43          equals = name.equals(anotherName);
44       return equals;
45    }
46
47    public int hashCode()
48    {
49       return (name == null ? 0 : name.hashCode());
50    }
51
52    public String JavaDoc toString()
53    {
54       return name;
55    }
56
57    public String JavaDoc getName()
58    {
59       return name;
60    }
61 }
62
Popular Tags