📄 jahiagroup.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .//// NK - 18 Dec. 2001 :// 1. Added properties to grouppackage org.jahia.services.usermanager;import java.security.Principal;import java.security.acl.Group;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.Set;import java.util.HashSet;import java.util.Vector;import org.jahia.registries.ServicesRegistry;/** * This class represents a group of <code>Principals</code> which can be users * or groups. A group can have subgroups holding again users or subgroups.</br> * </br> * Each group is defined with a name, which is unique inside a site, but not * necessarily unique between two sites. Each group has also a unique * identification key, which is unique in the database. This way, a group is * uniquely identified in all the sites and Jahia servers sharing the same * database.</br> * </br> * The group names are used only to present an intuitive signification for the * administrators of each site. As the key is the only way to assure unicity * between the sites and servers, it will be used to represent the group inside * of jahia and not the group name. * * @author Fulco Houkes * @version 2.1 */public abstract class JahiaGroup implements Group{ /** Group unique identification name */ protected String mGroupname; /** Group global identification key, unique in all the sites and Jahia * servers sharing the same groups data source. */ protected String mGroupKey; /** The site id */ protected int mSiteID; /** Hashtable holding all the group members. Is assumed to be never null. */ protected Hashtable mMembers = new Hashtable(); //-------------------------------------------------------------------------- /** * Get grp's properties list. * * @return Return a reference on the grp's properties list, or null if no * property is present. */ public abstract Properties getProperties (); //-------------------------------------------------------------------------- /** * Retrieve the requested grp property. * * @param key Property's name. * * @return Return the property's value of the specified key, or null if the * property does not exist. */ public abstract String getProperty (String key); //-------------------------------------------------------------------------- /** * Remove the specified property from the properties list. * * @param key Property's name. */ public abstract boolean removeProperty (String key); //-------------------------------------------------------------------------- /** * Add (or update if not already in the property list) a property key-value * pair in the grp's properties list. * * @param key Property's name. * @param value Property's value. */ public abstract boolean setProperty (String key, String value); //------------------------------------------------------------------------- /** Adds the specified member to the group. * * @param user * The principal to add to this group. * * @return * Return true if the member was successfully added, false if the * principal was already a member. */ public abstract boolean addMember (Principal principal); //------------------------------------------------------------------------- /** Compares this principal to the specified object. Returns true if the object * passed in matches the principal represented by the implementation of this * interface. * * @param another * Principal to compare with. * * @return * Return true if the principal passed in is the same as that * encapsulated by this principal, and false otherwise. */ public boolean equals (Object another) { return (mGroupname.equals (((JahiaGroup)another).getName())); } //------------------------------------------------------------------------- /** Return the group key. * * @return * REturn the unique group identification key. */ public String getGroupKey () { return mGroupKey; } //------------------------------------------------------------------------- /** Returns the unique identifier of this principal object. * * @return The unique identifier of this group. */ public String getName () { return mGroupKey; } //------------------------------------------------------------------------- /** Returns the name of this group. * * @return The name of this group. */ public String getGroupname () { return mGroupname; } //------------------------------------------------------------------------- /** Returns the site id. * * @return int the siteID. */ public int getSiteID () { return mSiteID; } //------------------------------------------------------------------------- /** * Returns the group's home page id. * -1 : undefined * * @return int The group homepage id. */ public abstract int getHomepageID (); //------------------------------------------------------------------------- /** * Set the home page id. * * @param int The group homepage id. * @return false on error */ public abstract boolean setHomepageID (int id); //------------------------------------------------------------------------- /** Returns a hashcode for this principal. * * @return * A hashcode for this principal. */ public abstract int hashCode (); //------------------------------------------------------------------------- /** Returns true if the passed principal is a member of the group. This method * does a recursive search, so if a principal belongs to a group which is a * member of this group, true is returned. * * @param principal * The principal whose membership is to be checked. * * @return * Return true if the principal is a member of this group, false otherwise. */ public boolean isMember (Principal principal) { if (principal == null) { return false; } // By default, the principal is not a member of the group. boolean result = false; // Get the list of members Enumeration members = mMembers.elements (); // For each member check if it's the member we are looking for, // otherwise, if the member is a group, check recursively in this group // for the requested member. while ((members.hasMoreElements()) && !result) { Principal member = (Principal)members.nextElement(); if (member != null) { // check if the member is the one we are looking for if (member.getName().equals (principal.getName())) { result = true; } else { // if the member is a group look for the principal in this // group. Groups are already loaded. if (member instanceof Group) { result = ((Group)member).isMember (principal); } } } } if (result == false) { /** @todo this is a temporary solution until we have implicit * group implementation. Then we will have guest_provider, users_provider * groups that are contained within the global users and guest groups */ // let's now check if we are in the special case of guest and users // for external sources users // user could be external database user, let's look him up... if ((JahiaGroupManagerService.GUEST_GROUPNAME.equals(mGroupname)) || (JahiaGroupManagerService.USERS_GROUPNAME.equals(mGroupname)) ) { JahiaUser extUser = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(principal.getName()); if ( extUser != null) { if (!(extUser instanceof JahiaDBUser)) { result = true; } } } } return result; //Principal tmp = (Principal)mMembers.get(principal.getName()); //return (tmp != null); } //------------------------------------------------------------------------- /** Returns an enumeration of the members in the group. The returned objects * can be instances of either <code>Principal</code> or <code>Group</code>. * </br></br> * Note that the <code>Group</code> is an instanciation of the * <code>Principal</code> class. * * @return * An enumeration of the group members. */ public Enumeration members () { return mMembers.elements (); } /** * This method returns ONLY a list of users. All sub groups are expanded * to return only the full list of members. * @return Set a set of JahiaUsers that are all the implicit and explicit * users in this group */ public Set getRecursiveUserMembers() { Set users = new HashSet(); /** @todo this is a temporary solution until we have implicit * group implementation. Then we will have guest_provider, users_provider * groups that are contained within the global users and guest groups */ // let's now check if we are in the special case of guest and users // for external sources users // user could be external database user, let's look him up... if ((JahiaGroupManagerService.GUEST_GROUPNAME.equals(mGroupname)) || (JahiaGroupManagerService.USERS_GROUPNAME.equals(mGroupname)) ) { Vector userKeyList = ServicesRegistry.getInstance().getJahiaUserManagerService().getUserList(); if ( userKeyList != null) { Enumeration userKeyEnum = userKeyList.elements(); while (userKeyEnum.hasMoreElements()) { String curUserKey = (String) userKeyEnum.nextElement(); JahiaUser curUser = ServicesRegistry.getInstance().getJahiaUserManagerService().lookupUser(curUserKey); users.add(curUser); } return users; } } // Get the list of members Enumeration members = mMembers.elements (); // For each member check if it's the member we are looking for, // otherwise, if the member is a group, check recursively in this group // for the requested member. while (members.hasMoreElements()) { Principal curMember = (Principal)members.nextElement(); // if the member is a group look for the principal in this // group. Groups are already loaded. if (curMember instanceof JahiaGroup) { JahiaGroup groupMember = (JahiaGroup) curMember; users.addAll (groupMember.getRecursiveUserMembers ()); } else { users.add(curMember); } } return users; } //------------------------------------------------------------------------- /** Removes the specified member from the group. * * @param user The principal to remove from this group. * * @return Return true if the principal was removed, or false if the * principal was not a member. */ public abstract boolean removeMember (Principal principal); //------------------------------------------------------------------------- /** Removes all members from the group. * * @return Return false on error */ public boolean removeMembers (){ Enumeration members = mMembers.elements(); Principal aMember = null; while ( members.hasMoreElements() ){ aMember = (Principal)members.nextElement(); removeMember(aMember); } return true; } //-------------------------------------------------------------------------- /** * Returns a string representation of this group. * * @return A string representation of this group. */ public abstract String toString (); /** * Get the name of the provider of this group. * * @return * String representation of the name of the provider of this group */ public abstract String getProviderName();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -