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

📄 jahiaacl.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            {                case JahiaACLEntry.ACL_YES :                    result = 1;                    break;                case JahiaACLEntry.ACL_NO :                    result = 0;                    break;            }        }        entry = null;        return result;   }   /**    * Search recursively the user permission in the ACL.    * @todo This code has to be reviewed    *    * @param user    * @param permission    * @param table    *    * @return  Return 1 if the user has the requested permission, 0 if the user    *          has no permission and -1 if the user was not found.    */   private int getUserPermissionInGroupHashtable (JahiaUser user, int permission, Hashtable table)   {        int result = -1;        // Check if the user has the requested permission in one of the group entries.        Enumeration names = table.keys();        while (names.hasMoreElements())        {            String groupname = (String)names.nextElement();            JahiaGroup group = ServicesRegistry.getInstance().                    getJahiaGroupManagerService().lookupGroup (groupname);            if (group != null)            {                //System.out.println (group.toString());                // Check if the user is member of the group                if (group.isMember (user))                {                    //System.out.println ("FH : user ["+user.getUsername()+"::"+user.getName()+"] is member of group ["+group.getName()+"::"+group.getGroupname()+"]");                    // if it's the first time the user is found in a group, set by default                    // the "deny" permission. If the user has the permission, it will be                    // given later.                    if (result < 0) {                        result = 0;                    }                    // Get the permission entries for the group and check it.                    JahiaACLEntry entry = (JahiaACLEntry)table.get(groupname);                    if (entry.getPermission (permission) ==                        JahiaACLEntry.ACL_YES)                    {                        result = 1;                    }                    entry = null;                } else {                    //System.out.println ("FH : user ["+user.getUsername()+"::"+user.getName()+"] is not member of group ["+group.getName()+"::"+group.getGroupname()+"]");                }            } // if            groupname = null;            group = null;        } // while        names = null;        return result;   }   /**    * Find permissions recursively.    *    * @param userTable    * @param groupTable    */    private void recursePermissions (Hashtable userTable, Hashtable groupTable) {        if (userTable != null) {            buildPermissions (userTable, mUserEntries);        }        if (groupTable != null) {            buildPermissions (groupTable, mGroupEntries);        }        if (mParentACL != null && mInheritance == 0) {            mParentACL.recursePermissions (userTable, groupTable);        }    }   /**    * @todo This code has to be reviewed    *    * @param table    */   private void getUsersPermissions (Hashtable table)   {        // for each ACL user entry check if it doesn't already exist in the        // global user entries hashtable. If it does, add only permission that        // should be herited by the current user entry.        Enumeration keys = mUserEntries.keys();        String localUsername;        while (keys.hasMoreElements ())        {            localUsername = (String)keys.nextElement();            if (localUsername != null)            {                JahiaACLEntry entry = (JahiaACLEntry)table.get (localUsername);                JahiaACLEntry localEntry = (JahiaACLEntry)mUserEntries.get (localUsername);                // if the user already exist, add some permission if needed,                // otherwise add the user entry in the table.                if (entry != null)                {                    int tristate      = entry.getTriState();                    int localTristate = localEntry.getTriState();                    // 1. get the bit mask of the permissions to be inherited                    int mask = ((~localTristate) & tristate);                    // if there is some bits to set, go for it, otherwise give up                    // and go to the next user.                    if (mask != 0)                    {                        int state = entry.getState();                        // 2. get the permission to set                        int permissionMask = (localEntry.getState() & mask);                        // 3. compute the new entry state                        state = (state | permissionMask);                        // 4. compute the new entry tristate                        tristate = ((~mask) & tristate);                        // finally update the state and tristate                        entry.set (state, tristate);                    }                } else {                    table.put (localUsername, localEntry.clone());                }                entry = null;                localEntry = null;            }        } // while        keys = null;        localUsername = null;        if (mParentACL != null) {            mParentACL.getUsersPermissions (table);        }   }   /**    * @todo This code has to be reviewed    *    * @param table    * @param localTable    */    private void buildPermissions(Hashtable table, Hashtable localTable)    {        // for each ACL user/group entry check if it doesn't already exist in the        // global user entries hashtable. If it does, add only permission that        // should be herited by the current user entry.        Enumeration keys = localTable.keys();        String name;        while (keys.hasMoreElements ())        {            name = (String)keys.nextElement();            if (name != null)            {                JahiaACLEntry entry = (JahiaACLEntry)table.get (name);                JahiaACLEntry localEntry = (JahiaACLEntry)localTable.get (name);                // if the user already exist, add some permission if needed,                // otherwise add the user entry in the table.                if (entry != null)                {                    int tristate      = entry.getTriState();                    int localTristate = localEntry.getTriState();                    // 1. get the bit mask of the permissions to be inherited                    int mask = ((~localTristate) & tristate);                    // if there is some bits to set, go for it, otherwise give up                    // and go to the next user.                    if (mask != 0)                    {                        int state = entry.getState();                        // 2. get the permission to set                        int permissionMask = (localEntry.getState() & mask);                        // 3. compute the new entry state                        state = (state | permissionMask);                        // 4. compute the new entry tristate                        tristate = ((~mask) & tristate);                        // finally update the state and tristate                        entry.set (state, tristate);                    }                } else {                    table.put (name, localEntry.clone());                }                localEntry = null;                entry = null;            }        } // while        name = null;        keys = null;   }   /**    * Get the user/group name list from the hashtable.    *    * @param hashtable    * @param entry    * @return a vector of user/group name.    */   private Vector getNameList(Hashtable hashtable, JahiaACLEntry entry)   {        Vector result;        if (entry == null) {            return getKeysFromHashTable (hashtable);        }        else        {            result = new Vector();            Enumeration keys = hashtable.keys();            while (keys.hasMoreElements())            {                String name = (String)keys.nextElement();                JahiaACLEntry hashtableEntry = (JahiaACLEntry)hashtable.get (name);                if (hashtableEntry.hasSameBitsActivated (entry)) {                    result.add (name);                }            }        }        return result;   }    /**     * Transpose the hashtable's keys into a vector.     *     * @param hashtable     *     * @return a vector of hashtable keys.     */    protected Vector getKeysFromHashTable(Hashtable hashtable)    {        Vector vect = new Vector();        Enumeration names = hashtable.keys();        while (names.hasMoreElements()) {            vect.add (names.nextElement());        }        return vect;    }   /**    * Clone the specified Hashtable. All the entries of the specified hashtable    * will also be cloned.    *    * @param   table    *      Hashtable to be cloned.    *    * @return    *      The cloned hashtable.    */   private Hashtable cloneHashtable(Hashtable table)   {        Hashtable newTable = null;        if (table != null) {            newTable = new Hashtable ();            // clone each entry in the specified hashtable            Enumeration keys = table. keys();            while (keys.hasMoreElements()) {                // get the member key                String key = new String ((String)keys.nextElement());                JahiaACLEntry entry = (JahiaACLEntry)table.get (key);                newTable.put (key, entry.clone());            }        }        return newTable;   }   /**    * Return all the ACL user entries.    *    * @return    *      Return a hashtable of all the ACL user entries. Format is    *      (String) userName, (JahiaACLEntry) aclEntry    */   public Hashtable getAllUserEntries()   {        return mUserEntries;   }   /**    * Return clone of all the ACL group entries.    *    * @return    *      Return a hashtable clone of all the ACL group entries. Format is    *      (String) groupName, (JahiaACLEntry) aclEntry    */    public Hashtable getAllGroupEntries()    {        return mGroupEntries;    }    /**     * Set the new parent ACL.     *     * @param   parentACL     *      Reference of the parent ACL. Set to <code>null</code> if the ACL     *      has no parent.     *  @throws JahiaDatabaseException     */    public void setParentACL (JahiaACL parentACL)        throws JahiaDatabaseException    {        setParentACL (parentACL, true);    }    /**     * Set the new parent ACL.     *     * @param   parentACL     *      Reference of the parent ACL. Set to <code>null</code> if the ACL     *      has no parent.     * @param   update     *      true if the setted parent has to be updated into the database.     *  @throws JahiaDatabaseException     */    protected void setParentACL (JahiaACL parentACL, boolean update)        throws JahiaDatabaseException    {        mParentACL = parentACL;        mParentID = parentACL.getID();        if (update) {            mDBUtils.updateACL (this);        }    }    /**     * Clone the current ACL.     *     * @return The new ACL cloned, null if unsuccessfull.     */    public Object clone() {        try {            int aclID = mDBUtils.getNextID();            JahiaACL acl = new JahiaACL(aclID, mParentACL, mInheritance);            acl.setUserEntries(cloneHashtable(mUserEntries));            acl.setGroupEntries(cloneHashtable(mGroupEntries));            mDBUtils.addACLInDB(acl);            System.out.println("mParentID : " + mParentID);            return acl;        } catch (JahiaDatabaseException ex) {        }        return null;    }}

⌨️ 快捷键说明

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