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

📄 jahiaacl.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
   }   /**    * Get the current group permissions. If the group has no entry in the ACL    * getGroupEntry returns null.    *    * @param   group    *      Reference to the group object    *    * @return    *      Return the requested acl entry, null if it doesn't exist.    */   public JahiaACLEntry getGroupEntry(JahiaGroup group)   {        if (group!=null) {            return (JahiaACLEntry)mGroupEntries.get(group.getName());        }        return null;   }    /**    * Set the new group permissions. If the group already has an entry in the    * ACL, the old permissions are overriden. If the group has no entry, the    * specified persmission are added as is.    *    * @param   group    *      Reference to the group object    * @param   entry    *      Reference to the ACL entry.    *    * @return    *      Return true on success, or false on any failure.    */    public synchronized boolean setGroupEntry (JahiaGroup group, JahiaACLEntry entry)    {        if ((group == null) || (entry == null)) {            return false;        }        boolean result;        JahiaACLEntry tmp = (JahiaACLEntry)mGroupEntries.get (group.getName());        try {            if (tmp == null) {                result = mDBUtils.addACLEntry (mID, GROUP_TYPE_ENTRY,                        group.getName(), entry.getState(), entry.getTriState());            } else {                result = mDBUtils.updateACLEntry (mID, GROUP_TYPE_ENTRY,                        group.getName(), entry.getState(), entry.getTriState());            }        }        catch (JahiaDatabaseException ex) {            result = false;            tmp = null;        }        tmp = null;        if (result) {            mGroupEntries.put (group.getName(), entry);        }        return result;    }    /**     * Set the current ACL group entries.     *     * @param groupEntries The group entries hash table.     */    public void setGroupEntries(Hashtable groupEntries) {        mGroupEntries = groupEntries;    }    /**     * Remove the specified group from the ACL entry.     *     * @param group The group to remove.     *     * @return true if group removed successfully.     */    public synchronized boolean removeGroupEntry(JahiaGroup group)    {        if (group == null) {            return false;        }        try {            if (mDBUtils.removeACLEntry (mID, GROUP_TYPE_ENTRY, group.getName()))            {                mGroupEntries.remove (group.getName());                return true;            }        }        catch (JahiaDatabaseException ex) {        }        return false;    }   /**    * Return all the group names present in the ACL object having the same    * rights as specified, but not the Administrator group    *    * @param  entry    *      Access rights bits map. Set this parameter to null to get all the    *      group names regarding their access rights.    *    * @return    *      Return a Vector holding all the String representation of the    *      groupnames. The returned Vector is never null, but if no group is    *      present in the ACL, it will be empty.    */   public Vector getGroupnameListNoAdmin(JahiaACLEntry entry)   {        Vector result = getGroupnameList (entry);        for (int i = 0; i < result.size(); i++) {            String adminGroup = (String)result.elementAt(i);            if (adminGroup.indexOf(JahiaGroupManagerService.ADMINISTRATORS_GROUPNAME) == 0)                result.removeElementAt(i--);        }        return result;   }   /**    * Return all the group 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    *      group names regarding their access rights.    *    * @return    *      Return a Vector holding all the String representation of the    *      groups' usernames. The returned Vector is never null, but if no    *      group is present in the ACL, it will be empty.    */   public Vector getGroupnameList(JahiaACLEntry entry)   {        Hashtable table = new Hashtable();        recursePermissions (null, table);        Vector result = getNameList (table, entry);        table = null;        return result;   }    /**     * Check the permission of a given group recursively from the acl tree.     *     * @param   group     *      Reference to a non-null group object.     * @param   permission     *      Bit index of the requested access, this index should be defined as     *      a constant in the derived classes.     * @return     *      True if the specified group has the requested rights in the ACL,     *      or in one of the parent's ACLs.     */    public boolean getPermission (JahiaGroup group, int permission)    {        boolean result = false;        if (group != null)        {            Hashtable table = new Hashtable();            recursePermissions (null, table);            JahiaACLEntry entry = (JahiaACLEntry)table.get (group.getName());            if (entry != null) {                result = (entry.getPermission (permission) ==                          JahiaACLEntry.ACL_YES);            }            table = null;            entry = null;        }        return result;    }    /**     * Check the permission of a given user recursively from the acl tree.     * @todo This code has to be reviewed     *     * @param   user     *      Reference to a non-null user object.     * @param   permission     *      Bit index of the requested access, this index should be defined as     *      a constant in the derived classes.     * @param siteID, the context used to retrieve the site's administrator group     *     * @return     *      True if the specified user has the requested rights in the ACL,     *      or in one of the parent's ACLs.     */    public boolean getPermission(JahiaUser user, int permission, int siteID)    {        int result = -1;        if (user == null) {            return false;        }        try {            // First check if the user is member of the administrators group.            // if it's the case, then give the user all the rights.            JahiaGroup adminGroup = ServicesRegistry.getInstance().getJahiaGroupManagerService().getAdministratorGroup (siteID);            if (adminGroup != null) {                if (adminGroup.isMember (user)) {                    result = 1;                }            }            //JahiaConsole.println(CLASS_NAME+".getPermission(user,perm)","step1 result=" + result);            if ( result == -1 ){                 adminGroup = null;                 // Compute recursively the user and group permission according to                 // the ACL entries flags.                 Hashtable userTable  = new Hashtable ();                 Hashtable groupTable = new Hashtable ();                 recursePermissions (userTable, groupTable);                 // Check if the user is explicitely mentioned in the ACL, look up                 // recursively the user in the tree.                 result = getUserPermissionInHashtable (user, permission, userTable);                //JahiaConsole.println(CLASS_NAME+".getPermission(user,perm)","step2 result=" + result);                 if (result == -1) {                     // seems the user has not been found directly in the ACL tree,                     // check now if the user is member of one of the specified group                     // in the ACL.                     result = getUserPermissionInGroupHashtable (user, permission,                                                                 groupTable);                 }                 //JahiaConsole.println(CLASS_NAME+".getPermission(user,perm)","step3 result=" + result);                 userTable = null;                 groupTable = null;            }        }        catch (NullPointerException ex) {            result = 0;        }        // return true only if one of the groups in the ACL tree has the        // requested permission and if the user is member of this group.        return (result == 1);   }   /**    * Convert the actual ACL object to String containing all neccessary information    * to verify the integrity.    *    * @return    *       The String to display    */   public String toString()   {        StringBuffer buffer = new StringBuffer ();        String key = null;        JahiaACLEntry entry = null;        buffer.append("\n");        buffer.append("Detail of ACL object [");        buffer.append(Integer.toString(mID));        buffer.append("] :\n");        buffer.append("  -ACL parent ID = ");        if (mParentACL != null) {            buffer.append (Integer.toString(mParentID));        } else {            buffer.append("-no parent-");        }        buffer.append("\n");        buffer.append("  -ACL inheritance = ");        buffer.append(Integer.toString(mInheritance));        buffer.append ("\n\n");        // get the user accesses        buffer.append ("  -Local user access : ");        Enumeration usernames = mUserEntries.keys();        if (usernames.hasMoreElements()) {            buffer.append ("\n");            while (usernames.hasMoreElements()) {                key = (String)usernames.nextElement();                entry = (JahiaACLEntry)mUserEntries.get (key);                int state = entry.getState();                int triState = entry.getTriState();                buffer.append ("    -"+key+" : ["+Integer.toBinaryString (state)+                               "] ["+Integer.toBinaryString (triState)+"]\n");            }        } else {            buffer.append ("-no users-\n");        }        // Get the group accesses        buffer.append ("  -Local group access : ");        Enumeration groupnames = mGroupEntries.keys();        if (groupnames.hasMoreElements()) {            buffer.append ("\n");            while (groupnames.hasMoreElements()) {                key = (String)groupnames.nextElement();                entry = (JahiaACLEntry)mGroupEntries.get (key);                int state = entry.getState();                int triState = entry.getTriState();                buffer.append ("    -"+key+" : ["+Integer.toBinaryString (state)+                               "] ["+Integer.toBinaryString (triState)+"]\n");            }        } else {            buffer.append ("-no groups-\n");        }        // Get the recursed permissions        Hashtable userTable  = new Hashtable ();        Hashtable groupTable = new Hashtable ();        recursePermissions (userTable, groupTable);        buffer.append ("  -recursed user access : ");        usernames = userTable.keys();        if (usernames.hasMoreElements()) {            buffer.append ("\n");            while (usernames.hasMoreElements()) {                key = (String)usernames.nextElement();                entry = (JahiaACLEntry)userTable.get (key);                int state = entry.getState();                int triState = entry.getTriState();                buffer.append ("    -"+key+" : ["+Integer.toBinaryString (state)+                               "] ["+Integer.toBinaryString (triState)+"]\n");            }        } else {            buffer.append ("-no users-\n");        }        buffer.append ("  -recursed group access : ");        groupnames = groupTable.keys();        if (groupnames.hasMoreElements()) {            buffer.append ("\n");            while (groupnames.hasMoreElements()) {                key = (String)groupnames.nextElement();                entry = (JahiaACLEntry)groupTable.get (key);                int state = entry.getState();                int triState = entry.getTriState();                buffer.append ("    -"+key+" : ["+Integer.toBinaryString (state)+                               "] ["+Integer.toBinaryString (triState)+"]\n");            }        } else {            buffer.append ("-no groups-\n");        }        usernames = null;        groupnames = null;        userTable = null;        groupTable = null;        key = null;        entry = null;        return buffer.toString();   }   /**    * 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 getUserPermissionInHashtable(JahiaUser user, int permission, Hashtable table)   {        int result = -1; // start as if the user was not found.        //check if the user is in entries        JahiaACLEntry entry = (JahiaACLEntry)table.get (user.getName());        if (entry != null)        {            switch (entry.getPermission (permission))

⌨️ 快捷键说明

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