📄 cmsresourcebroker.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/genericSql/CmsResourceBroker.java,v $
* Date : $Date: 2002/05/10 23:43:56 $
* Version: $Revision: 1.320.2.1 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.file.genericSql;
import javax.servlet.http.*;
import java.util.*;
import java.net.*;
import java.io.*;
import source.org.apache.java.io.*;
import source.org.apache.java.util.*;
// Flex: Removed CmsClassLoader import com.opencms.boot.CmsClassLoader;
import com.opencms.boot.CmsBase;
import com.opencms.core.*;
import com.opencms.file.*;
import com.opencms.template.*;
import java.sql.SQLException;
import java.util.zip.*;
import org.w3c.dom.*;
/**
* This is THE resource broker. It merges all resource broker
* into one public class. The interface is local to package. <B>All</B> methods
* get additional parameters (callingUser and currentproject) to check the security-
* police.
*
* @author Andreas Schouten
* @author Michaela Schleich
* @author Michael Emmerich
* @author Anders Fugmann
* @version $Revision: 1.320.2.1 $ $Date: 2002/05/10 23:43:56 $
*
*/
public class CmsResourceBroker implements I_CmsResourceBroker, I_CmsConstants {
//create a compare class to be used in the vector.
class Resource {
private String path = null;
public Resource(String path) {
this.path = path;
}
public boolean equals(Object obj) {
return ( (obj instanceof CmsResource) && path.equals( ((CmsResource) obj).getResourceName() ));
}
}
/**
* Constant to count the file-system changes.
*/
protected long m_fileSystemChanges = 0;
/**
* Constant to count the file-system changes if Folders are involved.
*/
protected long m_fileSystemFolderChanges = 0;
/**
* Hashtable with resource-types.
*/
protected Hashtable m_resourceTypes = null;
/**
* The configuration of the property-file.
*/
protected Configurations m_configuration = null;
/**
* The access-module.
*/
protected CmsDbAccess m_dbAccess = null;
/**
* The Registry
*/
protected I_CmsRegistry m_registry = null;
/**
* The portnumber the workplace access is limited to.
*/
protected int m_limitedWorkplacePort = -1;
/**
* Define the caches
*/
protected CmsCache m_userCache = null;
protected CmsCache m_groupCache = null;
protected CmsCache m_usergroupsCache = null;
protected CmsCache m_projectCache = null;
protected CmsProject m_onlineProjectCache = null;
protected CmsCache m_propertyCache = null;
protected CmsCache m_propertyDefCache = null;
protected CmsCache m_propertyDefVectorCache = null;
protected CmsCache m_accessCache = null;
protected int m_cachelimit = 0;
protected String m_refresh = null;
// cache for single resources
protected CmsResourceCache m_resourceCache = null;
// cache for resource lists
protected CmsResourceCache m_subresCache = null; // resources in folder
/**
* backup published resources for history
*/
protected boolean m_enableHistory = true;
/**
* Accept a task from the Cms.
*
* <B>Security:</B>
* All users are granted.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param taskid The Id of the task to accept.
*
* @exception CmsException Throws CmsException if something goes wrong.
*/
public void acceptTask(CmsUser currentUser, CmsProject currentProject, int taskId) throws CmsException
{
CmsTask task = m_dbAccess.readTask(taskId);
task.setPercentage(1);
task = m_dbAccess.writeTask(task);
m_dbAccess.writeSystemTaskLog(taskId, "Task was accepted from " + currentUser.getFirstname() + " " + currentUser.getLastname() + ".");
}
/**
* Checks, if the user may create this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
*
* @return wether the user has access, or not.
*/
public boolean accessCreate(CmsUser currentUser, CmsProject currentProject,
CmsResource resource) throws CmsException {
// check, if this is the onlineproject
if(onlineProject(currentUser, currentProject).equals(currentProject)){
// the online-project is not writeable!
return(false);
}
// check the access to the project
if( ! accessProject(currentUser, currentProject, currentProject.getId()) ) {
// no access to the project!
return(false);
}
// check if the resource belongs to the current project
if(resource.getProjectId() != currentProject.getId()) {
return false;
}
// is the resource locked?
if( resource.isLocked() && (resource.isLockedBy() != currentUser.getId() ||
(resource.getLockedInProject() != currentProject.getId() &&
currentProject.getFlags() != C_PROJECT_STATE_INVISIBLE)) ) {
// resource locked by anopther user, no creation allowed
return(false);
}
// check the rights for the current resource
if( ! ( accessOther(currentUser, currentProject, resource, C_ACCESS_PUBLIC_WRITE) ||
accessOwner(currentUser, currentProject, resource, C_ACCESS_OWNER_WRITE) ||
accessGroup(currentUser, currentProject, resource, C_ACCESS_GROUP_WRITE) ) ) {
// no write access to this resource!
return false;
}
// read the parent folder
if(resource.getParent() != null) {
// readFolder without checking access
resource = m_dbAccess.readFolder(resource.getProjectId(), resource.getRootName()+resource.getParent());
} else {
// no parent folder!
return true;
}
// check the rights and if the resource is not locked
do {
if( accessOther(currentUser, currentProject, resource, C_ACCESS_PUBLIC_READ) ||
accessOwner(currentUser, currentProject, resource, C_ACCESS_OWNER_READ) ||
accessGroup(currentUser, currentProject, resource, C_ACCESS_GROUP_READ) ) {
// is the resource locked?
if( resource.isLocked() && resource.isLockedBy() != currentUser.getId() ) {
// resource locked by anopther user, no creation allowed
return(false);
}
// read next resource
if(resource.getParent() != null) {
// readFolder without checking access
resource = m_dbAccess.readFolder(resource.getProjectId(), resource.getRootName()+resource.getParent());
}
} else {
// last check was negative
return(false);
}
} while(resource.getParent() != null);
// all checks are done positive
return(true);
}
/**
* Checks, if the user may create this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
*
* @return wether the user has access, or not.
*/
public boolean accessCreate(CmsUser currentUser, CmsProject currentProject,
String resourceName) throws CmsException {
CmsResource resource = m_dbAccess.readFileHeader(currentProject.getId(), resourceName);
return accessCreate(currentUser, currentProject, resource);
}
/**
* Checks, if the group may access this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
* @param flags The flags to check.
*
* @return wether the user has access, or not.
*/
protected boolean accessGroup(CmsUser currentUser, CmsProject currentProject,
CmsResource resource, int flags)
throws CmsException {
// is the user in the group for the resource?
if(userInGroup(currentUser, currentProject, currentUser.getName(),
readGroup(currentUser, currentProject,
resource).getName())) {
if( (resource.getAccessFlags() & flags) == flags ) {
return true;
}
}
// the resource isn't accesible by the user.
return false;
}
/**
* Checks, if the user may lock this resource.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param resource The resource to check.
*
* @return wether the user may lock this resource, or not.
*/
public boolean accessLock(CmsUser currentUser, CmsProject currentProject,
CmsResource resource) throws CmsException {
// check, if this is the onlineproject
if(onlineProject(currentUser, currentProject).equals(currentProject)){
// the online-project is not writeable!
return(false);
}
// check the access to the project
if( ! accessProject(currentUser, currentProject, currentProject.getId()) ) {
// no access to the project!
return(false);
}
// check if the resource belongs to the current project
if(resource.getProjectId() != currentProject.getId()) {
return false;
}
// read the parent folder
if(resource.getParent() != null) {
// readFolder without checking access
resource = m_dbAccess.readFolder(resource.getProjectId(), resource.getRootName()+resource.getParent());
} else {
// no parent folder!
return true;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -