KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > services > usermanager > GenericPrincipal


1 //
2
// ____.
3
// __/\ ______| |__/\. _______
4
// __ .____| | \ | +----+ \
5
// _______| /--| | | - \ _ | : - \_________
6
// \\______: :---| : : | : | \________>
7
// |__\---\_____________:______: :____|____:_____\
8
// /_____|
9
//
10
// . . . i n j a h i a w e t r u s t . . .
11
//
12
//
13
// NK 12.04.2001 - Added to support Multi Site and Servlet API
14

15
16 package org.jahia.services.usermanager;
17
18
19 import java.security.Principal JavaDoc;
20
21 /**
22  * The minimal implementation of a Principal
23  * Used in Servlet Request Wrapper getUserPrincipal().
24  * It's a wrapper around a JahiaUser but its getName() return the login username,
25  * not the jahia user internal key.
26  *
27  * @author NK
28  */

29 public class GenericPrincipal implements Principal JavaDoc {
30
31     private JahiaUser mUser;
32
33     private GenericPrincipal () {
34     };
35
36
37
38     public GenericPrincipal (JahiaUser user) {
39         mUser = user;
40     }
41
42
43     public String JavaDoc getName () {
44         if (mUser == null) {
45             return "";
46         }
47         return mUser.getUsername ();
48     }
49
50     public boolean equals (Object JavaDoc another) {
51         if (mUser == null) {
52             return false;
53         }
54
55         if (another instanceof Principal JavaDoc) {
56             if (another != null) {
57                 return (mUser.getName ().equals (((Principal JavaDoc) another).getName ()));
58             }
59         }
60         return false;
61     }
62
63     public int hashCode () {
64         if (mUser == null) {
65             return -1;
66         }
67         return mUser.hashCode ();
68     }
69
70
71     public String JavaDoc toString () {
72         if (mUser == null) {
73             return "";
74         }
75
76         StringBuffer JavaDoc output = new StringBuffer JavaDoc ("Detail of user [" + mUser.getUsername () + "]\n");
77         output.append (" - ID [" + Integer.toString (mUser.hashCode ()) + "]");
78         return output.toString ();
79     }
80
81 }
Popular Tags