KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > security > IdentificationPrincipal


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17
18 package org.apache.geronimo.security;
19
20 import java.io.Serializable JavaDoc;
21 import java.security.Principal JavaDoc;
22
23
24 /**
25  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
26  */

27 public class IdentificationPrincipal implements Principal JavaDoc, Serializable JavaDoc {
28     private final SubjectId id;
29     private transient String JavaDoc name;
30
31     public IdentificationPrincipal(SubjectId id) {
32         this.id = id;
33     }
34
35     public SubjectId getId() {
36         return id;
37     }
38
39     /**
40      * Compares this principal to the specified object. Returns true
41      * if the object passed in matches the principal represented by
42      * the implementation of this interface.
43      *
44      * @param another principal to compare with.
45      * @return true if the principal passed in is the same as that
46      * encapsulated by this principal, and false otherwise.
47      */

48     public boolean equals(Object JavaDoc another) {
49         if (!(another instanceof IdentificationPrincipal)) return false;
50
51         IdentificationPrincipal idPrincipal = (IdentificationPrincipal) another;
52
53         return id.equals(idPrincipal.id);
54     }
55
56     /**
57      * Returns a string representation of this principal.
58      *
59      * @return a string representation of this principal.
60      */

61     public String JavaDoc toString() {
62         return getName();
63     }
64
65     /**
66      * Returns a hashcode for this principal.
67      *
68      * @return a hashcode for this principal.
69      */

70     public int hashCode() {
71         return getName().hashCode();
72     }
73
74     /**
75      * Returns the name of this principal.
76      *
77      * @return the name of this principal.
78      */

79     public String JavaDoc getName() {
80         if (name == null) {
81
82             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc("");
83             buffer.append(getClass().getName());
84             buffer.append("[");
85             buffer.append(id);
86             buffer.append("]");
87
88             name = buffer.toString();
89         }
90         return name;
91     }
92 }
93
Popular Tags