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

📄 rdbmuseridentitystore.java

📁 uPortal是开放源码的Portal门户产品
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                   int newUID = CounterStoreFactory.getCounterStoreImpl().getIncrementIntegerId("UP_USER");                                      // Add new user to all appropriate tables                   int newPortalUID = addNewUser(newUID, person, templateUser);                   portalUser = new PortalUser();                   portalUser.setUserId(newPortalUID);               }           }           else if (portalUser == null) {               //If this is a new user and we can't create them               throw new AuthorizationException("No portal information exists for user " + userName);           }       } catch (Exception e) {           log.error( "RDBMUserIdentityStore::getPortalUID()", e);           throw new AuthorizationException(e.getMessage(), e);       }            return portalUser.getUserId();   }  static final protected void commit (Connection connection) {    try {      if (RDBMServices.supportsTransactions)        connection.commit();    } catch (Exception e) {      log.error( "RDBMUserIdentityStore::commit(): " + e);    }  }  static final protected void rollback (Connection connection) {    try {      if (RDBMServices.supportsTransactions)        connection.rollback();    } catch (Exception e) {      log.error( "RDBMUserIdentityStore::rollback(): " + e);    }  }    /**   * Gets the PortalUser data store object for the specified user name.   *    * @param userName The user's name   * @return A PortalUser object or null if the user doesn't exist.   * @throws Exception   */  protected PortalUser getPortalUser(String userName) throws Exception {      PortalUser portalUser = null;            Connection con = null;      try {          con = RDBMServices.getConnection();          PreparedStatement pstmt = null;                    try {              String query = "SELECT USER_ID, USER_DFLT_USR_ID FROM UP_USER WHERE USER_NAME=?";                            pstmt = con.prepareStatement(query);              pstmt.setString(1, userName);                            ResultSet rs = null;              try {                  log.debug("RDBMUserIdentityStore::getPortalUID(userName=" + userName + "): " + query);                  rs = pstmt.executeQuery();                  if (rs.next()) {                      portalUser = new PortalUser();                      portalUser.setUserId(rs.getInt("USER_ID"));                      portalUser.setUserName(userName);                      portalUser.setDefaultUserId(rs.getInt("USER_DFLT_USR_ID"));                  }              } finally {                  try { rs.close(); } catch (Exception e) {}              }          } finally {              try { pstmt.close(); } catch (Exception e) {}          }      } finally {          try { RDBMServices.releaseConnection(con); } catch (Exception e) {}      }             return portalUser;  }    protected String getTemplateName(IPerson person) {      String templateName = (String)person.getAttribute(templateAttrName);      // Just use the default template if requested template not populated      if (templateName == null || templateName.equals("")) {          templateName = defaultTemplateUserName;      }      return templateName;  }  /**   * Gets the TemplateUser data store object for the specified template user name.   *    * @param templateUserName The template user's name   * @return A TemplateUser object or null if the user doesn't exist.   * @throws Exception   */  protected TemplateUser getTemplateUser(String templateUserName) throws Exception {      TemplateUser templateUser = null;              Connection con = null;      try {          con = RDBMServices.getConnection();          PreparedStatement pstmt = null;          try {              String query = "SELECT USER_ID, USER_DFLT_LAY_ID FROM UP_USER WHERE USER_NAME=?";                            pstmt = con.prepareStatement(query);              pstmt.setString(1, templateUserName);                            ResultSet rs = null;              try {                  log.debug("RDBMUserIdentityStore::getTemplateUser(templateUserName=" + templateUserName + "): " + query);                  rs = pstmt.executeQuery();                  if (rs.next()) {                      templateUser = new TemplateUser();                      templateUser.setUserName(templateUserName);                      templateUser.setUserId(rs.getInt("USER_ID"));                      templateUser.setDefaultLayoutId(rs.getInt("USER_DFLT_LAY_ID"));                  } else {                      if (!templateUserName.equals(defaultTemplateUserName)) {                          templateUser = getTemplateUser(defaultTemplateUserName);                      }                  }              } finally {                  try { rs.close(); } catch (Exception e) {}              }          } finally {              try { pstmt.close(); } catch (Exception e) {}          }      } finally {          try { RDBMServices.releaseConnection(con); } catch (Exception e) {}      }             return templateUser;  }    protected boolean userHasSavedLayout(int userId) throws Exception {      boolean userHasSavedLayout = false;      Connection con = null;      try {          con = RDBMServices.getConnection();          PreparedStatement pstmt = null;          try {              String query = "SELECT * FROM UP_USER_PROFILE WHERE USER_ID=? AND LAYOUT_ID IS NOT NULL";                            pstmt = con.prepareStatement(query);              pstmt.setInt(1, userId);                            ResultSet rs = null;              try {                  log.debug("RDBMUserIdentityStore::getTemplateUser(userId=" + userId + "): " + query);                  rs = pstmt.executeQuery();                  if (rs.next()) {                      userHasSavedLayout = true;                  }              } finally {                  try { rs.close(); } catch (Exception e) {}              }          } finally {              try { pstmt.close(); } catch (Exception e) {}          }      } finally {          try { RDBMServices.releaseConnection(con); } catch (Exception e) {}      }            return userHasSavedLayout;  }    protected void updateUser(int userId, IPerson person, TemplateUser templateUser) throws Exception {      // Remove my existing group memberships      IGroupMember me = GroupService.getGroupMember(person.getEntityIdentifier());       Iterator myExistingGroups = me.getContainingGroups();      while (myExistingGroups.hasNext()) {          IEntityGroup eg = (IEntityGroup)myExistingGroups.next();          if (eg.isEditable()) {            eg.removeMember(me);            eg.updateMembers();          }      }            // Copy template user's groups memberships      IGroupMember template = GroupService.getEntity(templateUser.getUserName(), Class.forName("org.jasig.portal.security.IPerson"));      Iterator templateGroups = template.getContainingGroups();      while (templateGroups.hasNext()) {          IEntityGroup eg = (IEntityGroup)templateGroups.next();          if (eg.isEditable()) {            eg.addMember(me);            eg.updateMembers();          }              }                    Connection con = null;      try {          con = RDBMServices.getConnection();          // Turn off autocommit if the database supports it          if (RDBMServices.supportsTransactions)              con.setAutoCommit(false);                  PreparedStatement deleteStmt = null;          PreparedStatement queryStmt = null;          PreparedStatement insertStmt = null;          try {              // Update UP_USER              String update =                  "UPDATE UP_USER " +                  "SET USER_DFLT_USR_ID=?, " +                      "USER_DFLT_LAY_ID=?, " +                      "NEXT_STRUCT_ID=null " +                  "WHERE USER_ID=?";                            insertStmt = con.prepareStatement(update);              insertStmt.setInt(1, templateUser.getUserId());              insertStmt.setInt(2, templateUser.getDefaultLayoutId());              insertStmt.setInt(3, userId);                            log.debug("RDBMUserIdentityStore::addNewUser(): " + update);              insertStmt.executeUpdate();              insertStmt.close();                                            // Start copying...              ResultSet rs = null;              String delete = null;              String query = null;              String insert = null;              try {                                    // Update UP_USER_PARAM                  delete =                      "DELETE FROM UP_USER_PARAM " +                      "WHERE USER_ID=?";                  deleteStmt = con.prepareStatement(delete);                  deleteStmt.setInt(1, userId);                  log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + userId + "): " + delete);                  deleteStmt.executeUpdate();                  deleteStmt.close();                  query =                      "SELECT USER_ID, USER_PARAM_NAME, USER_PARAM_VALUE " +                      "FROM UP_USER_PARAM " +                      "WHERE USER_ID=?";                   queryStmt = con.prepareStatement(query);                  queryStmt.setInt(1, templateUser.getUserId());                  log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + templateUser.getUserId() + "): " + query);                  rs = queryStmt.executeQuery();                                    while (rs.next()) {                      insert =                          "INSERT INTO UP_USER_PARAM (USER_ID, USER_PARAM_NAME, USER_PARAM_VALUE) " +                          "VALUES(?, ?, ?)";                                                  String userParamName = rs.getString("USER_PARAM_NAME");                      String userParamValue = rs.getString("USER_PARAM_VALUE");                                            insertStmt = con.prepareStatement(insert);                      insertStmt.setInt(1, userId);                      insertStmt.setString(2, userParamName);                      insertStmt.setString(3, userParamValue);                                            log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + userId + ", USER_PARAM_NAME=" + userParamName + ", USER_PARAM_VALUE=" + userParamValue + "): " + insert);                      insertStmt.executeUpdate();                                         }                  rs.close();                  queryStmt.close();                  insertStmt.close();                                                      // Update UP_USER_PROFILE                                      delete =                      "DELETE FROM UP_USER_PROFILE " +                      "WHERE USER_ID=?";                  deleteStmt = con.prepareStatement(delete);                  deleteStmt.setInt(1, userId);                  log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + userId + "): " + delete);                  deleteStmt.executeUpdate();                  deleteStmt.close();                                    query =                       "SELECT USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION " +                      "FROM UP_USER_PROFILE " +                      "WHERE USER_ID=?";                  queryStmt = con.prepareStatement(query);                  queryStmt.setInt(1, templateUser.getUserId());                  log.debug("RDBMUserIdentityStore::updateUser(USER_ID=" + templateUser.getUserId() + "): " + query);                  rs = queryStmt.executeQuery();                                    while (rs.next()) {                      insert =                          "INSERT INTO UP_USER_PROFILE (USER_ID, PROFILE_ID, PROFILE_NAME, DESCRIPTION, LAYOUT_ID, STRUCTURE_SS_ID, THEME_SS_ID) " +                          "VALUES(?, ?, ?, ?, NULL, NULL, NULL)";                        

⌨️ 快捷键说明

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