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

📄 jahiausermanagerldapprovider.java

📁 java 写的一个新闻发布系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    /**     * This method returns the list of this site's users' keys.     *     * @param siteID   an identifier for the site whose user list we can to     * retrieve     * @return Return a vector of strings holding the user identification key .     */    public Vector getUserList (int siteID){        return getUserList();    }    /**     * This method return all users' keys in the system.     *     * @return Return a vector of strings holding the user identification key .     */    public Vector getUserList (){        Vector result = new Vector();        try {            NamingEnumeration answer = getUsers(getPublicContext(), null);            while (answer.hasMore()) {                SearchResult sr = (SearchResult) answer.next();                JahiaUser curUser = ldapToJahiaUser(sr, null);                if (curUser != null) {                    result.add(curUser.getUserKey());                }            }        } catch (SizeLimitExceededException slee) {            // we just return the list as it is            JahiaConsole.println("JahiaUserManagerLDAPProvider.getUserList",                                 "Search generated more than configured maximum search limit in " +                                 DEFAULT_CONFIGURATION_FILE +                                 ", limiting to " +                                 this.ldapProperties.getProperty(SEARCH_COUNT_LIMIT_PROP) +                                 " first results...");        } catch (NamingException ne) {            JahiaConsole.printe("JahiaUserManagerLDAPProvider.getUserList", ne);            invalidatePublicCtx();            result = new Vector();        }        return result;    }    /**     * Find users according to a table of name=value properties. If the left     * side value is "*" for a property then it will be tested against all the     * properties. ie *=test* will match every property that starts with "test"     * @param siteID site identifier     * @param searchCriterias a Properties object that contains search criterias     * in the format name,value (for example "*"="*" or "username"="*test*") or     * null to search without criterias     * @return Set a set of JahiaUser elements that correspond to those     * search criterias, or an empty one if an error has occured. Note this will     * only return the configured limit of users at maxium. Check out the     * users.ldap.properties file to change the limit.     */    public Set searchUsers(int siteID, Properties searchCriterias) {        Set result = new HashSet();        try {            NamingEnumeration ldapUsers = getUsers(getPublicContext(), searchCriterias);            while (ldapUsers.hasMore()) {                SearchResult sr = (SearchResult) ldapUsers.next();                JahiaLDAPUser user = ldapToJahiaUser(sr, null);                if (user != null) {                    result.add(user);                }            }        } catch (SizeLimitExceededException slee) {            // JahiaConsole.printe("JahiaUserManagerLDAPProvider.searchUsers", slee);            // we just return the list as it is            JahiaConsole.println("JahiaUserManagerLDAPProvider.searchUsers",                                 "Search generated more than configured maximum search limit in " +                                 DEFAULT_CONFIGURATION_FILE +                                 ", limiting to " +                                 this.ldapProperties.getProperty(SEARCH_COUNT_LIMIT_PROP) +                                 " first results...");        } catch (NamingException ne) {            JahiaConsole.printe("JahiaUserManagerLDAPProvider.searchUsers", ne);            invalidatePublicCtx();            result = new HashSet();        }        return result;    }    /**     * Default constructor     *     * @exception  JahiaException   The user manager need some Jahia services to be     *      able to run correctly. If one of these services are not instanciated then a     *      JahiaException exception is thrown.     */    protected JahiaUserManagerLDAPProvider () throws JahiaException    {        mUserCache  = new Hashtable();        ServicesRegistry registry = ServicesRegistry.getInstance();        if (registry != null)        {            mIncrementorService = registry.getJahiaIncrementorsDBService();            if (mIncrementorService == null) {                throw new JahiaException (MSG_INTERNAL_ERROR,                                          "User manager could not get the Incrementors DB Service instance.",                                          JahiaException.SERVICE_ERROR,                                          JahiaException.CRITICAL);            }            mGroupService = (JahiaGroupManagerDBService)registry.getJahiaGroupManagerService();            if (mGroupService == null) {                throw new JahiaException (MSG_INTERNAL_ERROR,                                          "User manager could not get the Group Manager Service instance.",                                          JahiaException.SERVICE_ERROR,                                          JahiaException.CRITICAL);            }            mACLService = registry.getJahiaACLManagerService();            if (mACLService == null) {                throw new JahiaException (MSG_INTERNAL_ERROR,                                          "User manager could not get the ACL Manager Service instance.",                                          JahiaException.SERVICE_ERROR,                                          JahiaException.CRITICAL);            }        } else {            throw new JahiaException (MSG_INTERNAL_ERROR,                                      "User manager could not get the Service Registry instance.",                                      JahiaException.REGISTRY_ERROR,                                      JahiaException.CRITICAL);        }    }    public void init( JahiaPrivateSettings jSettings )    throws JahiaInitializationException {        String configPath = jSettings.jahiaLdapDiskPath;        String configFileName;        File configFile = new File(configPath + File.separator + DEFAULT_CONFIGURATION_FILE);        if (configFile.exists()) {            configFileName = configPath + File.separator + DEFAULT_CONFIGURATION_FILE;            try {                File ldapPropFile = new File (configFileName);                FileInputStream ldapPropInputStr = new FileInputStream(ldapPropFile);                ldapProperties = new Properties();                ldapProperties.load(ldapPropInputStr);                ldapPropInputStr.close();            } catch (FileNotFoundException fnfe) {                JahiaConsole.printe("UserLDAPService.init", fnfe);            } catch (IOException ioe) {                JahiaConsole.printe("UserLDAPService.init", ioe);            }        } else {            JahiaConsole.println("UserLDAPService.init",                                 "Config file not found in " + configPath + File.separator + DEFAULT_CONFIGURATION_FILE);        }        try {            publicCtx = connectToPublicDir();        } catch (NamingException ne) {            JahiaConsole.printe("JavaUserManagerLDAPProvider.init", ne);            invalidatePublicCtx();        }        String wildCardAttributeStr = ldapProperties.getProperty(this.SEARCH_WILDCARD_ATTRIBUTE_LIST);        if (wildCardAttributeStr != null) {            this.searchWildCardAttributeList = new Vector();            StringTokenizer wildCardTokens = new StringTokenizer(wildCardAttributeStr, ", ");            while (wildCardTokens.hasMoreTokens()) {                String curAttrName = wildCardTokens.nextToken().trim();                this.searchWildCardAttributeList.add(curAttrName);            }        }        JahiaConsole.println("JahiaUserManagerLDAPProvider.init", "Initialized and connected to public repository");    }    /** Return the amount of users in the database.     *     * @return     *      The amount of users.     * @throws JahiaException in case there's a problem retrieving the number     * of users from the storage     */    public synchronized int getNbUsers ()        throws  JahiaException    {        return -1;    }    /**     * Return the number of user for a gived site     *     * @param siteID the site identifier for which to retrieve the number of     * users     * @return     *      Return the number of users in the system.     * @throws JahiaException in case there is a problem retrieving the number     * of users for a given site.     */    public int getNbUsers (int siteID)    throws  JahiaException{        return getNbUsers();    }    /**     * This method returns the list of this site's users' ids.     *     * @param siteID the identifier for the site for which to retrieve userIDs     * @return Return a vector of strings holding the user ids .     */    private Vector getUserIds (int siteID){        Vector result = new Vector();        return result;    }    /**     * return a DOM document of all users of a site     *     * @param siteID the site id     *     * @return JahiaDOMObject a DOM representation of this object     * @throws JahiaException in case there is an error communicating with     * the storage system     *     */    public JahiaDOMObject getUsersAsDOM( int siteID )    throws JahiaException{        JahiaDBDOMObject dom = null;        return dom;    }    /**     * return a DOM document of all user props of a site     *     * @param siteID the site id     *     * @return JahiaDOMObject a DOM representation of this object     *     * @throws JahiaException in case there is a problem communicating with the     * storage backend system.     */    public JahiaDOMObject getUserPropsAsDOM( int siteID )    throws JahiaException{        JahiaDBDOMObject dom = null;        return dom;    }    //--------------------------------------------------------------------------    /**     * return a DOM document of all user group access for a site.     * Note : the actual implementation of LDAP user return all LDAP users in the system,     * not users of a given site only.     * Return an empty Dom for any siteID != 0. You must call it with a siteID == 0.     *     * @param int the site id     *     * @return JahiaDOMObject a DOM representation of this object     *     * @author NK     */    public JahiaDOMObject getUserGroupAccessAsDOM(int siteID)    throws JahiaException{        class UsrGrpAccessFilter implements DBRowDataFilter {            public UsrGrpAccessFilter(){            }            public boolean inValue(Hashtable vals){                if ( vals == null ){                    return false;                }                String val = null;                try {                    val = (String)vals.get("id_jahia_member");                    return ( val.startsWith(JahiaLDAPUser.USERKEY_LDAP_PREFIX) );                } catch ( Throwable t ){                    JahiaConsole.println("getUserGroupAccessAsDOM","Error parsing " + val);                    //t.printStackTrace();                }                return false;            }        }        Connection dbConn = null;        Statement statement = null;        String output = null;        JahiaDBDOMObject dom = null;        if ( siteID != 0 ){ // Actually LDAP users are not attached to a site but to all sites.            dom = new JahiaDBDOMObject();            return dom;        }        UsrGrpAccessFilter usrGrpAccessFilter = new UsrGrpAccessFilter();        try {            String sqlQuery = "SELECT * FROM jahia_grp_access";            dbConn = getDBConnection(0);            statement = dbConn.createStatement();            if (statement != null) {                ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery( statement,sqlQuery );                if (rs != null) {                    dom = new JahiaDBDOMObject();                    dom.addTable("jahia_grp_access",rs,usrGrpAccessFilter);                    return dom;                }            }        } catch (SQLException se) {            String errorMsg = "Error in getUserGroupAccessAsDOM(int siteID) : " + se.getMessage();            JahiaConsole.println( "JahiaGroupManagerDBService", errorMsg );            throw new JahiaException(   "Cannot load groups from the database",                                        errorMsg, JahiaException.DATABASE_ERROR,                                        JahiaException.CRITICAL );        } finally {            closeDBConnection (dbConn);            closeStatement (statement);        }        return dom;    }

⌨️ 快捷键说明

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