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

📄 cmsresourcebroker.java

📁 java 编写的程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
 * All users are granted.
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param username The name of the user.
 * @return Vector of groups
 * @exception CmsException Throws CmsException if operation was not succesful
 */
public Vector getGroupsOfUser(CmsUser currentUser, CmsProject currentProject, String username) throws CmsException {
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;

    Vector allGroups = (Vector) m_usergroupsCache.get(C_USER + username);
    if ((allGroups == null) || (allGroups.size() == 0)) {
        Vector groups = dbAccess.getAllGroupsOfUser(username);
        m_usergroupsCache.put(C_USER + username, groups);
        return groups;
    }
    return allGroups;
}
/**
 * Returns a list of users in a group.<P/>
 *
 * <B>Security:</B>
 * All users are granted, except the anonymous user.
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param groupname The name of the group to list users from.
 * @return Vector of users.
 * @exception CmsException Throws CmsException if operation was not succesful.
 */
public Vector getUsersOfGroup(CmsUser currentUser, CmsProject currentProject, String groupname) throws CmsException {
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;

    // check the security
    if (!anonymousUser(currentUser, currentProject).equals(currentUser)) {
        return dbAccess.getUsersOfGroup(currentUser, groupname, C_USER_TYPE_SYSTEMUSER);
    } else {
        throw new CmsException("[" + this.getClass().getName() + "] " + groupname, CmsException.C_NO_ACCESS);
    }
}
    /**
     * Initializes the resource broker and sets up all required modules and connections.
     * @param config The OpenCms configuration.
     * @exception CmsException Throws CmsException if something goes wrong.
     */
    public void init(Configurations config) throws CmsException {
        super.init(config);
    }
/**
 * Determines, if the users may manage a project.<BR/>
 * Only the manager of a project may publish it.
 *
 * <B>Security:</B>
 * All users are granted.
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @return true, if the may manage this project.
 * @exception CmsException Throws CmsException if operation was not succesful.
 */
public boolean isManagerOfProject(CmsUser currentUser, CmsProject currentProject) throws CmsException {
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
    return (dbAccess.isManagerOfProject(currentUser, currentProject));
}
/**
 * Locks a resource.<br>
 *
 * Only a resource in an offline project can be locked. The state of the resource
 * is set to CHANGED (1).
 * If the content of this resource is not exisiting in the offline project already,
 * it is read from the online project and written into the offline project.
 * A user can lock a resource, so he is the only one who can write this
 * resource. <br>
 *
 * <B>Security:</B>
 * Access is granted, if:
 * <ul>
 * <li>the user has access to the project</li>
 * <li>the user can write the resource</li>
 * <li>the resource is not locked by another user</li>
 * </ul>
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param resource The complete path to the resource to lock.
 * @param force If force is true, a existing locking will be oberwritten.
 *
 * @exception CmsException  Throws CmsException if operation was not succesful.
 * It will also be thrown, if there is a existing lock
 * and force was set to false.
 */
public void lockResource(CmsUser currentUser, CmsProject currentProject, String resourcename, boolean force) throws CmsException {
    CmsResource cmsResource = null;
    CmsFolder cmsFolder = null;
    CmsFile cmsFile = null;
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
    Vector resources = dbAccess.lockResource(currentUser, currentProject, resourcename, force);

    for (int i = 0; i < resources.size(); i++) {
        cmsResource = (CmsResource) resources.elementAt(i);
        String resourceName = cmsResource.getResourceName();
        if (resourceName.endsWith("/")) {
            cmsFolder = new CmsFolder(cmsResource.getResourceId(), cmsResource.getParentId(),
                                    cmsResource.getFileId(), resourceName, cmsResource.getType(),
                                    cmsResource.getFlags(), cmsResource.getOwnerId(), cmsResource.getGroupId(),
                                    cmsResource.getProjectId(), cmsResource.getAccessFlags(),
                                    cmsResource.getState(), cmsResource.isLockedBy(), cmsResource.getDateCreated(),
                                    cmsResource.getDateLastModified(), cmsResource.getResourceLastModifiedBy(),
                                    cmsResource.getProjectId());

        } else {
            cmsFile = new CmsFile(cmsResource.getResourceId(), cmsResource.getParentId(),
                                    cmsResource.getFileId(), resourceName, cmsResource.getType(),
                                    cmsResource.getFlags(), cmsResource.getOwnerId(), cmsResource.getGroupId(),
                                    cmsResource.getProjectId(), cmsResource.getAccessFlags(),
                                    cmsResource.getState(), cmsResource.isLockedBy(), cmsResource.getLauncherType(),
                                    cmsResource.getLauncherClassname(), cmsResource.getDateCreated(),
                                    cmsResource.getDateLastModified(), cmsResource.getResourceLastModifiedBy(),
                                    new byte[0], cmsResource.getLength(),cmsResource.getProjectId());

        }
        m_resourceCache.remove(resourceName);
    }
    m_subresCache.clear();
}

/**
 * Unocks a resource.<br>
 *
 * Only a resource in an offline project can be unlocked. The state of the resource
 * is set to CHANGED (1).
 * If the content of this resource is not exisiting in the offline project already,
 * it is read from the online project and written into the offline project.
 * A user can unlock a resource, so he is the only one who can write this
 * resource. <br>
 *
 * <B>Security:</B>
 * Access is granted, if:
 * <ul>
 * <li>the user has access to the project</li>
 * <li>the user can write the resource</li>
 * <li>the resource is locked by current user</li>
 * </ul>
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param resource The complete path to the resource to unlock.
 *
 * @exception CmsException  Throws CmsException if operation was not succesful.
 */
public void unlockResource(CmsUser currentUser, CmsProject currentProject, String resourcename) throws CmsException {

    CmsResource cmsResource = null;
    CmsFolder cmsFolder = null;
    CmsFile cmsFile = null;
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
    Vector resources = dbAccess.unlockResource(currentUser, currentProject, resourcename);

    for (int i=0; i < resources.size(); i++) {
        cmsResource = (CmsResource)resources.elementAt(i);
        String resourceName = cmsResource.getResourceName();
        if (resourceName.endsWith("/")) {
            cmsFolder = new CmsFolder(cmsResource.getResourceId(), cmsResource.getParentId(),
                                    cmsResource.getFileId(), resourceName, cmsResource.getType(),
                                    cmsResource.getFlags(), cmsResource.getOwnerId(), cmsResource.getGroupId(),
                                    cmsResource.getProjectId(), cmsResource.getAccessFlags(),
                                    cmsResource.getState(), cmsResource.isLockedBy(), cmsResource.getDateCreated(),
                                    cmsResource.getDateLastModified(), cmsResource.getResourceLastModifiedBy(),
                                    cmsResource.getProjectId());
        } else {
            cmsFile = new CmsFile(cmsResource.getResourceId(), cmsResource.getParentId(),
                                    cmsResource.getFileId(), resourceName, cmsResource.getType(),
                                    cmsResource.getFlags(), cmsResource.getOwnerId(), cmsResource.getGroupId(),
                                    cmsResource.getProjectId(), cmsResource.getAccessFlags(),
                                    cmsResource.getState(), cmsResource.isLockedBy(), cmsResource.getLauncherType(),
                                    cmsResource.getLauncherClassname(), cmsResource.getDateCreated(),
                                    cmsResource.getDateLastModified(), cmsResource.getResourceLastModifiedBy(),
                                    new byte[0], cmsResource.getLength(),cmsResource.getProjectId());
        }
        m_resourceCache.remove(resourceName);
    }
    m_subresCache.clear();
}
/**
 * Checks if a user is member of a group.<P/>
 *
 * <B>Security:</B>
 * All users are granted, except the anonymous user.
 *
 * @param currentUser The user who requested this method.
 * @param currentProject The current project of the user.
 * @param callingUser The user who wants to use this method.
 * @param nameuser The name of the user to check.
 * @param groupname The name of the group to check.
 * @return True or False
 *
 * @exception CmsException Throws CmsException if operation was not succesful
 */
public boolean userInGroup(CmsUser currentUser, CmsProject currentProject, String username, String groupname) throws CmsException {
    com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
    try {
        CmsUser user = null;
        try {
            user = readUser(currentUser, currentProject, username);
        } catch (CmsException exc){
            user = readWebUser(currentUser, currentProject, username);
        }
        CmsGroup group = readGroup(currentUser, currentProject, groupname);
        return (dbAccess.userInGroup(user.getId(), group.getId()));
    } catch (CmsException ex) {
        return false;
    }
}
}

⌨️ 快捷键说明

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