/** * Returns the groups of an user filtered by the specified IP address.<p> * * @param dbc the current database context * @param username the name of the user * @param readRoles if to read roles or groups * * @return the groups of the given user, as a list of {@link CmsGroup} objects * * @throws CmsException if something goes wrong */ public List<CmsGroup> getGroupsOfUser(CmsDbContext dbc, String username, boolean readRoles) throws CmsException { return getGroupsOfUser(dbc, username, "", true, readRoles, false, dbc.getRequestContext().getRemoteAddress()); }
/** * Returns the groups of an user filtered by the specified IP address.<p> * * @param dbc the current database context * @param username the name of the user * @param readRoles if to read roles or groups * * @return the groups of the given user, as a list of {@link CmsGroup} objects * * @throws CmsException if something goes wrong */ public List getGroupsOfUser(CmsDbContext dbc, String username, boolean readRoles) throws CmsException { return getGroupsOfUser(dbc, username, "", true, readRoles, false, dbc.getRequestContext().getRemoteAddress()); }
/** * @see org.opencms.db.I_CmsProjectDriver#readProjects(org.opencms.db.CmsDbContext, String) */ public List<CmsProject> readProjects(CmsDbContext dbc, String ouFqn) throws CmsDataAccessException { if ((dbc.getRequestContext() != null) && (dbc.getRequestContext().getAttribute(DBC_ATTR_READ_PROJECT_FOR_RESOURCE) != null)) { dbc.getRequestContext().removeAttribute(DBC_ATTR_READ_PROJECT_FOR_RESOURCE); // TODO: this should get its own method in the interface return readProjectsForResource(dbc, ouFqn); } List<CmsProject> projects = new ArrayList<CmsProject>(); try { // create the statement Query q = m_sqlManager.createQuery(dbc, C_PROJECTS_READ_BYOU_1); q.setParameter(1, CmsOrganizationalUnit.SEPARATOR + ouFqn + "%"); List<CmsDAOProjects> res = q.getResultList(); for (CmsDAOProjects p : res) { projects.add(internalCreateProject(p)); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } return (projects); }
/** * Checks if the user of the current database context has permissions to impersonate the given role * for the given resource.<p> * * @param dbc the current OpenCms users database context * @param role the role to check * @param resource the resource to check the role for * * @throws CmsRoleViolationException if the user does not have the required role permissions * * @see org.opencms.security.CmsRoleManager#checkRole(CmsObject, CmsRole) */ public void checkRoleForResource(CmsDbContext dbc, CmsRole role, CmsResource resource) throws CmsRoleViolationException { if (!hasRoleForResource(dbc, dbc.currentUser(), role, resource)) { throw role.createRoleViolationExceptionForResource(dbc.getRequestContext(), resource); } }
/** * Checks if the user of the current database context has permissions to impersonate the given role * for the given resource.<p> * * @param dbc the current OpenCms users database context * @param role the role to check * @param resource the resource to check the role for * * @throws CmsRoleViolationException if the user does not have the required role permissions * * @see org.opencms.security.CmsRoleManager#checkRole(CmsObject, CmsRole) */ public void checkRoleForResource(CmsDbContext dbc, CmsRole role, CmsResource resource) throws CmsRoleViolationException { if (!hasRoleForResource(dbc, dbc.currentUser(), role, resource)) { throw role.createRoleViolationExceptionForResource(dbc.getRequestContext(), resource); } }
if ((dbc.getRequestContext() != null) && (dbc.getRequestContext().getAttribute(DBC_ATTR_READ_PROJECT_FOR_RESOURCE) != null)) { dbc.getRequestContext().removeAttribute(DBC_ATTR_READ_PROJECT_FOR_RESOURCE);
/** * Returns the list of organizational units the given resource belongs to.<p> * * @param dbc the current database context * @param resource the resource * * @return list of {@link CmsOrganizationalUnit} objects * * @throws CmsException if something goes wrong */ public List getResourceOrgUnits(CmsDbContext dbc, CmsResource resource) throws CmsException { try { dbc.getRequestContext().setAttribute(I_CmsVfsDriver.REQ_ATTR_RESOURCE_OUS, Boolean.TRUE); return m_vfsDriver.readRelations( dbc, dbc.currentProject().getUuid(), resource, CmsRelationFilter.TARGETS.filterIncludeChildren()); } finally { dbc.getRequestContext().removeAttribute(I_CmsVfsDriver.REQ_ATTR_RESOURCE_OUS); } }
/** * Checks if the user of the current database context has permissions to impersonate the given role * in the given organizational unit.<p> * * If the organizational unit is <code>null</code>, this method will check if the * given user has the given role for at least one organizational unit.<p> * * @param dbc the current OpenCms users database context * @param role the role to check * * @throws CmsRoleViolationException if the user does not have the required role permissions * * @see org.opencms.security.CmsRoleManager#checkRole(CmsObject, CmsRole) */ public void checkRole(CmsDbContext dbc, CmsRole role) throws CmsRoleViolationException { if (!hasRole(dbc, dbc.currentUser(), role)) { if (role.getOuFqn() != null) { throw role.createRoleViolationExceptionForOrgUnit(dbc.getRequestContext(), role.getOuFqn()); } else { throw role.createRoleViolationException(dbc.getRequestContext()); } } }
/** * Checks if the user of the current database context has permissions to impersonate the given role * in the given organizational unit.<p> * * If the organizational unit is <code>null</code>, this method will check if the * given user has the given role for at least one organizational unit.<p> * * @param dbc the current OpenCms users database context * @param role the role to check * * @throws CmsRoleViolationException if the user does not have the required role permissions * * @see org.opencms.security.CmsRoleManager#checkRole(CmsObject, CmsRole) */ public void checkRole(CmsDbContext dbc, CmsRole role) throws CmsRoleViolationException { if (!hasRole(dbc, dbc.currentUser(), role)) { if (role.getOuFqn() != null) { throw role.createRoleViolationExceptionForOrgUnit(dbc.getRequestContext(), role.getOuFqn()); } else { throw role.createRoleViolationException(dbc.getRequestContext()); } } }
CmsObject cms = new CmsObject(getSecurityManager(), dbc.getRequestContext()); Iterator itRelations = getRelationsForResource( dbc,
/** * @see org.opencms.db.I_CmsUserDriver#writePassword(org.opencms.db.CmsDbContext, java.lang.String, java.lang.String, java.lang.String) */ public void writePassword(CmsDbContext dbc, String userFqn, String oldPassword, String newPassword) throws CmsDataAccessException, CmsPasswordEncryptionException { // check if the old password is valid if (oldPassword != null) { readUser(dbc, userFqn, oldPassword, ""); } String pwd = newPassword; if (dbc.getRequestContext().getAttribute(REQ_ATTR_DONT_DIGEST_PASSWORD) == null) { pwd = OpenCms.getPasswordHandler().digest(newPassword); } try { Query q = m_sqlManager.createQuery(dbc, C_USERS_SET_PWD_3); q.setParameter(1, CmsOrganizationalUnit.getSimpleName(userFqn)); q.setParameter(2, CmsOrganizationalUnit.SEPARATOR + CmsOrganizationalUnit.getParentFqn(userFqn)); List<CmsDAOUsers> res = q.getResultList(); for (CmsDAOUsers u : res) { u.setUserPassword(pwd); } } catch (PersistenceException e) { throw new CmsDataAccessException(Messages.get().container(Messages.ERR_JPA_PERSITENCE_1, e), e); } }
/** * @see org.opencms.db.I_CmsUserDriver#writePassword(org.opencms.db.CmsDbContext, java.lang.String, java.lang.String, java.lang.String) */ public void writePassword(CmsDbContext dbc, String userFqn, String oldPassword, String newPassword) throws CmsDataAccessException, CmsPasswordEncryptionException { PreparedStatement stmt = null; Connection conn = null; // check if the old password is valid if (oldPassword != null) { readUser(dbc, userFqn, oldPassword, ""); } String pwd = newPassword; if (dbc.getRequestContext().getAttribute(REQ_ATTR_DONT_DIGEST_PASSWORD) == null) { pwd = OpenCms.getPasswordHandler().digest(newPassword); } try { conn = getSqlManager().getConnection(dbc); stmt = m_sqlManager.getPreparedStatement(conn, "C_USERS_SET_PWD_3"); stmt.setString(1, pwd); stmt.setString(2, CmsOrganizationalUnit.getSimpleName(userFqn)); stmt.setString(3, CmsOrganizationalUnit.SEPARATOR + CmsOrganizationalUnit.getParentFqn(userFqn)); stmt.executeUpdate(); } catch (SQLException e) { throw new CmsDbSqlException(Messages.get().container( Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e); } finally { m_sqlManager.closeAll(dbc, conn, stmt, null); } }
/** * @see org.opencms.db.I_CmsUserDriver#writePassword(org.opencms.db.CmsDbContext, java.lang.String, java.lang.String, java.lang.String) */ public void writePassword(CmsDbContext dbc, String userFqn, String oldPassword, String newPassword) throws CmsDataAccessException, CmsPasswordEncryptionException { PreparedStatement stmt = null; Connection conn = null; // check if the old password is valid if (oldPassword != null) { readUser(dbc, userFqn, oldPassword, ""); } String pwd = newPassword; if (dbc.getRequestContext().getAttribute(REQ_ATTR_DONT_DIGEST_PASSWORD) == null) { pwd = OpenCms.getPasswordHandler().digest(newPassword); } try { conn = getSqlManager().getConnection(dbc); stmt = m_sqlManager.getPreparedStatement(conn, "C_USERS_SET_PWD_3"); stmt.setString(1, pwd); stmt.setString(2, CmsOrganizationalUnit.getSimpleName(userFqn)); stmt.setString(3, CmsOrganizationalUnit.SEPARATOR + CmsOrganizationalUnit.getParentFqn(userFqn)); stmt.executeUpdate(); } catch (SQLException e) { throw new CmsDbSqlException( Messages.get().container(Messages.ERR_GENERIC_SQL_1, CmsDbSqlException.getErrorQuery(stmt)), e); } finally { m_sqlManager.closeAll(dbc, conn, stmt, null); } }
/** * Repairs broken categories.<p> * * @param dbc the database context * @param projectId the project id * @param resource the resource to repair the categories for * * @throws CmsException if something goes wrong */ public void repairCategories(CmsDbContext dbc, CmsUUID projectId, CmsResource resource) throws CmsException { CmsObject cms = OpenCms.initCmsObject(new CmsObject(getSecurityManager(), dbc.getRequestContext())); cms.getRequestContext().setSiteRoot(""); cms.getRequestContext().setCurrentProject(readProject(dbc, projectId)); CmsCategoryService.getInstance().repairRelations(cms, resource); }
/** * Repairs broken categories.<p> * * @param dbc the database context * @param projectId the project id * @param resource the resource to repair the categories for * * @throws CmsException if something goes wrong */ public void repairCategories(CmsDbContext dbc, CmsUUID projectId, CmsResource resource) throws CmsException { CmsObject cms = OpenCms.initCmsObject(new CmsObject(getSecurityManager(), dbc.getRequestContext())); cms.getRequestContext().setSiteRoot(""); cms.getRequestContext().setCurrentProject(readProject(dbc, projectId)); CmsCategoryService.getInstance().repairRelations(cms, resource); }
/** * Removes a resource after it has been deleted by the driver manager.<p> * * @param dbc the current database context * @param resourceName the root path of the deleted resource * @throws CmsException if something goes wrong */ public void removeDeletedResource(CmsDbContext dbc, String resourceName) throws CmsException { try { m_driverManager.getVfsDriver(dbc).readResource(dbc, dbc.currentProject().getUuid(), resourceName, false); throw new CmsLockException( Messages.get().container( Messages.ERR_REMOVING_UNDELETED_RESOURCE_1, dbc.getRequestContext().removeSiteRoot(resourceName))); } catch (CmsVfsResourceNotFoundException e) { // ok, ignore } unlockResource(resourceName, true); unlockResource(resourceName, false); }
/** * Removes a resource after it has been deleted by the driver manager.<p> * * @param dbc the current database context * @param resourceName the root path of the deleted resource * @throws CmsException if something goes wrong */ public void removeDeletedResource(CmsDbContext dbc, String resourceName) throws CmsException { try { m_driverManager.getVfsDriver().readResource(dbc, dbc.currentProject().getUuid(), resourceName, false); throw new CmsLockException(Messages.get().container( Messages.ERR_REMOVING_UNDELETED_RESOURCE_1, dbc.getRequestContext().removeSiteRoot(resourceName))); } catch (CmsVfsResourceNotFoundException e) { // ok, ignore } unlockResource(resourceName, true); unlockResource(resourceName, false); }
dbc.getRequestContext().setCurrentProject(m_driverManager.readProject(dbc, CmsProject.ONLINE_PROJECT_ID)); try { CmsDriverManager.NOTHING_CHANGED); } finally { dbc.getRequestContext().setCurrentProject(project);
/** * Adds a new relation to the given resource.<p> * * @param dbc the database context * @param resource the resource to add the relation to * @param target the target of the relation * @param type the type of the relation * @param importCase if importing relations * * @throws CmsException if something goes wrong */ public void addRelationToResource( CmsDbContext dbc, CmsResource resource, CmsResource target, CmsRelationType type, boolean importCase) throws CmsException { if (type.isDefinedInContent()) { throw new CmsIllegalArgumentException(Messages.get().container( Messages.ERR_ADD_RELATION_IN_CONTENT_3, dbc.removeSiteRoot(resource.getRootPath()), dbc.removeSiteRoot(target.getRootPath()), type.getLocalizedName(dbc.getRequestContext().getLocale()))); } CmsRelation relation = new CmsRelation(resource, target, type); m_vfsDriver.createRelation(dbc, dbc.currentProject().getUuid(), relation); if (!importCase) { setDateLastModified(dbc, resource, System.currentTimeMillis()); } }
/** * Creates the project for the temporary workplace files.<p> * * @param dbc the current database context * * @return the created project for the temporary workplace files * * @throws CmsException if something goes wrong */ public CmsProject createTempfileProject(CmsDbContext dbc) throws CmsException { // read the needed groups from the cms CmsGroup projectUserGroup = readGroup(dbc, dbc.currentProject().getGroupId()); CmsGroup projectManagerGroup = readGroup(dbc, dbc.currentProject().getManagerGroupId()); CmsProject tempProject = m_projectDriver.createProject( dbc, new CmsUUID(), dbc.currentUser(), projectUserGroup, projectManagerGroup, I_CmsProjectDriver.TEMP_FILE_PROJECT_NAME, Messages.get().getBundle(dbc.getRequestContext().getLocale()).key( Messages.GUI_WORKPLACE_TEMPFILE_PROJECT_DESC_0), CmsProject.PROJECT_FLAG_HIDDEN, CmsProject.PROJECT_TYPE_NORMAL); m_projectDriver.createProjectResource(dbc, tempProject.getUuid(), "/"); OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap( "project", tempProject))); return tempProject; }