📄 jahiaaclmanagerservice.java
字号:
//// ____.// __/\ ______| |__/\. _______// __ .____| | \ | +----+ \// _______| /--| | | - \ _ | : - \_________// \\______: :---| : : | : | \________>// |__\---\_____________:______: :____|____:_____\// /_____|//// . . . i n j a h i a w e t r u s t . . .////package org.jahia.services.acl;import java.util.Enumeration;import java.util.Hashtable;import java.util.Vector;import org.jahia.data.JahiaDOMObject;import org.jahia.exceptions.JahiaException;import org.jahia.exceptions.database.JahiaDatabaseException;import org.jahia.registries.ServicesRegistry;import org.jahia.services.JahiaService;import org.jahia.services.database.JahiaDBPoolService;import org.jahia.services.usermanager.JahiaGroup;import org.jahia.services.usermanager.JahiaUser;import org.jahia.utils.JahiaConsole;/** * ACL Services * * @author Fulco Houkes * @author MAP * @version 1.1 */public class JahiaACLManagerService extends JahiaService { private static JahiaACLManagerService mACLService; /** * @associates JahiaACL */ private Hashtable mACLCache; private JahiaDBPoolService mDBPoolService; private AclDBUtils mDBUtils; //------------------------------------------------------------------------- /** * Default constructor. * @throws JahiaException */ protected JahiaACLManagerService () throws JahiaException { final String TMP_MSG = "ACL Manager"; mACLCache = new Hashtable (); ServicesRegistry registry = ServicesRegistry.getInstance(); if (registry != null) { mDBPoolService = registry.getDBPoolService(); if (mDBPoolService == null) { throw new JahiaException (TMP_MSG, "ACL manager could not get the DB Connection Pool Service instance.", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } } else { throw new JahiaException (TMP_MSG, "ACL manager could not get the Service Registry instance.", JahiaException.REGISTRY_ERROR, JahiaException.CRITICAL); } mDBUtils = AclDBUtils.getInstance(); JahiaConsole.println ("JahiaACLManagerService", "Caching all ACLs from database"); mACLCache = mDBUtils.readAllACLs(); JahiaConsole.println ("JahiaACLManagerService : ", Integer.toString(mACLCache.size()) + " ACLs cached..."); } //------------------------------------------------------------------------- /** * Return the singleton instance of the ACL Manager service. * * @return Return the reterence on the ACL Manager Service. */ public static JahiaACLManagerService getInstance () { if (mACLService == null) { try { mACLService = new JahiaACLManagerService (); } catch (JahiaException ex) { return null; } } return mACLService; } //------------------------------------------------------------------------- /** * Create a new reference on a JahiaACL object. * * @param parent Reference on a parent JahiaACL object. Setting the * parent reference object ot null, means the object will * not be able to inherit access rights from a parent * object. * * @return Return a reference on a new ACL object. Return null if the * ACL object could not be created. */ public synchronized JahiaACL createACL (JahiaACL parent) { JahiaACL acl = null; // Get the next available user ID int aclID; try { aclID = mDBUtils.getNextID(); } catch (JahiaException ex) { return null; } // Create the ACL acl = new JahiaACL (aclID, parent, ACLInfo.INHERITANCE); // add the new acl in the cache. if (acl != null) { try { if (mDBUtils.addACLInDB (acl)) { mACLCache.put (new Integer(acl.getID()), acl); } else { acl = null; } } catch (JahiaDatabaseException ex) { acl = null; } } return acl; } //------------------------------------------------------------------------- /** * Return the specified ACL. * * @param aclID * Unique identification number of the required ACL. * * @return * Return the reference on the requested ACL * * @exception ACLNotFoundException * Throws this excption if the specified ACL is not present in the * system. * @exception JahiaDatabaseException * Thorws this exception on any database failure. */ public JahiaACL lookupACL (int aclID) throws ACLNotFoundException, JahiaDatabaseException { return (JahiaACL)mACLCache.get (new Integer(aclID)); } //------------------------------------------------------------------------- /** * Remove the specified ACL from DB also from cache. * * @param acl the ACL to remove. * @return true if no problems. */ public synchronized boolean deleteACL (JahiaACL acl) { boolean result = false; try { if (mDBUtils.deleteACLFromDB (acl)) { mACLCache.remove (new Integer(acl.getID())); result = true; } } catch (JahiaDatabaseException ex) { result = false; } return result; } //------------------------------------------------------------------------- /** * Remove the specified user from all Jahia ACLs. * * @param user The user in question. * @return true if no problems. */ public synchronized boolean removeUserFromAllACLs (JahiaUser user) { if (user == null) { return false; } boolean result = false; try { // remove the entries from the database if (mDBUtils.removeACLUserEntries (user.getName())) { JahiaACL acl; Enumeration enum = mACLCache.elements(); while (enum.hasMoreElements()) { acl = (JahiaACL)enum.nextElement(); if (acl != null) { JahiaConsole.println("JahiaACLManagerService.removeUserFromAllACLs","remove user from ACL : " + acl.getID() ); acl.removeUserEntry (user); } } result = true; } else { result = false; } } catch (JahiaDatabaseException ex) { result = false; } return result; } //------------------------------------------------------------------------- /** * Remove the specified group from all Jahia ACLs. * * @param group The group in question. * @return true if no problem. */ public synchronized boolean removeGroupFromAllACLs (JahiaGroup group) { if (group == null) { return false; } boolean result = false; try { if (mDBUtils.removeACLGroupEntries (group.getName())) { JahiaACL acl; Enumeration enum = mACLCache.keys(); while (enum.hasMoreElements()) { acl = (JahiaACL)mACLCache.get (enum.nextElement()); if (acl != null) { acl.removeGroupEntry (group); } } result = true; } else { result = false; } } catch (JahiaDatabaseException ex) { result = false; } return result; } //-------------------------------------------------------------------------- /** * return a DOM document of requested acl and all parents and their own parents... * * @param ids the list of acl ids * @param withParents if true, return parents too * * @return JahiaDOMObject a DOM representation of this object * @throws JahiaException * * @author NK */ public JahiaDOMObject getAclsAsDOM( Vector ids , boolean withParents ) throws JahiaException{ return mDBUtils.getAclsAsDOM(ids,withParents); } //-------------------------------------------------------------------------- /** * return a DOM document of requested acl entries * * @param ids the list of acl ids * * @return JahiaDOMObject a DOM representation of this object * @throws JahiaException * * @author NK */ public JahiaDOMObject getAclEntriesAsDOM( Vector ids ) throws JahiaException{ return mDBUtils.getAclEntriesAsDOM(ids); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -