KickJava   Java API By Example, From Geeks To Geeks.

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


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

7 package org.jboss.security;
8
9 import java.security.Principal JavaDoc;
10
11 /** An implementation of Principal and Comparable that represents any role.
12 Any Principal or name of a Principal when compared to an AnybodyPrincipal
13 using {@link #equals(Object) equals} or {@link #compareTo(Object) compareTo}
14 will always be found equals to the AnybodyPrincipal.
15
16 Note that this class is not likely to operate correctly in a collection
17 since the hashCode() and equals() methods are not correlated.
18
19 @author Scott.Stark@jboss.org
20 @version $Revision: 1.5 $
21 */

22 public class AnybodyPrincipal implements Comparable JavaDoc, Principal JavaDoc
23 {
24     public static final String JavaDoc ANYBODY = "<ANYBODY>";
25     public static final AnybodyPrincipal ANYBODY_PRINCIPAL = new AnybodyPrincipal();
26
27     public int hashCode()
28     {
29         return ANYBODY.hashCode();
30     }
31
32     /**
33     @return "<ANYBODY>"
34     */

35     public String JavaDoc getName()
36     {
37         return ANYBODY;
38     }
39
40     public String JavaDoc toString()
41     {
42         return ANYBODY;
43     }
44     
45     /** This method always returns 0 to indicate equality for any argument.
46     This is only meaningful when comparing against other Principal objects
47      or names of Principals.
48
49     @return true to indicate equality for any argument.
50     */

51     public boolean equals(Object JavaDoc another)
52     {
53         return true;
54     }
55
56     /** This method always returns 0 to indicate equality for any argument.
57     This is only meaningful when comparing against other Principal objects
58      or names of Principals.
59
60     @return 0 to indicate equality for any argument.
61     */

62     public int compareTo(Object JavaDoc o)
63     {
64         return 0;
65     }
66
67 }
68
Popular Tags