KickJava   Java API By Example, From Geeks To Geeks.

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


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
11
12 /**
13  * The CallerIdentity is a principal that may have a credential.
14  *
15  * @author Thomas.Diesler@jboss.org
16  * @version $Revision: 1.1 $
17  */

18 public class CallerIdentity extends SimplePrincipal
19 {
20    /** The run-as role */
21    private Object JavaDoc credential;
22
23    // hash code cache
24
private int hashCode;
25
26    /**
27     * Construct an unmutable instance of a CallerIdentity
28     */

29    public CallerIdentity(String JavaDoc principal, Object JavaDoc credential)
30    {
31       super(principal);
32       this.credential = credential;
33    }
34
35    public Object JavaDoc getCredential()
36    {
37       return credential;
38    }
39
40    /**
41     * Returns a string representation of the object.
42     * @return a string representation of the object.
43     */

44    public String JavaDoc toString()
45    {
46       return "[principal=" + getName() + "]";
47    }
48
49    /**
50     * Indicates whether some other object is "equal to" this one.
51     */

52    public boolean equals(Object JavaDoc obj)
53    {
54       if (obj == null) return false;
55       if (obj instanceof CallerIdentity)
56       {
57          CallerIdentity other = (CallerIdentity)obj;
58          return getName().equals(other.getName());
59       }
60       return false;
61    }
62
63    /**
64     * Returns a hash code value for the object.
65     */

66    public int hashCode()
67    {
68       if (hashCode == 0)
69       {
70          hashCode = toString().hashCode();
71       }
72       return hashCode;
73    }
74 }
75
Popular Tags