KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > nightlabs > ipanema > base > IpanemaBasePrincipal


1 /*
2  * Created on 21.09.2004
3  */

4 package com.nightlabs.ipanema.base;
5
6 import java.security.Principal JavaDoc;
7
8 import org.apache.log4j.Logger;
9
10 import com.nightlabs.ipanema.security.RoleSet;
11
12 /**
13  * @author marco
14  */

15 public class IpanemaBasePrincipal
16     implements Principal JavaDoc
17 {
18     public static Logger LOGGER = Logger.getLogger(IpanemaBasePrincipal.class);
19
20     protected String JavaDoc userID;
21     protected String JavaDoc organisationID;
22     protected boolean userIsOrganisation;
23     protected RoleSet roleSet;
24     
25     public IpanemaBasePrincipal(String JavaDoc _userID, String JavaDoc _organisationID, boolean _userIsOrganisation, RoleSet _roleSet)
26     {
27         if (_userID == null)
28             throw new NullPointerException JavaDoc("userID must not be null!");
29
30         if (_organisationID == null)
31             throw new NullPointerException JavaDoc("organisationID must not be null!");
32         
33         if (_roleSet == null)
34             throw new NullPointerException JavaDoc("roleSet must not be null!");
35
36         this.userID = _userID;
37         this.organisationID = _organisationID;
38         this.userIsOrganisation = _userIsOrganisation;
39         this.roleSet = _roleSet;
40     }
41     
42     public RoleSet getRoleSet()
43     {
44         return roleSet;
45     }
46
47     public boolean equals(Object JavaDoc obj)
48     {
49         if (obj == this)
50             return true;
51
52         if (!(obj instanceof IpanemaBasePrincipal))
53             return false;
54
55         IpanemaBasePrincipal other = (IpanemaBasePrincipal)obj;
56
57         return
58             this.userIsOrganisation == other.userIsOrganisation &&
59             this.getName().equals(other.getName()) &&
60             this.organisationID.equals(other.organisationID);
61     }
62
63     protected String JavaDoc thisString = null;
64     public String JavaDoc toString()
65     {
66         if (thisString == null) {
67             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
68             sb.append(this.getClass().getName());
69             sb.append('{');
70             sb.append(userID);
71             sb.append('@');
72             sb.append(organisationID);
73             sb.append('}');
74             thisString = sb.toString();
75         }
76         return thisString;
77     }
78
79     public int hashCode()
80     {
81         return this.toString().hashCode();
82     }
83
84     /**
85      * @return Returns the userIsOrganisation.
86      */

87     public boolean userIsOrganisation() {
88         return userIsOrganisation;
89     }
90     /**
91      * @return Returns the organisationID.
92      */

93     public String JavaDoc getOrganisationID() {
94         return organisationID;
95     }
96     /**
97      * @return Returns the userID.
98      */

99     public String JavaDoc getUserID() {
100         return userID;
101     }
102
103     protected String JavaDoc principalName = null;
104     /**
105      * @see java.security.Principal#getName()
106      */

107     public String JavaDoc getName() {
108         if (principalName == null) {
109             StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
110             sb.append(userID);
111             sb.append('@');
112             sb.append(organisationID);
113             principalName = sb.toString();
114         }
115         LOGGER.debug("principalName="+principalName);
116         return principalName;
117     }
118
119 }
120
Popular Tags