?? cmsresourcebroker.java
字號:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/file/oracleplsql/CmsResourceBroker.java,v $
* Date : $Date: 2001/12/20 13:14:34 $
* Version: $Revision: 1.34 $
*
* 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.oracleplsql;
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.*;
import com.opencms.core.*;
import com.opencms.file.*;
import com.opencms.template.*;
/**
* 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.34 $ $Date: 2001/12/20 13:14:34 $
*/
public class CmsResourceBroker extends com.opencms.file.genericSql.CmsResourceBroker {
/**
* 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 {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
return (dbAccess.accessCreate(currentUser, currentProject, resource));
}
/**
* 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 has access, or not.
*/
public boolean accessLock(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
return (dbAccess.accessLock(currentUser, currentProject, resource));
}
// Methods working with projects
/**
* Tests if the user can access the project.
*
* <B>Security:</B>
* All users are granted.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param projectId the id of the project.
* @return true, if the user has access, else returns false.
* @exception CmsException Throws CmsException if something goes wrong.
*/
public boolean accessProject(CmsUser currentUser, CmsProject currentProject, int projectId) throws CmsException {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
return (dbAccess.accessProject(currentUser, projectId));
}
/**
* Checks, if the user may read 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 accessRead(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
Boolean access=(Boolean)m_accessCache.get(currentUser.getId()+":"+currentProject.getId()+":"+resource.getResourceName());
if (access != null) {
return access.booleanValue();
} else {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
boolean ac=dbAccess.accessRead(currentUser, currentProject, resource);
m_accessCache.put(currentUser.getId()+":"+currentProject.getId()+":"+resource.getResourceName(),new Boolean(ac));
return ac;
}
}
/**
* Checks, if the user may write 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 accessWrite(CmsUser currentUser, CmsProject currentProject, CmsResource resource) throws CmsException {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
return (dbAccess.accessWrite(currentUser, currentProject, resource));
}
/**
* Copies a file in the Cms. <br>
*
* <B>Security:</B>
* Access is cranted, if:
* <ul>
* <li>the user has access to the project</li>
* <li>the user can read the sourceresource</li>
* <li>the user can create the destinationresource</li>
* <li>the destinationresource dosn't exists</li>
* </ul>
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
* @param source The complete path of the sourcefile.
* @param destination The complete path to the destination.
*
* @exception CmsException Throws CmsException if operation was not succesful.
*/
public void copyFile(CmsUser currentUser, CmsProject currentProject, String source, String destination) throws CmsException {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
// checks, if the destinateion is valid, if not it throws a exception
validFilename(destination.replace('/', 'a'));
CmsResource sourceFile = readFileHeader(currentUser, currentProject, source);
try {
if(accessOther(currentUser, currentProject, sourceFile, C_ACCESS_PUBLIC_WRITE) ||
accessOwner(currentUser, currentProject, sourceFile, C_ACCESS_OWNER_WRITE) ||
accessGroup(currentUser, currentProject, sourceFile, C_ACCESS_GROUP_WRITE)){
dbAccess.copyFile(currentProject, currentUser.getId(), source, destination);
// inform about the file-system-change
fileSystemChanged(false);
m_subresCache.clear();
} else {
throw new CmsException("[" + this.getClass().getName() + "] " + source,
CmsException.C_NO_ACCESS);
}
} catch (CmsException e) {
throw e;
}
}
/**
* return the correct DbAccess class.
* This method should be overloaded by all other Database Drivers
* Creation date: (09/15/00 %r)
* @return com.opencms.file.genericSql.CmsDbAccess
* @param configurations source.org.apache.java.util.Configurations
* @exception com.opencms.core.CmsException Thrown if CmsDbAccess class could not be instantiated.
*/
public com.opencms.file.genericSql.CmsDbAccess createDbAccess(Configurations configurations) throws CmsException
{
return new com.opencms.file.oracleplsql.CmsDbAccess(configurations);
}
/**
* Returns all projects, which are owned by the user or which are accessible
* for the group of the user.
*
* <B>Security</B>
* All users are granted.
*
* @param currentUser The user who requested this method.
* @param currentProject The current project of the user.
*
* @return a Vector of projects.
*/
public Vector getAllAccessibleProjects(CmsUser currentUser,
CmsProject currentProject)
throws CmsException {
com.opencms.file.oracleplsql.CmsDbAccess dbAccess = (com.opencms.file.oracleplsql.CmsDbAccess) m_dbAccess;
// get all projects which are owned by the user.
Vector projects = dbAccess.getAllAccessibleProjects(currentUser);
// return the vector of projects
return(projects);
}
/**
* Returns a list of groups of a user.<P/>
*
* <B>Security:</B>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -