📄 cmsrole.java
字号:
// set the configured group names for the system roles
ADMINISTRATOR.m_groupName = defaultUsers.getGroupAdministrators();
PROJECT_MANAGER.m_groupName = defaultUsers.getGroupProjectmanagers();
WORKPLACE_USER.m_groupName = defaultUsers.getGroupUsers();
// TODO: Don't base all roles only on the "Administrator" group
MODULE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
ACCOUNT_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
EXPORT_DATABASE.m_groupName = defaultUsers.getGroupAdministrators();
IMPORT_DATABASE.m_groupName = defaultUsers.getGroupAdministrators();
DEVELOPER.m_groupName = defaultUsers.getGroupAdministrators();
SCHEDULER_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
SEARCH_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
VFS_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
RESOURCE_TYPE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
HISTORY_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
PROPERTY_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
ROOT_FOLDER_ACCESS.m_groupName = defaultUsers.getGroupAdministrators();
WORKPLACE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators();
SYSTEM_USER.m_groupName = defaultUsers.getGroupUsers();
// create a lookup list for the system roles
m_systemRoles = Collections.unmodifiableList(Arrays.asList(new CmsRole[] {
ADMINISTRATOR,
PROJECT_MANAGER,
WORKPLACE_USER,
MODULE_MANAGER,
ACCOUNT_MANAGER,
EXPORT_DATABASE,
IMPORT_DATABASE,
DEVELOPER,
SCHEDULER_MANAGER,
SEARCH_MANAGER,
VFS_MANAGER,
RESOURCE_TYPE_MANAGER,
HISTORY_MANAGER,
PROPERTY_MANAGER,
ROOT_FOLDER_ACCESS,
WORKPLACE_MANAGER,
SYSTEM_USER}));
// now initilaize all system roles
for (int i = 0; i < m_systemRoles.size(); i++) {
((CmsRole)m_systemRoles.get(i)).initialize();
}
}
/**
* Returns <code>true</code> if the role group of this role (not the groups from the parent roles)
* matches a name of one of the given groups.<p>
*
* This check is required only to find out if a user is a direct member of the role group of
* this role. It should never be used for permission checks. For all permission checks, use
* <code>{@link #hasRole(List)}</code>.<p>
*
* @param groups a List of <code>{@link CmsGroup}</code> instances to match this role group against
* @return <code>true</code> if the role group of this role (not the groups from the parent roles)
* matches a name of one of the given groups
*/
public boolean checkDirectAccess(List groups) {
for (int i = 0; i < groups.size(); i++) {
if (m_groupName.equals(((CmsGroup)groups.get(i)).getName())) {
return true;
}
}
return false;
}
/**
* Returns a role violation exception configured with a localized, role specific message
* for this role.<p>
*
* @param context the current users OpenCms request context
*
* @return a role violation exception configured with a localized, role specific message
* for this role
*/
public CmsRoleViolationException createRoleViolationException(CmsRequestContext context) {
String roleName;
if (m_systemRole) {
// localize role names for system roles
roleName = Messages.get().getBundle(context.getLocale()).key("GUI_ROLENAME_" + m_roleName + "_0");
} else {
roleName = getRoleName();
}
return new CmsRoleViolationException(Messages.get().container(
Messages.ERR_NOT_IN_ROLE_2,
context.currentUser().getName(),
roleName));
}
/**
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof CmsRole) {
return m_roleName.equals(((CmsRole)obj).m_roleName);
}
return false;
}
/**
* Returns the name of the group this role is mapped to in the OpenCms database.<p>
*
* @return the name of the group this role is mapped to in the OpenCms database
*/
public String getGroupName() {
return m_groupName;
}
/**
* Returns the (unmodifialble) List of parent roles of this role (instances of <code>{@link CmsRole}</code>.<p>
*
* @return the (unmodifialble) List of parent roles of this role
*/
public List getParentRoles() {
return m_parentRoles;
}
/**
* Returns the name of the role.<p>
*
* @return the name of the role
*/
public String getRoleName() {
return m_roleName;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
return m_roleName.hashCode();
}
/**
* Returns <code>true</code> if at last one of the given <code>{@link CmsGroup}</code> instances is
* equal to a group of this role.<p>
*
* This checks the given list against the role group of this role as well as against the role group
* of all parent roles.<p>
*
* @param groups a List of <code>{@link CmsGroup}</code> instances to match the role groups against
* @return <code>true</code> if at last one of the given group names is equal to a group name
* of this role
*/
public boolean hasRole(List groups) {
String[] groupNames = new String[groups.size()];
for (int i = 0; i < groups.size(); i++) {
groupNames[i] = ((CmsGroup)groups.get(i)).getName();
}
return hasRole(groupNames);
}
/**
* Returns <code>true</code> if at last one of the given group names is equal to a group name
* of this role.<p>
*
* This checks the given list against the role group of this role as well as against the role group
* of all parent roles.<p>
*
* @param groupNames the group names to match the role groups against
* @return <code>true</code> if at last one of the given group names is equal to a group name
* of this role
*/
public boolean hasRole(String[] groupNames) {
for (int i = 0; i < m_distictGroupNames.length; i++) {
for (int j = 0; j < groupNames.length; j++) {
if (m_distictGroupNames[i].equals(groupNames[j])) {
return true;
}
}
}
return false;
}
/**
* @see java.lang.Object#toString()
*/
public String toString() {
StringBuffer result = new StringBuffer();
result.append("[");
result.append(this.getClass().getName());
result.append(", role: ");
result.append(getRoleName());
result.append(", group: ");
result.append(getGroupName());
result.append("]");
return result.toString();
}
/**
* Initializes this role, creating an optimized data structure for
* the lookup of the role group names.<p>
*/
private void initialize() {
// calculate the distinct groups of this role
ArrayList distinctGroups = new ArrayList();
distinctGroups.add(getGroupName());
for (int i = 0; i < m_parentRoles.size(); i++) {
String name = ((CmsRole)m_parentRoles.get(i)).getGroupName();
if (!distinctGroups.contains(name)) {
distinctGroups.add(name);
}
}
m_distictGroupNames = distinctGroups.toArray();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -