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

📄 cmsdrivermanager.java

📁 一个cms内容管理平台
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                    throw new CmsDbEntryNotFoundException(Messages.get().container(
                        Messages.ERR_UNKNOWN_GROUP_1,
                        groupname));
                }
            } else {
                throw new CmsDbEntryNotFoundException(Messages.get().container(
                    Messages.ERR_UNKNOWN_USER_1,
                    user.getName()));
            }
        }
    }

    /**
     * Creates a new web user.<p>
     * 
     * A web user has no access to the workplace but is able to access personalized
     * functions controlled by the OpenCms.<br>
     * 
     * Moreover, a web user can be created by any user, the intention being that
     * a "Guest" user can create a personalized account for himself.<p>
     * 
     * @param dbc the current database context
     * @param name the new name for the user
     * @param password the new password for the user
     * @param group the default groupname for the user
     * @param description the description for the user
     * @param additionalInfos a <code>{@link Map}</code> with additional infos for the user
     *        Infos may be stored into the Usertables (depending on the implementation).
     *
     * @return the new user will be returned
     * 
     * @throws CmsException if operation was not succesfull
     * @throws CmsSecurityException if the password is not valid
     * @throws CmsIllegalArgumentException if the provided name has an illegal format (length == 0)
     * @throws CmsDbEntryNotFoundException if the user for the given name or the given group was not found 
     */
    public CmsUser addWebUser(
        CmsDbContext dbc,
        String name,
        String password,
        String group,
        String description,
        Map additionalInfos)
    throws CmsException, CmsSecurityException, CmsIllegalArgumentException, CmsDbEntryNotFoundException {

        return addWebUser(dbc, name, password, group, null, description, additionalInfos);
    }

    /**
     * Adds a web user to the Cms.<p>
     * 
     * A web user has no access to the workplace but is able to access personalized
     * functions controlled by the OpenCms.<p>
     * 
     * @param dbc the current database context
     * @param name the new name for the user
     * @param password the new password for the user
     * @param group the default groupname for the user
     * @param additionalGroup an additional group for the user
     * @param description the description for the user
     * @param additionalInfos a Hashtable with additional infos for the user, these
     *        Infos may be stored into the Usertables (depending on the implementation)
     *
     * @return the new user will be returned
     * 
     * @throws CmsException if operation was not succesfull
     * @throws CmsSecurityException if the password is not valid
     * @throws CmsIllegalArgumentException if the provided name has an illegal format (length == 0)
     * @throws CmsDbEntryNotFoundException if the user for the given name or the given group was not found 
     */
    public CmsUser addWebUser(
        CmsDbContext dbc,
        String name,
        String password,
        String group,
        String additionalGroup,
        String description,
        Map additionalInfos)
    throws CmsException, CmsDbEntryNotFoundException, CmsIllegalArgumentException, CmsSecurityException {

        CmsUser newUser = createUser(dbc, name, password, description, additionalInfos, CmsUser.USER_TYPE_WEBUSER);
        CmsUser user = m_userDriver.readUser(dbc, newUser.getName(), CmsUser.USER_TYPE_WEBUSER);
        //check if the user exists
        if (user != null) {
            CmsGroup usergroup = readGroup(dbc, group);
            //check if group exists
            if (usergroup != null && isWebgroup(dbc, usergroup)) {
                //add this user to the group
                m_userDriver.createUserInGroup(dbc, user.getId(), usergroup.getId(), null);
                // update the cache
                m_userGroupsCache.clear();
            } else {
                throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, group));
            }
            // if an additional groupname is given and the group does not belong to
            // Users, Administrators or Projectmanager add the user to this group
            if (CmsStringUtil.isNotEmpty(additionalGroup)) {
                CmsGroup addGroup = readGroup(dbc, additionalGroup);
                if (addGroup != null && isWebgroup(dbc, addGroup)) {
                    //add this user to the group
                    m_userDriver.createUserInGroup(dbc, user.getId(), addGroup.getId(), null);
                    // update the cache
                    m_userGroupsCache.clear();
                } else {
                    throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, group));
                }
            }
        } else {
            throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_USER_1, user.getName()));
        }
        return newUser;
    }

    /**
     * Creates a backup of the current project.<p>
     * 
     * @param dbc the current database context
     * @param tagId the version of the backup
     * @param publishDate the date of publishing
     *
     * @throws CmsDataAccessException if operation was not succesful
     */
    public void backupProject(CmsDbContext dbc, int tagId, long publishDate) throws CmsDataAccessException {

        m_backupDriver.writeBackupProject(dbc, tagId, publishDate);
    }

    /**
     * Changes the project id of the resource to the current project, indicating that 
     * the resource was last modified in this project.<p>
     * 
     * @param dbc the current database context
     * @param resource theresource to apply this operation to
     * 
     * @throws CmsException if something goes wrong
     * 
     * @see CmsObject#changeLastModifiedProjectId(String)
     * @see I_CmsResourceType#changeLastModifiedProjectId(CmsObject, CmsSecurityManager, CmsResource)
     */
    public void changeLastModifiedProjectId(CmsDbContext dbc, CmsResource resource) throws CmsException {

        // update the project id of a modified resource as "modified inside the current project"
        m_vfsDriver.writeLastModifiedProjectId(dbc, dbc.currentProject(), dbc.currentProject().getId(), resource);

        clearResourceCache();

        OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap(
            "resource",
            resource)));
    }

    /**
     * Changes the lock of a resource to the current user,
     * that is "steals" the lock from another user.<p>
     * 
     * @param dbc the current database context
     * @param resource the resource to change the lock for
     * 
     * @throws CmsException if something goes wrong
     * @throws CmsSecurityException if something goes wrong
     * 
     * 
     * @see CmsObject#changeLock(String)
     * @see I_CmsResourceType#changeLock(CmsObject, CmsSecurityManager, CmsResource)
     * 
     * @see CmsSecurityManager#hasPermissions(CmsRequestContext, CmsResource, CmsPermissionSet, boolean, CmsResourceFilter)
     */
    public void changeLock(CmsDbContext dbc, CmsResource resource) throws CmsException, CmsSecurityException {

        // get the current lock
        CmsLock currentLock = getLock(dbc, resource);
        // check if the resource is locked at all
        if (currentLock.isNullLock()) {
            throw new CmsLockException(Messages.get().container(
                Messages.ERR_CHANGE_LOCK_UNLOCKED_RESOURCE_1,
                dbc.getRequestContext().getSitePath(resource)));
        } else if (currentLock.getUserId().equals(dbc.currentUser().getId())
            && (currentLock.getProjectId() == dbc.currentProject().getId())
            && (currentLock.getType() == CmsLock.TYPE_EXCLUSIVE)) {
            // the current lock requires no change
            return;
        }

        // duplicate logic from CmsSecurityManager#hasPermissions() because lock state can't be ignored
        // if another user has locked the file, the current user can never get WRITE permissions with the default check
        int denied = 0;
        // check if the current user is admin
        boolean canIgnorePermissions = m_securityManager.hasRole(dbc, CmsRole.VFS_MANAGER);
        // if the resource type is jsp
        // write is only allowed for administrators
        if (!canIgnorePermissions && (resource.getTypeId() == CmsResourceTypeJsp.getStaticTypeId())) {
            if (!m_securityManager.hasRole(dbc, CmsRole.DEVELOPER)) {
                denied |= CmsPermissionSet.PERMISSION_WRITE;
            }
        }
        CmsPermissionSetCustom permissions;
        if (canIgnorePermissions) {
            // if the current user is administrator, anything is allowed
            permissions = new CmsPermissionSetCustom(~0);
        } else {
            // otherwise, get the permissions from the access control list
            permissions = getPermissions(dbc, resource, dbc.currentUser());
        }
        // revoke the denied permissions
        permissions.denyPermissions(denied);
        // now check if write permission is granted
        if ((CmsPermissionSet.ACCESS_WRITE.getPermissions() & permissions.getPermissions()) != CmsPermissionSet.ACCESS_WRITE.getPermissions()) {
            // check failed, throw exception
            m_securityManager.checkPermissions(
                dbc.getRequestContext(),
                resource,
                CmsPermissionSet.ACCESS_WRITE,
                CmsSecurityManager.PERM_DENIED);
        }
        // if we got here write permission is granted on the target

        // remove the old lock
        m_lockManager.removeResource(this, dbc, resource, true);
        // apply the new lock
        lockResource(dbc, resource, CmsLock.COMMON);
    }

    /**
     * Changes the user type of the user.<p>
     * 
     * @param dbc the current database context
     * @param user the user to change
     * @param userType the new usertype of the user
     * 
     * @throws CmsDataAccessException if something goes wrong
     */
    public void changeUserType(CmsDbContext dbc, CmsUser user, int userType) throws CmsDataAccessException {

        // try to remove user from cache
        clearUserCache(user);
        m_userDriver.writeUserType(dbc, user.getId(), userType);
    }

    /**
     * Changes the user type of the user.<p>
     * 
     * @param dbc the current database context
     * @param userId the id of the user to change
     * @param userType the new usertype of the user
     * 
     * @throws CmsDataAccessException if something goes wrong
     * @throws CmsDataAccessException if an underlying <code>Exception</code> related to runtime type instantiation (<code>IOException</code>, <code>ClassCastException</code>) occurs. 
     * @throws CmsDbSqlException  if an underlying <code>Exception</code> related to data retrieval (<code>SQLException</code>) occurs.  
     * @throws CmsDbEntryNotFoundException if the user corresponding to the given id does not exist in the database
     * 
     */
    public void changeUserType(CmsDbContext dbc, CmsUUID userId, int userType)
    throws CmsDataAccessException, CmsDbEntryNotFoundException, CmsDbSqlException {

        CmsUser theUser = m_userDriver.readUser(dbc, userId);
        changeUserType(dbc, theUser, userType);
    }

    /**
     * Changes the user type of the user.<p>

     * Only the administrator can change the type.<p>
     * 
     * @param dbc the current database context
     * @param username the name of the user to change
     * @param userType the new usertype of the user
     * 
     * @throws CmsException if something goes wrong
     */
    public void changeUserType(CmsDbContext dbc, String username, int userType) throws CmsException {

        CmsUser theUser = null;
        try {
            // try to read the webuser
            theUser = readWebUser(dbc, username);
        } catch (CmsDbEntryNotFoundException confe) {
            // try to read the systemuser
            theUser = readUser(dbc, username);
        }
        changeUserType(dbc, theUser, userType);
    }

    /**
     * Changes the resource flags of a resource.<p>
     * 
     * The resource flags are used to indicate various "special" conditions
     * for a resource. Most notably, the "internal only" setting which signals 
     * that a resource can not be directly requested with it's URL.<p>
     * 
     * @param dbc the current database context
     * @param resource the resource to change the flags for
     * @param flags the new resource flags for this resource
     *
     * @throws CmsException if something goes wrong
     * 
     * @see CmsObject#chflags(String, int)
     * @see I_CmsResourceType#chflags(CmsObject, CmsSecurityManager, CmsResource, int)
     */
    public void chflags(CmsDbContext dbc, CmsResource resource, int flags) throws CmsException {

        // must operate on a clone to ensure resource is not modified in case permissions are not granted
        CmsResource clone = (CmsResource)resource.clone();
        clone.setFlags(flags);
        writeResource(dbc, clone);
    }

    /**
     * Changes the resource type of a resource.<p>
     * 
     * OpenCms handles resources according to the resource type,
     * not the file suffix. This is e.g. why a JSP in OpenCms can have the 
     * suffix ".html" instead of ".jsp" only. Changing the resource type
     * makes sense e.g. if you want to make a plain text file a JSP resource,
     * or a binary file an image, etc.<p> 
     * 
     * @param dbc the current database context
     * @param resource the resource to change the type for
     * @param type the new resource type for this resource
     *
     * @throws CmsException if something goes wrong

⌨️ 快捷键说明

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