📄 jahiausermanagerdbprovider.java
字号:
ServicesRegistry registry = ServicesRegistry.getInstance(); if (registry != null) { mDBPoolService = registry.getDBPoolService(); if (mDBPoolService == null) { throw new JahiaException (MSG_INTERNAL_ERROR, "User manager could not get the DB Connection Pool Service instance.", JahiaException.SERVICE_ERROR, JahiaException.CRITICAL); } 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); } } //-------------------------------------------------------------------------- // Executes and INSERT, UPDATE or DELETE SQL operation. This method should not // be used with and SELECT operation. This method lock the object on database // write access. private boolean makeQuery (String query) { // Get a database connection Connection dbConn = getDBConnection (2003); if (dbConn == null) { return false; } boolean result = false; Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { synchronized (this) { ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); result = true; } } } catch (SQLException sqlEx) { toConsole ("SQL Exception occured for query ["+query+"]"); // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { closeDBConnection (dbConn); closeStatement (statement); } return result; } //-------------------------------------------------------------------------- private boolean addUserIntoDB (int id, String username, String password, String userKey, int siteID, Properties properties) { // Get a database connection Connection dbConn = getDBConnection (1002); if (dbConn == null) { return false; } boolean result = true; String userIDStr = Integer.toString (id); Statement statement = null; try { statement = dbConn.createStatement(); String query = "INSERT INTO jahia_users (id_jahia_users, name_jahia_users, password_jahia_users, key_jahia_users, siteid_jahia_users) VALUES ("+ userIDStr+",'"+username+"','"+password+"','" + userKey + "'," + siteID + ")"; ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); // Add the user's attributes if (properties != null) { Enumeration enum = properties.propertyNames(); String name, value; if (enum.hasMoreElements()) { while (enum.hasMoreElements()) { name = (String)enum.nextElement(); value = properties.getProperty(name); query = "INSERT INTO jahia_user_prop (id_jahia_users, name_jahia_user_prop, value_jahia_user_prop)"+ " VALUES ("+userIDStr+",'" + name + "','" + value + "')"; ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,query); } } } } catch (SQLException sqlEx) { toConsole ("SQL Exception occured!"); result = false; } finally { closeDBConnection (dbConn); closeStatement (statement); } return result; } //-------------------------------------------------------------------------- private JahiaDBUser lookupUserInDB (int siteID, String name) { // Get a database connection Connection dbConn = getDBConnection (1003); if (dbConn == null) { return null; } JahiaDBUser user = null; Properties properties = new Properties(); // execute the SELECT query Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { String query = "SELECT id_jahia_users, password_jahia_users, key_jahia_users FROM jahia_users WHERE name_jahia_users='"+ name + "' and siteid_jahia_users=" + siteID; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { if (rs.next()) { int userID = rs.getInt("id_jahia_users"); String password = rs.getString ("password_jahia_users"); String userKey = rs.getString("key_jahia_users"); // Get all the user attributes query = "SELECT name_jahia_user_prop, value_jahia_user_prop FROM jahia_user_prop WHERE id_jahia_users="+ Integer.toString(userID); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement,query); if (rs != null) { String propName = null; String propVal = null; while (rs.next()) { propName = rs.getString("name_jahia_user_prop"); propVal = rs.getString ("value_jahia_user_prop"); if ( propVal == null ){ propVal = ""; } if ( propName != null ){ properties.put (propName, propVal); } } } user = new JahiaDBUser (userID, name, password, userKey, siteID, properties); } } } } catch (SQLException ex) { toConsole ("SQL Exception occured : Could not read the user ["+name+ "] from the database for site id ["+siteID+"]"); // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { closeDBConnection (dbConn); closeStatement (statement); } return user; } //-------------------------------------------------------------------------- private JahiaDBUser lookupUserInDB (String userKey) { // Get a database connection Connection dbConn = getDBConnection (1003); if (dbConn == null) { return null; } JahiaDBUser user = null; Properties properties = new Properties(); // execute the SELECT query Statement statement = null; try { statement = dbConn.createStatement(); if (statement != null) { String query = "SELECT id_jahia_users, name_jahia_users, password_jahia_users, siteid_jahia_users FROM jahia_users WHERE key_jahia_users='"+userKey+"'"; ResultSet rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery(statement,query); if (rs != null) { if (rs.next()) { int userID = rs.getInt("id_jahia_users"); String name = rs.getString("name_jahia_users"); String password = rs.getString ("password_jahia_users"); int siteID = rs.getInt("siteid_jahia_users"); // Get all the user attributes query = "SELECT name_jahia_user_prop, value_jahia_user_prop FROM jahia_user_prop WHERE id_jahia_users="+ Integer.toString(userID); rs = ServicesRegistry.getInstance().getDBPoolService().executeQuery (statement,query); if (rs != null) { String propName = null; String propVal = null; while (rs.next()) { propName = rs.getString("name_jahia_user_prop"); propVal = rs.getString ("value_jahia_user_prop"); if ( propVal == null ){ propVal = ""; } if ( propName != null ){ properties.put (propName, propVal); } } } user = new JahiaDBUser (userID, name, password, userKey, siteID, properties); } } } } catch (SQLException ex) { toConsole ("SQL Exception occured : Could not read the user ["+ userKey+"]"); // FIXME -Fulco- : Don't know yet what to do with this exception. // It should be logged somewhere ! } finally { closeDBConnection (dbConn); closeStatement (statement); } return user; } //-------------------------------------------------------------------------- private boolean deleteUserFromDB (JahiaUser user) { // Get a database connection Connection dbConn = getDBConnection (1004); if (dbConn == null) { return false; } boolean result = false; Statement statement = null; try { statement = dbConn.createStatement(); String tmpStr = "WHERE id_jahia_users="+Integer.toString (((JahiaDBUser)user).getID()); String query; ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,"DELETE FROM jahia_users "+tmpStr); ServicesRegistry.getInstance().getDBPoolService().executeUpdate (statement,"DELETE FROM jahia_user_prop "+tmpStr); result = true; } catch (SQLException sqlEx) { toConsole ("SQL Exception occured!"); } finally { try { ServicesRegistry.getInstance().getDBPoolService().freeConnection (dbConn); if (statement!=null) statement.close(); } catch (SQLException sqlEx) { toConsole ("deleteUserFromDB() : SQL Exception occured while freeing the connection pool."); } } return result; } //------------------------------------------------------------------------- // FH 2 May 2001 /** Return the amount of users in the database. * * @return * The amount of users. */ public synchronized int getNbUsers () throws JahiaException { return getNbUsers(-1); } //------------------------------------------------------------------------- /** * Return the number of user for a gived site * * @return * Return the number of users in the system. */ public int getNbUsers (int siteID) throws JahiaException{ int counter = 0; Connection dbConn = getDBConnection (713705); if (dbConn != null) { StringBuffer query = new StringBuffer (); Statement statement = null;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -