1 4 package com.nightlabs.ipanema.base; 5 6 import java.security.Principal ; 7 8 import org.apache.log4j.Logger; 9 10 import com.nightlabs.ipanema.security.RoleSet; 11 12 15 public class IpanemaBasePrincipal 16 implements Principal 17 { 18 public static Logger LOGGER = Logger.getLogger(IpanemaBasePrincipal.class); 19 20 protected String userID; 21 protected String organisationID; 22 protected boolean userIsOrganisation; 23 protected RoleSet roleSet; 24 25 public IpanemaBasePrincipal(String _userID, String _organisationID, boolean _userIsOrganisation, RoleSet _roleSet) 26 { 27 if (_userID == null) 28 throw new NullPointerException ("userID must not be null!"); 29 30 if (_organisationID == null) 31 throw new NullPointerException ("organisationID must not be null!"); 32 33 if (_roleSet == null) 34 throw new NullPointerException ("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 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 thisString = null; 64 public String toString() 65 { 66 if (thisString == null) { 67 StringBuffer sb = new StringBuffer (); 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 87 public boolean userIsOrganisation() { 88 return userIsOrganisation; 89 } 90 93 public String getOrganisationID() { 94 return organisationID; 95 } 96 99 public String getUserID() { 100 return userID; 101 } 102 103 protected String principalName = null; 104 107 public String getName() { 108 if (principalName == null) { 109 StringBuffer sb = new StringBuffer (); 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 |