📄 cmsdrivermanager.java
字号:
public static final int READMODE_UNMATCHSTATE = 2;
/** Key to indicate complete update. */
public static final int UPDATE_ALL = 3;
/** Key to indicate update of resource record. */
public static final int UPDATE_RESOURCE = 4;
/** Key to indicate update of resource state. */
public static final int UPDATE_RESOURCE_STATE = 1;
/** Key to indicate update of structure record. */
public static final int UPDATE_STRUCTURE = 5;
/** Key to indicate update of structure state. */
public static final int UPDATE_STRUCTURE_STATE = 2;
/** The log object for this class. */
private static final Log LOG = CmsLog.getLog(CmsSecurityManager.class);
/** Separator for user cache. */
private static final char USER_CACHE_SEP = '\u0000';
/** Cache for access control lists. */
private Map m_accessControlListCache;
/** The backup driver. */
private I_CmsBackupDriver m_backupDriver;
/** Temporary concurrent lock list for the "create resource" method. */
private List m_concurrentCreateResourceLocks;
/** The configuration of the property-file. */
private Map m_configuration;
/** The list of initialized JDBC pools. */
private List m_connectionPools;
/** Cache for groups. */
private Map m_groupCache;
/** The HTML link validator. */
private CmsXmlDocumentLinkValidator m_htmlLinkValidator;
/** The class used for cache key generation. */
private I_CmsCacheKey m_keyGenerator;
/** The lock manager. */
private CmsLockManager m_lockManager = OpenCms.getLockManager();
/** Cache for offline projects. */
private Map m_projectCache;
/** The project driver. */
private I_CmsProjectDriver m_projectDriver;
/** Cache for properties. */
private Map m_propertyCache;
/** Cache for resources. */
private Map m_resourceCache;
/** Cache for resource lists. */
private Map m_resourceListCache;
/** The security manager (for access checks). */
private CmsSecurityManager m_securityManager;
/** The sql manager. */
private CmsSqlManager m_sqlManager;
/** Cache for user data. */
private Map m_userCache;
/** The user driver. */
private I_CmsUserDriver m_userDriver;
/** Cache for user groups. */
private Map m_userGroupsCache;
/** The VFS driver. */
private I_CmsVfsDriver m_vfsDriver;
/** The workflow driver. */
private I_CmsWorkflowDriver m_workflowDriver;
/**
* Private constructor, initializes some required member variables.<p>
*/
private CmsDriverManager() {
m_connectionPools = new ArrayList();
}
/**
* Reads the required configurations from the opencms.properties file and creates
* the various drivers to access the cms resources.<p>
*
* The initialization process of the driver manager and its drivers is split into
* the following phases:
* <ul>
* <li>the database pool configuration is read</li>
* <li>a plain and empty driver manager instance is created</li>
* <li>an instance of each driver is created</li>
* <li>the driver manager is passed to each driver during initialization</li>
* <li>finally, the driver instances are passed to the driver manager during initialization</li>
* </ul>
*
* @param configurationManager the configuration manager
* @param securityManager the security manager
* @param runtimeInfoFactory the initialized OpenCms runtime info factory
*
* @return CmsDriverManager the instanciated driver manager
* @throws CmsInitException if the driver manager couldn't be instanciated
*/
public static CmsDriverManager newInstance(
CmsConfigurationManager configurationManager,
CmsSecurityManager securityManager,
I_CmsDbContextFactory runtimeInfoFactory) throws CmsInitException {
Map configuration = configurationManager.getConfiguration();
ExtendedProperties config;
if (configuration instanceof ExtendedProperties) {
config = (ExtendedProperties)configuration;
} else {
config = new ExtendedProperties();
config.putAll(configuration);
}
// initialize static hashtables
CmsDbUtil.init();
List drivers = null;
String driverName = null;
I_CmsVfsDriver vfsDriver = null;
I_CmsUserDriver userDriver = null;
I_CmsProjectDriver projectDriver = null;
I_CmsWorkflowDriver workflowDriver = null;
I_CmsBackupDriver backupDriver = null;
CmsDriverManager driverManager = null;
try {
// create a driver manager instance
driverManager = new CmsDriverManager();
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE1_0));
}
if ((runtimeInfoFactory == null) && CmsLog.INIT.isDebugEnabled()) {
CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_RT_0));
}
} catch (Exception exc) {
CmsMessageContainer message = Messages.get().container(Messages.LOG_ERR_DRIVER_MANAGER_START_0);
if (LOG.isFatalEnabled()) {
LOG.fatal(message.key(), exc);
}
throw new CmsInitException(message, exc);
}
// set the security manager
driverManager.m_securityManager = securityManager;
// create and set the sql manager
driverManager.m_sqlManager = new CmsSqlManager(driverManager);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE2_0));
}
// read the pool names to initialize
String[] driverPoolNames = config.getStringArray(CmsDriverManager.CONFIGURATION_DB + ".pools");
if (CmsLog.INIT.isInfoEnabled()) {
String names = "";
for (int p = 0; p < driverPoolNames.length; p++) {
names += driverPoolNames[p] + " ";
}
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_POOLS_1, names));
}
// initialize each pool
for (int p = 0; p < driverPoolNames.length; p++) {
driverManager.newPoolInstance(config, driverPoolNames[p]);
}
// initialize the runtime info factory with the generated driver manager
if (runtimeInfoFactory != null) {
runtimeInfoFactory.initialize(driverManager);
}
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE3_0));
}
// read the vfs driver class properties and initialize a new instance
drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_VFS));
driverName = config.getString((String)drivers.get(0) + ".vfs.driver");
drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null;
vfsDriver = (I_CmsVfsDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers);
// read the user driver class properties and initialize a new instance
drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_USER));
driverName = config.getString((String)drivers.get(0) + ".user.driver");
drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null;
userDriver = (I_CmsUserDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers);
// read the project driver class properties and initialize a new instance
drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_PROJECT));
driverName = config.getString((String)drivers.get(0) + ".project.driver");
drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null;
projectDriver = (I_CmsProjectDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers);
// read the workflow driver class properties and initialize a new instance
drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_WORKFLOW));
driverName = config.getString((String)drivers.get(0) + ".workflow.driver");
drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null;
workflowDriver = (I_CmsWorkflowDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers);
// read the backup driver class properties and initialize a new instance
drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_BACKUP));
driverName = config.getString((String)drivers.get(0) + ".backup.driver");
drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null;
backupDriver = (I_CmsBackupDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers);
try {
// invoke the init method of the driver manager
driverManager.init(
configurationManager,
config,
vfsDriver,
userDriver,
projectDriver,
workflowDriver,
backupDriver);
if (CmsLog.INIT.isInfoEnabled()) {
CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE4_OK_0));
}
} catch (Exception exc) {
CmsMessageContainer message = Messages.get().container(Messages.LOG_ERR_DRIVER_MANAGER_START_0);
if (LOG.isFatalEnabled()) {
LOG.fatal(message.key(), exc);
}
throw new CmsInitException(message, exc);
}
// register the driver manager for required events
org.opencms.main.OpenCms.addCmsEventListener(driverManager, new int[] {
I_CmsEventListener.EVENT_UPDATE_EXPORTS,
I_CmsEventListener.EVENT_CLEAR_CACHES,
I_CmsEventListener.EVENT_CLEAR_PRINCIPAL_CACHES,
I_CmsEventListener.EVENT_PUBLISH_PROJECT});
// return the configured driver manager
return driverManager;
}
/**
* Updates the state of the given task as accepted by the current user.<p>
*
* @param dbc the current database context
* @param taskId the Id of the task to accept
*
* @throws CmsException if something goes wrong
*/
public void acceptTask(CmsDbContext dbc, int taskId) throws CmsException {
CmsTask task = m_workflowDriver.readTask(dbc, taskId);
task.setPercentage(1);
task = m_workflowDriver.writeTask(dbc, task);
// currently don't localize workflow logs (this log goes to the database)
m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Task was accepted from "
+ dbc.currentUser().getFirstname()
+ " "
+ dbc.currentUser().getLastname()
+ '.');
}
/**
* Adds a user to a group.<p>
*
* @param dbc the current database context
* @param username the name of the user that is to be added to the group
* @param groupname the name of the group
*
* @throws CmsException if operation was not succesfull
* @throws CmsDbEntryNotFoundException if the given user or the given group was not found
*/
public void addUserToGroup(CmsDbContext dbc, String username, String groupname)
throws CmsException, CmsDbEntryNotFoundException {
if (!userInGroup(dbc, username, groupname)) {
CmsUser user;
CmsGroup group;
try {
user = readUser(dbc, username);
} catch (CmsDbEntryNotFoundException e) {
user = readWebUser(dbc, username);
}
//check if the user exists
if (user != null) {
// web user can not be members of:
// Administrators, Projectmanagers or Users
if (user.getType() == CmsUser.USER_TYPE_WEBUSER) {
List forbidden = new ArrayList();
forbidden.add(OpenCms.getDefaultUsers().getGroupAdministrators());
forbidden.add(OpenCms.getDefaultUsers().getGroupProjectmanagers());
forbidden.add(OpenCms.getDefaultUsers().getGroupUsers());
if (forbidden.contains(groupname)) {
throw new CmsSecurityException(
Messages.get().container(Messages.ERR_WEBUSER_GROUP_1, forbidden));
}
}
group = readGroup(dbc, groupname);
//check if group exists
if (group != null) {
//add this user to the group
m_userDriver.createUserInGroup(dbc, user.getId(), group.getId(), null);
// update the cache
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -