1 41 42 63 64 package org.jahia.services.usermanager; 65 66 import org.jahia.registries.ServicesRegistry; 67 68 import java.io.Serializable ; 69 import java.security.Principal ; 70 import java.security.acl.Group ; 71 import java.util.*; 72 import org.jahia.exceptions.*; 73 74 92 public abstract class JahiaGroup implements Group , Serializable { 93 94 private static org.apache.log4j.Logger logger = 95 org.apache.log4j.Logger.getLogger(JahiaGroup.class); 96 97 98 protected String mGroupname; 99 100 104 protected String mGroupKey; 105 106 107 protected int mSiteID; 108 109 110 protected Hashtable mMembers = new Hashtable (); 111 112 113 119 public abstract Properties getProperties (); 120 121 122 130 public abstract String getProperty (String key); 131 132 133 138 public abstract boolean removeProperty (String key); 139 140 141 148 public abstract boolean setProperty (String key, String value); 149 150 151 159 public abstract boolean addMember (Principal principal); 160 161 162 172 public boolean equals (Object another) { 173 return (mGroupname.equals (((JahiaGroup) another).getName ())); 174 } 175 176 177 182 public String getGroupKey () { 183 return mGroupKey; 184 } 185 186 187 192 public String getName () { 193 return mGroupKey; 194 } 195 196 197 202 public String getGroupname () { 203 return mGroupname; 204 } 205 206 207 212 public int getSiteID () { 213 return mSiteID; 214 } 215 216 217 223 public abstract int getHomepageID (); 224 225 226 233 public abstract boolean setHomepageID (int id); 234 235 236 241 public abstract int hashCode (); 242 243 244 253 public boolean isMember (Principal principal) { 254 if (principal == null) { 255 return false; 256 } 257 258 boolean result = false; 260 261 Enumeration members = mMembers.elements (); 263 264 while ((members.hasMoreElements ()) && !result) { 268 Principal member = (Principal ) members.nextElement (); 269 if (member != null) { 270 271 if (member.getName ().equals (principal.getName ())) { 273 result = true; 274 } else { 275 276 if (member instanceof Group ) { 279 result = ((Group ) member).isMember (principal); 280 } 281 } 282 } 283 } 284 285 if (result == false) { 286 290 if ((JahiaGroupManagerService.GUEST_GROUPNAME.equals (mGroupname)) || 294 (JahiaGroupManagerService.USERS_GROUPNAME.equals (mGroupname))) { 295 JahiaUser extUser = ServicesRegistry.getInstance ().getJahiaUserManagerService () 296 .lookupUser (principal.getName ()); 297 if (extUser != null) { 298 if (!(extUser instanceof JahiaDBUser)) { 299 result = true; 300 } else if ( this instanceof JahiaDBGroup 301 && JahiaGroupManagerService.GUEST_GROUPNAME.equals (mGroupname) 302 && JahiaUserManagerService.GUEST_USERNAME.equals(extUser.getUsername()) ){ 303 result = true; 304 } 305 } 306 } 307 } 308 309 return result; 310 311 } 314 315 316 325 public Enumeration members () { 326 return mMembers.elements (); 327 } 328 329 public List memberList() { 330 return new ArrayList(mMembers.values()); 331 } 332 333 334 341 public Set getRecursiveUserMembers () { 342 Set users = new HashSet (); 343 344 348 if ((JahiaGroupManagerService.GUEST_GROUPNAME.equals (mGroupname)) || 352 (JahiaGroupManagerService.USERS_GROUPNAME.equals (mGroupname))) { 353 Vector userList = null; 354 try { 355 userList = ServicesRegistry.getInstance(). 356 getJahiaSiteUserManagerService().getMembers( 357 getSiteID()); 358 } catch (JahiaException ex) { 359 logger.error("Error while trying to retrieve full user list for site " + getSiteID(), ex); 360 } 361 if (userList != null) { 362 users.addAll(userList); 363 } 364 Vector userKeyList = ServicesRegistry.getInstance().getJahiaUserManagerService().getUserList(); 367 if ( userKeyList != null) { 368 Enumeration userKeyEnum = userKeyList.elements(); 369 while (userKeyEnum.hasMoreElements()) { 370 String curUserKey = (String ) userKeyEnum.nextElement(); 371 JahiaUser curUser = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(curUserKey); 372 if ((curUser.getSiteID() < 1) && (!users.contains(curUser))) { 373 users.add(curUser); 376 } 377 } 378 return users; 379 } 380 } 381 382 Enumeration members = mMembers.elements (); 384 385 while (members.hasMoreElements ()) { 389 Principal curMember = (Principal ) members.nextElement (); 390 391 if (curMember instanceof JahiaGroup) { 394 JahiaGroup groupMember = (JahiaGroup) curMember; 395 users.addAll (groupMember.getRecursiveUserMembers ()); 396 } else { 397 users.add (curMember); 398 } 399 } 400 401 return users; 402 } 403 404 405 413 public abstract boolean removeMember (Principal principal); 414 415 416 421 public boolean removeMembers () { 422 423 Enumeration members = mMembers.elements (); 424 Principal aMember = null; 425 while (members.hasMoreElements ()) { 426 aMember = (Principal ) members.nextElement (); 427 removeMember (aMember); 428 } 429 return true; 430 } 431 432 433 438 public abstract String toString (); 439 440 445 public abstract String getProviderName (); 446 447 } 448 | Popular Tags |