📄 cmssecuritymanager.java
字号:
* @param description the description for the new user
* @param additionalInfos the additional infos for the user
*
* @return the created user
*
* @see CmsObject#createUser(String, String, String, Map)
*
* @throws CmsException if something goes wrong
* @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
*/
public CmsUser createUser(
CmsRequestContext context,
String name,
String password,
String description,
Map additionalInfos) throws CmsException, CmsRoleViolationException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
CmsUser result = null;
try {
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
result = m_driverManager.createUser(dbc, name, password, description, additionalInfos);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_CREATE_USER_1, name), e);
} finally {
dbc.clear();
}
return result;
}
/**
* Deletes all entries in the published resource table.<p>
*
* @param context the current request context
* @param linkType the type of resource deleted (0= non-paramter, 1=parameter)
*
* @throws CmsException if something goes wrong
*/
public void deleteAllStaticExportPublishedResources(CmsRequestContext context, int linkType) throws CmsException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
m_driverManager.deleteAllStaticExportPublishedResources(dbc, linkType);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_STATEXP_PUBLISHED_RESOURCES_0), e);
} finally {
dbc.clear();
}
}
/**
* Deletes the versions from the backup tables that are older then the given timestamp
* and/or number of remaining versions.<p>
*
* The number of verions always wins, i.e. if the given timestamp would delete more versions
* than given in the versions parameter, the timestamp will be ignored. <p>
*
* Deletion will delete file header, content and properties. <p>
*
* @param context the current request context
* @param timestamp timestamp which defines the date after which backup resources must be deleted
* @param versions the number of versions per file which should kept in the system
* @param report the report for output logging
*
* @throws CmsException if operation was not succesful
* @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#HISTORY_MANAGER}
*/
public void deleteBackups(CmsRequestContext context, long timestamp, int versions, I_CmsReport report)
throws CmsException, CmsRoleViolationException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
checkRole(dbc, CmsRole.HISTORY_MANAGER);
m_driverManager.deleteBackups(dbc, timestamp, versions, report);
} catch (Exception e) {
dbc.report(null, Messages.get().container(
Messages.ERR_DELETE_BACKUPS_2,
new Date(timestamp),
new Integer(versions)), e);
} finally {
dbc.clear();
}
}
/**
* Deletes a group, where all permissions, users and childs of the group
* are transfered to a replacement group.<p>
*
* @param context the current request context
* @param groupId the id of the group to be deleted
* @param replacementId the id of the group to be transfered, can be <code>null</code>
*
* @throws CmsException if operation was not succesful
* @throws CmsSecurityException if the group is a default group.
* @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
*/
public void deleteGroup(CmsRequestContext context, CmsUUID groupId, CmsUUID replacementId)
throws CmsException, CmsRoleViolationException, CmsSecurityException {
CmsGroup group = readGroup(context, groupId);
if (OpenCms.getDefaultUsers().isDefaultGroup(group.getName())) {
throw new CmsSecurityException(Messages.get().container(
Messages.ERR_CONSTRAINT_DELETE_GROUP_DEFAULT_1,
group.getName()));
}
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
// catch own exception as special cause for general "Error deleting group".
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
// this is needed because
// I_CmsUserDriver#removeAccessControlEntriesForPrincipal(CmsDbContext, CmsProject, CmsProject, CmsUUID)
// expects an offline project, if not data will become inconsistent
checkOfflineProject(dbc);
m_driverManager.deleteGroup(dbc, group, replacementId);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_GROUP_1, group.getName()), e);
} finally {
dbc.clear();
}
}
/**
* Delete a user group.<p>
*
* Only groups that contain no subgroups can be deleted.<p>
*
* @param context the current request context
* @param name the name of the group that is to be deleted
*
* @throws CmsException if operation was not succesful
* @throws CmsSecurityException if the group is a default group.
* @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER}
*
*/
public void deleteGroup(CmsRequestContext context, String name)
throws CmsException, CmsRoleViolationException, CmsSecurityException {
if (OpenCms.getDefaultUsers().isDefaultGroup(name)) {
throw new CmsSecurityException(Messages.get().container(
Messages.ERR_CONSTRAINT_DELETE_GROUP_DEFAULT_1,
name));
}
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
// catch own exception as special cause for general "Error deleting group".
checkRole(dbc, CmsRole.ACCOUNT_MANAGER);
// this is needed because
// I_CmsUserDriver#removeAccessControlEntriesForPrincipal(CmsDbContext, CmsProject, CmsProject, CmsUUID)
// expects an offline project, if not data will become inconsistent
checkOfflineProject(dbc);
m_driverManager.deleteGroup(dbc, name);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_GROUP_1, name), e);
} finally {
dbc.clear();
}
}
/**
* Deletes a project.<p>
*
* All modified resources currently inside this project will be reset to their online state.<p>
*
* @param context the current request context
* @param projectId the ID of the project to be deleted
*
* @throws CmsException if something goes wrong
* @throws CmsRoleViolationException if the current user does not own management access to the project
*/
public void deleteProject(CmsRequestContext context, int projectId) throws CmsException, CmsRoleViolationException {
if (projectId == CmsProject.ONLINE_PROJECT_ID) {
// online project must not be deleted
throw new CmsVfsException(org.opencms.file.Messages.get().container(
org.opencms.file.Messages.ERR_NOT_ALLOWED_IN_ONLINE_PROJECT_0));
}
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
CmsProject deleteProject = null;
try {
// read the project that should be deleted
deleteProject = m_driverManager.readProject(dbc, projectId);
checkManagerOfProjectRole(dbc, deleteProject);
m_driverManager.deleteProject(dbc, deleteProject);
} catch (Exception e) {
String projectName = deleteProject == null ? String.valueOf(projectId) : deleteProject.getName();
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_PROJECT_1, projectName), e);
} finally {
dbc.clear();
}
}
/**
* Deletes a property definition.<p>
*
* @param context the current request context
* @param name the name of the property definition to delete
*
* @throws CmsException if something goes wrong
* @throws CmsSecurityException if the project to delete is the "Online" project
* @throws CmsRoleViolationException if the current user does not own the role {@link CmsRole#PROPERTY_MANAGER}
*/
public void deletePropertyDefinition(CmsRequestContext context, String name)
throws CmsException, CmsSecurityException, CmsRoleViolationException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
checkOfflineProject(dbc);
checkRole(dbc, CmsRole.PROPERTY_MANAGER);
m_driverManager.deletePropertyDefinition(dbc, name);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_PROPERTY_1, name), e);
} finally {
dbc.clear();
}
}
/**
* Deletes a resource given its name.<p>
*
* The <code>siblingMode</code> parameter controls how to handle siblings
* during the delete operation.<br>
* Possible values for this parameter are: <br>
* <ul>
* <li><code>{@link org.opencms.file.CmsResource#DELETE_REMOVE_SIBLINGS}</code></li>
* <li><code>{@link org.opencms.file.CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li>
* </ul><p>
*
* @param context the current request context
* @param resource the name of the resource to delete (full path)
* @param siblingMode indicates how to handle siblings of the deleted resource
* @throws CmsException if something goes wrong
* @throws CmsSecurityException if the user does not have {@link CmsPermissionSet#ACCESS_WRITE} on the given resource.
* @see org.opencms.file.types.I_CmsResourceType#deleteResource(CmsObject, CmsSecurityManager, CmsResource, int)
*/
public void deleteResource(CmsRequestContext context, CmsResource resource, int siblingMode)
throws CmsException, CmsSecurityException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
checkOfflineProject(dbc);
checkPermissions(dbc, resource, CmsPermissionSet.ACCESS_WRITE, true, CmsResourceFilter.ALL);
m_driverManager.deleteResource(dbc, resource, siblingMode);
} catch (Exception e) {
dbc.report(null, Messages.get().container(Messages.ERR_DELETE_RESOURCE_1, context.getSitePath(resource)), e);
} finally {
dbc.clear();
}
}
/**
* Deletes an entry in the published resource table.<p>
*
* @param context the current request context
* @param resourceName The name of the resource to be deleted in the static export
* @param linkType the type of resource deleted (0= non-paramter, 1=parameter)
* @param linkParameter the parameters ofthe resource
*
* @throws CmsException if something goes wrong
*/
public void deleteStaticExportPublishedResource(
CmsRequestContext context,
String resourceName,
int linkType,
String linkParameter) throws CmsException {
CmsDbContext dbc = m_dbContextFactory.getDbContext(context);
try {
m_driverManager.deleteStaticExportPublishedResource(dbc, resourceName, linkType, linkParameter);
} catch (Exception e) {
dbc.report(
null,
Messages.get().container(Messages.ERR_DELETE_STATEXP_PUBLISHES_RESOURCE_1, resourceName),
e);
} finally {
dbc.clear();
}
}
/**
* Deletes a user.<p>
*
* @param context the current request context
* @param userId the Id of the user to be deleted
*
* @throws CmsException if something goes wrong
*/
public void deleteUser(CmsRequestContext context, CmsUUID userId) throws CmsException {
CmsUser user = readUser(context, userId);
deleteUser(context, user, null);
}
/**
* Deletes a user, where all permissions and resources attributes of the user
* were transfered to a replacement user.<p>
*
* @param context the current request context
* @param userId the id of the user to be deleted
* @param replacementId the id of the user to be transfered
*
* @throws CmsException if operation was not successful
*/
public void deleteUser(CmsRequestContext context, CmsUUID userId, CmsUUID replacementId) throws CmsException {
CmsUser user = readUser(context, userId);
CmsUser replacementUser = null;
if (replacementId != null && !replacementId.isNullUUID()) {
replacement
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -