/** * Reads the owner of a project.<p> * * @param dbc the current database context * @param project the project to get the owner from * * @return the owner of a resource * @throws CmsException if something goes wrong */ public CmsUser readOwner(CmsDbContext dbc, CmsProject project) throws CmsException { return readUser(dbc, project.getOwnerId()); }
/** * Reads the owner of a project.<p> * * @param dbc the current database context * @param project the project to get the owner from * * @return the owner of a resource * @throws CmsException if something goes wrong */ public CmsUser readOwner(CmsDbContext dbc, CmsProject project) throws CmsException { return readUser(dbc, project.getOwnerId()); }
/** * Returns the user identified by the given id.<p> * * @param userId the id of the user to retrieve * * @return the user identified by the given id */ protected CmsUser getUser(CmsUUID userId) { CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { return m_driverManager.readUser(dbc, userId); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } return null; }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }
/** * Returns the user, who had locked the resource.<p> * * A user can lock a resource, so he is the only one who can write this * resource. This methods checks, if a resource was locked. * * @param dbc the current database context * @param resource the resource * * @return the user, who had locked the resource * * @throws CmsException will be thrown, if the user has not the rights for this resource */ public CmsUser lockedBy(CmsDbContext dbc, CmsResource resource) throws CmsException { return readUser(dbc, m_lockManager.getLock(dbc, resource).getEditionLock().getUserId()); }
/** * Returns the user, who had locked the resource.<p> * * A user can lock a resource, so he is the only one who can write this * resource. This methods checks, if a resource was locked. * * @param dbc the current database context * @param resource the resource * * @return the user, who had locked the resource * * @throws CmsException will be thrown, if the user has not the rights for this resource */ public CmsUser lockedBy(CmsDbContext dbc, CmsResource resource) throws CmsException { return readUser(dbc, m_lockManager.getLock(dbc, resource).getEditionLock().getUserId()); }
/** * Returns the user identified by the given id.<p> * * @param userId the id of the user to retrieve * * @return the user identified by the given id */ protected CmsUser getUser(CmsUUID userId) { CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { return m_driverManager.readUser(dbc, userId); } catch (CmsException e) { dbc.rollback(); LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } return null; }
/** * Sets the driver manager instance.<p> * * @param driverManager the driver manager instance */ public void setDriverManager(CmsDriverManager driverManager) { m_driverManager = driverManager; CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { m_adminUserId = m_driverManager.readUser(dbc, OpenCms.getDefaultUsers().getUserAdmin()).getId(); } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } }
/** * Updates the user information. <p> * * The user id has to be a valid OpenCms user id.<br> * * The user with the given id will be completely overridden * by the given data.<p> * * @param dbc the current database context * @param user the user to be updated * * @throws CmsException if operation was not successful */ public void writeUser(CmsDbContext dbc, CmsUser user) throws CmsException { CmsUser oldUser = readUser(dbc, user.getId()); m_monitor.clearUserCache(oldUser); m_userDriver.writeUser(dbc, user); m_monitor.flushCache(CmsMemoryMonitor.CacheType.USERGROUPS); // fire user modified event Map eventData = new HashMap(); eventData.put(I_CmsEventListener.KEY_USER_ID, user.getId().toString()); eventData.put(I_CmsEventListener.KEY_USER_NAME, oldUser.getName()); eventData.put(I_CmsEventListener.KEY_USER_ACTION, I_CmsEventListener.VALUE_USER_MODIFIED_ACTION_WRITE_USER); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_USER_MODIFIED, eventData)); }
/** * Updates the user information. <p> * * The user id has to be a valid OpenCms user id.<br> * * The user with the given id will be completely overridden * by the given data.<p> * * @param dbc the current database context * @param user the user to be updated * * @throws CmsException if operation was not successful */ public void writeUser(CmsDbContext dbc, CmsUser user) throws CmsException { CmsUser oldUser = readUser(dbc, user.getId()); m_monitor.clearUserCache(oldUser); getUserDriver(dbc).writeUser(dbc, user); m_monitor.flushCache(CmsMemoryMonitor.CacheType.USERGROUPS, CmsMemoryMonitor.CacheType.USER_LIST); if (!dbc.getProjectId().isNullUUID()) { // user modified event is not needed return; } // fire user modified event Map<String, Object> eventData = new HashMap<String, Object>(); eventData.put(I_CmsEventListener.KEY_USER_ID, user.getId().toString()); eventData.put(I_CmsEventListener.KEY_USER_NAME, oldUser.getName()); eventData.put(I_CmsEventListener.KEY_USER_ACTION, I_CmsEventListener.VALUE_USER_MODIFIED_ACTION_WRITE_USER); eventData.put(I_CmsEventListener.KEY_USER_CHANGES, Integer.valueOf(user.getChanges(oldUser))); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_USER_MODIFIED, eventData)); }
/** * Sets the driver manager instance.<p> * * @param driverManager the driver manager instance */ public void setDriverManager(CmsDriverManager driverManager) { m_driverManager = driverManager; CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { m_adminUserId = m_driverManager.readUser(dbc, OpenCms.getDefaultUsers().getUserAdmin()).getId(); } catch (CmsException e) { dbc.rollback(); LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } }
/** * Sends a message to the given user, if publish notification is enabled or an error is shown in the message.<p> * * @param toUserId the id of the user to send the message to * @param message the message to send * @param hasErrors flag to determine if the message to send shows an error */ protected void sendMessage(CmsUUID toUserId, String message, boolean hasErrors) { CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { CmsUser toUser = m_driverManager.readUser(dbc, toUserId); CmsUserSettings settings = new CmsUserSettings(toUser); if (settings.getShowPublishNotification() || hasErrors) { // only show message if publish notification is enabled or the message shows an error OpenCms.getSessionManager().sendBroadcast(null, message, toUser); } } catch (CmsException e) { LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } }
/** * Sends a message to the given user, if publish notification is enabled or an error is shown in the message.<p> * * @param toUserId the id of the user to send the message to * @param message the message to send * @param hasErrors flag to determine if the message to send shows an error */ protected void sendMessage(CmsUUID toUserId, String message, boolean hasErrors) { CmsDbContext dbc = m_dbContextFactory.getDbContext(); try { CmsUser toUser = m_driverManager.readUser(dbc, toUserId); CmsUserSettings settings = new CmsUserSettings(toUser); if (settings.getShowPublishNotification() || hasErrors) { // only show message if publish notification is enabled or the message shows an error OpenCms.getSessionManager().sendBroadcast(null, message, toUser); } } catch (CmsException e) { dbc.rollback(); LOG.error(e.getLocalizedMessage(), e); } finally { dbc.clear(); } }
/** * Returns a user object based on the id of a user.<p> * * @param context the current request context * @param id the id of the user to read * * @return the user read * * @throws CmsException if something goes wrong */ public CmsUser readUser(CmsRequestContext context, CmsUUID id) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); CmsUser result = null; try { result = m_driverManager.readUser(dbc, id); } catch (Exception e) { dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_ID_1, id.toString()), e); } finally { dbc.clear(); } return result; }
/** * Returns a user object.<p> * * @param context the current request context * @param username the name of the user that is to be read * * @return user read form the cms * * @throws CmsException if operation was not successful */ public CmsUser readUser(CmsRequestContext context, String username) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); CmsUser result = null; try { result = m_driverManager.readUser(dbc, CmsOrganizationalUnit.removeLeadingSeparator(username)); } catch (Exception e) { dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e); } finally { dbc.clear(); } return result; }
/** * Returns a user object based on the id of a user.<p> * * @param context the current request context * @param id the id of the user to read * * @return the user read * * @throws CmsException if something goes wrong */ public CmsUser readUser(CmsRequestContext context, CmsUUID id) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); CmsUser result = null; try { result = m_driverManager.readUser(dbc, id); } catch (Exception e) { dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_ID_1, id.toString()), e); } finally { dbc.clear(); } return result; }
/** * Returns a user object.<p> * * @param context the current request context * @param username the name of the user that is to be read * * @return user read form the cms * * @throws CmsException if operation was not successful */ public CmsUser readUser(CmsRequestContext context, String username) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); CmsUser result = null; try { result = m_driverManager.readUser(dbc, CmsOrganizationalUnit.removeLeadingSeparator(username)); } catch (Exception e) { dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e); } finally { dbc.clear(); } return result; }
/** * Returns a user object if the password for the user is correct.<p> * * If the user/password pair is not valid a <code>{@link CmsException}</code> is thrown.<p> * * @param context the current request context * @param username the user name of the user that is to be read * @param password the password of the user that is to be read * * @return user read * * @throws CmsException if operation was not successful */ public CmsUser readUser(CmsRequestContext context, String username, String password) throws CmsException { CmsDbContext dbc = m_dbContextFactory.getDbContext(context); CmsUser result = null; try { result = m_driverManager.readUser(dbc, CmsOrganizationalUnit.removeLeadingSeparator(username), password); } catch (Exception e) { dbc.report(null, Messages.get().container(Messages.ERR_READ_USER_FOR_NAME_1, username), e); } finally { dbc.clear(); } return result; }
/** * Enumeration class for the mode parameter in the * {@link CmsDriverManager#readChangedResourcesInsideProject(CmsDbContext, CmsUUID, CmsReadChangedProjectResourceMode)} * method.<p> */ private static class CmsReadChangedProjectResourceMode { /** * Default constructor.<p> */ protected CmsReadChangedProjectResourceMode() { // noop } }
/** * Checks that the current user has enough permissions to modify the given user.<p> * * @param dbc the database context * @param username the name of the user to modify * @param role the needed role * * @throws CmsDataAccessException if something goes wrong accessing the database * @throws CmsRoleViolationException if the user has not the needed permissions */ protected void checkRoleForUserModification(CmsDbContext dbc, String username, CmsRole role) throws CmsDataAccessException, CmsRoleViolationException { CmsUser userToModify = m_driverManager.readUser(dbc, CmsOrganizationalUnit.removeLeadingSeparator(username)); if (dbc.currentUser().equals(userToModify)) { // a user is allowed to write his own data return; } if (hasRole(dbc, dbc.currentUser(), CmsRole.ROOT_ADMIN)) { // a user with the ROOT_ADMIN role may change any other user return; } if (hasRole(dbc, userToModify, CmsRole.ADMINISTRATOR)) { // check the user that is going to do the modification is administrator checkRole(dbc, CmsRole.ADMINISTRATOR); } else { // check the user that is going to do the modification has the given role checkRole(dbc, role); } }