1 30 31 34 package com.nightlabs.ipanema.security; 35 36 import java.io.Serializable ; 37 import java.security.Principal ; 38 39 import javax.jdo.PersistenceManager; 40 import javax.jdo.spi.PersistenceCapable; 41 42 import org.jboss.security.SimplePrincipal; 43 44 45 48 49 57 public class RoleRef implements Serializable 58 { 59 60 64 private String authorityID; 65 66 75 private String organisationID; 76 77 81 private String userID; 82 83 87 private String roleID; 88 89 protected Authority authority; 90 91 95 protected UserRef userRef; 96 97 private Role role; 98 99 private int referenceCount = 0; 100 101 public RoleRef() { } 102 103 public RoleRef(Authority _authority, UserRef _userRef, Role _role) 104 { 105 if (_authority == null) 106 throw new NullPointerException ("authority must not be null!"); 107 if (_userRef == null) 108 throw new NullPointerException ("userRef must not be null!"); 109 if (_role == null) 110 throw new NullPointerException ("role must not be null!"); 111 112 this.authorityID = _authority.getAuthorityID(); 113 this.organisationID = _userRef.getOrganisationID(); 114 this.userID = _userRef.getUserID(); 115 this.roleID = _role.getRoleID(); 116 this.authority = _authority; 117 this.userRef = _userRef; 118 this.role = _role; 119 } 120 121 124 public String getOrganisationID() { 125 return organisationID; 126 } 127 130 public String getUserID() { 131 return userID; 132 } 133 136 public String getRoleID() { 137 return roleID; 138 } 139 140 143 public int getReferenceCount() { 144 return referenceCount; 145 } 146 147 151 public int incrementReferenceCount(int incRefCount) 152 { 153 return (referenceCount+=incRefCount); 154 } 155 156 160 public int decrementReferenceCount(int decRefCount) 161 { 162 return (referenceCount-=decRefCount); 163 } 164 165 168 public UserRef getUserRef() { 169 return userRef; 170 } 171 172 175 public Role getRole() { 176 return role; 177 } 178 179 public static final int INCLUDE_NONE = 0; 180 public static final int INCLUDE_ROLE = 0x8; 184 public static final int INCLUDE_ROLE_ROLEGROUPS = INCLUDE_ROLE | 0x10; 185 186 public void makeTransient(int includeMask) 187 { 188 PersistenceManager pm = ((PersistenceCapable)this).jdoGetPersistenceManager(); 189 if (pm == null) 190 return; 191 192 pm.retrieve(this); 193 196 if ((includeMask & INCLUDE_ROLE) != 0) 197 getRole(); 198 199 pm.makeTransient(this); 200 201 213 if ((includeMask & INCLUDE_ROLE) != 0) { 214 int roleIncludeMask = 0; 215 if ((includeMask & INCLUDE_ROLE_ROLEGROUPS) != 0) 216 roleIncludeMask = roleIncludeMask | Role.INCLUDE_ROLEGROUPS; 217 218 this.role.makeTransient(roleIncludeMask); 219 } 220 else 221 this.role = null; 222 } 223 224 protected transient String thisString = null; 225 228 public String toString() { 229 if (thisString == null) { 230 StringBuffer sb = new StringBuffer (); 231 sb.append(this.getClass().getName()); 232 sb.append('{'); 233 sb.append(userID); 234 sb.append('@'); 235 sb.append(organisationID); 236 sb.append(','); 237 sb.append(roleID); 238 sb.append('}'); 239 } 240 return thisString; 241 } 242 243 246 public boolean equals(Object obj) 247 { 248 if (obj == this) 249 return true; 250 251 if (!(obj instanceof RoleRef)) 252 return false; 253 254 RoleRef other = (RoleRef) obj; 255 return 256 this.organisationID.equals(other.organisationID) && 257 this.userID.equals(other.userID) && 258 this.roleID.equals(other.roleID); 259 } 260 263 public int hashCode() 264 { 265 return organisationID.hashCode() ^ userID.hashCode() ^ roleID.hashCode(); 266 } 267 268 protected transient Principal rolePrincipal = null; 269 public Principal getRolePrincipal() 270 { 271 if (rolePrincipal == null) 272 rolePrincipal = new SimplePrincipal(roleID); 273 274 return rolePrincipal; 275 } 276 279 public Authority getAuthority() { 280 return authority; 281 } 282 } 283 | Popular Tags |