⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jahiaacl.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
////                                   ____.//                       __/\ ______|    |__/\.     _______//            __   .____|    |       \   |    +----+       \//    _______|  /--|    |    |    -   \  _    |    :    -   \_________//   \\______: :---|    :    :           |    :    |         \________>//           |__\---\_____________:______:    :____|____:_____\//                                      /_____|////                 . . . i n   j a h i a   w e   t r u s t . . .////// 18.04.2001 NK Added group in group support// 18.04.2001 NK Added Multi site supportpackage org.jahia.services.acl;import java.security.Principal;import java.security.acl.Group;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import org.jahia.exceptions.database.JahiaDatabaseException;import org.jahia.registries.ServicesRegistry;import org.jahia.services.usermanager.JahiaGroup;import org.jahia.services.usermanager.JahiaGroupManagerService;import org.jahia.services.usermanager.JahiaUser;import org.jahia.utils.JahiaConsole;/** * This class is private, not visible. It's only an internal class. To use the * standard ACLs for Jahia content, look at JahiaBaseACL. * * @author  Fulco Houkes * @author  NK * @author  MAP * @version 1.2 (Multisite compliant) */class JahiaACL implements ACLInfo{    private static final String CLASS_NAME = JahiaACL.class.getName();    /** This is the termination ACL ID constant. */    public static final int TERMINATION_ACL_ID = 0;    /** ACL unique identification number */    private int mID;    /** ACL parent unique identification number */    private int mParentID = 0; // Hollis to Foux in case there is no parent shoud the id -1 or 0 ?    /** ACL inheritance flag; 0 : inherit, 1 : no inheritance */    private int mInheritance;    /** Reference to the ACL database utilities class */    private AclDBUtils mDBUtils = null;    /** User permissions entries     * @associates JahiaACLEntry*/    private Hashtable mUserEntries;    /** Group permissions entries     * @associates JahiaACLEntry*/    private Hashtable mGroupEntries;    private JahiaACL mParentACL;    /**     * Constructor     *     * @param   id     *      ACL unique identification number.     * @param   parent     *      Reference to the parentACL. Can be null if there is no     *      parent available.     * @param inheritance     *      The inheritance flag (NO_INHERITANCE, INHERITANCE)     */    protected JahiaACL (int id, JahiaACL parent, int inheritance)    {        mID = id;        mParentACL = parent;        mInheritance = inheritance;        mParentID = parent != null ?  parent.getID() : 0;        mUserEntries  = new Hashtable();        mGroupEntries = new Hashtable();        mDBUtils = AclDBUtils.getInstance();    }    /**     * Return the ACL's unique identification number     *     * @return     *      Return an int representing the ACL's unique identification number.     */    public final int getID()    {        return mID;    }    /**     *  Return the ACL's parent ACL ID.     *     * @return     *      Return the parent's ACL ID.     */    public final int getParentID()    {        return mParentID;    }    /**     * Get the inheritance flag from the ACL     *     * @return the ACL inheritance status.     */    public final int getInheritance()    {        return mInheritance;    }    /**     * Set the inheritance flag to the ACL and update cache     *     * @param inheritance  The inheritance flag (INHERITANCE, NO_INHERITANCE).     *     * @return true if inheritance flag set correctly.     */    public final boolean setInheritance(int inheritance)    {        mInheritance = inheritance;        try {            return mDBUtils.updateACL(this);        } catch (JahiaDatabaseException ex) {            return false;        }    }   /**    * Return the parent ACL reference.    *    * @return    *      Return the parent ACL reference.    */   protected final JahiaACL getParent()   {        return mParentACL;   }   /**    * Get the current user permissions. If the user has no entry in the ACL    * getUserEntry returns null.    *    * @param   user    *      Reference to the user object    *    * @return    *      Return the requested acl entry, null if it doesn't exist.    */   public JahiaACLEntry getUserEntry(JahiaUser user)   {        if (user!=null) {            return (JahiaACLEntry)mUserEntries.get(user.getName());        }        return null;   }   /**    * Set the new user permissions. If the user already has an entry in the    * ACL, the old permissions are overriden. If the user has no entry, the    * specified persmission are added as is.    *    * @param   user    *      Reference to the user object    * @param   entry    *      Reference to the ACL entry.    *    * @return    *      Return true on success, or false on any failure.    */   public synchronized boolean setUserEntry (JahiaUser user, JahiaACLEntry entry)   {        if ((user == null) || (entry == null)) {            return false;        }        boolean result;        JahiaACLEntry currentEntry =                (JahiaACLEntry)mUserEntries.get (user.getName());        try {            if (currentEntry == null) {                result = mDBUtils.addACLEntry (mID, USER_TYPE_ENTRY,                        user.getName(), entry.getState(), entry.getTriState());            } else {                result = mDBUtils.updateACLEntry (mID, USER_TYPE_ENTRY,                        user.getName(), entry.getState(), entry.getTriState());            }        }        catch (JahiaDatabaseException ex) {            return false;        }        if (result) {            mUserEntries.put (user.getName(), entry);        }        return result;   }   /**    * Set the current ACL user entries.    *    * @param userEntries The user entries hash table.    */    public void setUserEntries(Hashtable userEntries) {        mUserEntries = userEntries;    }   /**    * Remove the ACL entry associated with the specified user.    *    * @param   user    *      The user reference.    *    * @return    *      Return <code>true</code> if the user entry could be removed    *      successfully from the ACL.    */   public synchronized boolean removeUserEntry(JahiaUser user)   {        boolean result = false;        if (user != null) {            try {                result = mDBUtils.removeACLEntry (mID, USER_TYPE_ENTRY,                                                user.getName());                if (result) {                    mUserEntries.remove (user.getName());                    return true;                }            }            catch (JahiaDatabaseException ex) {            }        }        return result;   }   /**    * Remove all the group type entries from the ACL    *    * @param type User or group given by ACLInfo : USER_TYPE_ENTRY,    *   GROUP_TYPE_ENTRY, ...    *    * @return    *      Return true on success or false on any failure.    */   protected synchronized boolean clearEntries(int type)   {        boolean result = false;        try {            result = mDBUtils.removeACLEntries (mID, type);        }        catch (JahiaDatabaseException ex) {        }        return result;   }   /**    * Return all the user names present in the ACL object having the same    * rights as specified.    *    * @param entry    *      Access rights bits map. Set this parameter to null to get    *      all the user names regarding their access rights.    *    * @return    *      Return a Vector holding all the String representation of the    *      users' usernames. The returned Vector is never null, but if no    *      user is present in the ACL, it will be empty.    */   public Vector getUsernameList(JahiaACLEntry entry)   {        Hashtable table = new Hashtable();        recursePermissions (table, null);        return getNameList (table, entry);   }   /**    * Return all the user names present in the ACL object having the same    * rights as specified, including users members of groups having the same    * rights as specified.    *    * @param   entry    *      Access rights bits map. Set this parameter to null to get all the    *      user names regarding their access rights. Only one bit of the entry    *      should be set to ACL_YES!    *    * @return    *      Return a Vector holding all the String representation of the users'    *      usernames. The returned Vector is never null, but if no user is    *      present in the ACL, it will be empty.    */   public Vector getUsernameListAlsoGroupUsers(JahiaACLEntry entry)   {        Hashtable userTable = new Hashtable ();        Hashtable groupTable = new Hashtable ();        recursePermissions (userTable, groupTable);        Vector result = getNameList (userTable, entry);        for (int k=0; k<result.size(); k++)        {            JahiaConsole.println("JahiaACL.getUsernameListAlsoGroupUsers","Name=" + (String)result.get(k));            if (mParentACL != null)            {                JahiaUser user = ServicesRegistry                            .getInstance()                            .getJahiaUserManagerService()                            .lookupUser((String)result.get(k));                JahiaACLEntry parentEntry = mParentACL.getUserEntry(user);                if (parentEntry != null)                {                    JahiaConsole.println("JahiaACL.getUsernameListAlsoGroupUsers", "parentAclEntry=" + parentEntry.toString());                }            }        }        Vector groupList = getNameList (groupTable, entry);        userTable = null;        groupTable = null;        // add in the result all users from every group that also have this        // access except for users that have excplicitely a NO access        for (int i=0; i<groupList.size(); i++)        {            String groupname = (String)groupList.elementAt(i);            JahiaGroup group = ServicesRegistry.getInstance().                    getJahiaGroupManagerService().lookupGroup (groupname);            Enumeration enum = group.members();            if (enum!=null) {                Principal p = null;                while (enum.hasMoreElements())                {                    p = (Principal)	enum.nextElement();                    if ( !(p instanceof Group) ){                        JahiaUser user = (JahiaUser)p;                        if ((user!=null) && (!result.contains(user.getName())))                        {                            // check if the user has access for this permission!                            ////////////////////////////////////////////////////////////////////////////                            //                            // What the hell are you doing here Dada's ???????                            // -Fulco-                            //                            ////////////////////////////////////////////////////////////////////////////                            // the user has the right for this permission ?                            int permBit = -1;                            for (int j=0; j<3; j++) {                                if (entry.getPermission(j) == JahiaACLEntry.ACL_YES) {                                    permBit = j;                                }                            }                            if ((permBit != -1) &&                                (this.getPermission (user, permBit, user.getSiteID()))) {                                result.add(user.getName());                            }                        }                        user = null;                    }                }                p = null;            }            groupname = null;            group = null;            enum = null;        }        return result;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -