📄 cmsresourcebroker.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/genericSql/Attic/CmsResourceBroker.java,v $
* Date : $Date: 2003/06/27 14:59:46 $
* Version: $Revision: 1.375.2.2 $
*
* 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 com.opencms.boot.CmsBase;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsConstants;
import com.opencms.file.*;
import com.opencms.flex.util.CmsLruHashMap;
import com.opencms.report.I_CmsReport;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.util.Utils;
import com.opencms.workplace.CmsAdminVfsLinkManagement;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Properties;
import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.w3c.dom.Document;
import source.org.apache.java.util.Configurations;
/**
* 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.375.2.2 $ $Date: 2003/06/27 14:59:46 $
*
*/
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 caches for often read resources
protected Map m_userCache = null;
protected Map m_groupCache = null;
protected Map m_userGroupsCache = null;
protected Map m_projectCache = null;
protected Map m_propertyCache = null;
protected Map m_propertyDefCache = null;
protected Map m_propertyDefVectorCache = null;
protected Map m_accessCache = null;
protected Map m_resourceCache = null;
protected Map m_resourceListCache = null;
// Constants used for cache property lookup
protected static final String C_CACHE_NULL_PROPERTY_VALUE = "__CACHE_NULL_PROPERTY_VALUE__";
protected static final String C_CACHE_ALL_PROPERTIES = "__CACHE_ALL_PROPERTIES__";
protected CmsProject m_onlineProjectCache = null;
protected int m_cachelimit = 0;
protected String m_refresh = null;
/**
* 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.
*
* @throws 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(currentProject.isOnlineProject()){
// 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(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(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, false);
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(currentProject.isOnlineProject()){
// 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!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -