1 31 32 package org.opencms.security; 33 34 import org.opencms.db.CmsDefaultUsers; 35 import org.opencms.file.CmsGroup; 36 import org.opencms.file.CmsRequestContext; 37 import org.opencms.main.OpenCms; 38 39 import java.util.ArrayList ; 40 import java.util.Arrays ; 41 import java.util.Collections ; 42 import java.util.List ; 43 44 73 public final class CmsRole { 74 75 76 public static final CmsRole ADMINISTRATOR = new CmsRole("ADMINISTRATOR", new CmsRole[0]); 77 78 79 public static final CmsRole DEVELOPER = new CmsRole("DEVELOPER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 80 81 82 public static final CmsRole EXPORT_DATABASE = new CmsRole("EXPORT_DATABASE", new CmsRole[] {CmsRole.ADMINISTRATOR}); 83 84 85 public static final CmsRole HISTORY_MANAGER = new CmsRole("HISTORY_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 86 87 88 public static final CmsRole IMPORT_DATABASE = new CmsRole("IMPORT_DATABASE", new CmsRole[] {CmsRole.ADMINISTRATOR}); 89 90 91 public static final CmsRole MODULE_MANAGER = new CmsRole("MODULE_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 92 93 94 public static final CmsRole PROJECT_MANAGER = new CmsRole("PROJECT_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 95 96 97 public static final CmsRole PROPERTY_MANAGER = new CmsRole( 98 "PROPERTY_MANAGER", 99 new CmsRole[] {CmsRole.ADMINISTRATOR}); 100 101 106 public static final CmsRole RESOURCE_TYPE_MANAGER = new CmsRole("RESOURCE_TYPE_MANAGER", new CmsRole[] { 107 CmsRole.ADMINISTRATOR, 108 CmsRole.MODULE_MANAGER}); 109 110 111 public static final CmsRole ROOT_FOLDER_ACCESS = new CmsRole( 112 "ROOT_FOLDER_ACCESS", 113 new CmsRole[] {CmsRole.ADMINISTRATOR}); 114 115 116 public static final CmsRole SCHEDULER_MANAGER = new CmsRole( 117 "SCHEDULER_MANAGER", 118 new CmsRole[] {CmsRole.ADMINISTRATOR}); 119 120 121 public static final CmsRole SEARCH_MANAGER = new CmsRole("SEARCH_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 122 123 124 public static final CmsRole ACCOUNT_MANAGER = new CmsRole("ACCOUNT_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 125 126 127 public static final CmsRole VFS_MANAGER = new CmsRole("VFS_MANAGER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 128 129 134 public static final CmsRole WORKPLACE_MANAGER = new CmsRole("WORKPLACE_MANAGER", new CmsRole[] { 135 CmsRole.ADMINISTRATOR, 136 CmsRole.MODULE_MANAGER, 137 CmsRole.DEVELOPER}); 138 139 140 public static final CmsRole WORKPLACE_USER = new CmsRole("WORKPLACE_USER", new CmsRole[] {CmsRole.ADMINISTRATOR}); 141 142 148 public static final CmsRole SYSTEM_USER = new CmsRole("SYSTEM_USER", new CmsRole[] { 149 CmsRole.ADMINISTRATOR, CmsRole.WORKPLACE_USER, CmsRole.PROJECT_MANAGER, CmsRole.DEVELOPER}); 151 152 153 private static List m_systemRoles; 154 155 156 private Object [] m_distictGroupNames; 157 158 159 private String m_groupName; 160 161 162 private List m_parentRoles; 163 164 165 private String m_roleName; 166 167 168 private boolean m_systemRole; 169 170 177 public CmsRole(String roleName, String groupName, CmsRole[] parentRoles) { 178 179 m_roleName = roleName; 180 m_groupName = groupName; 181 m_parentRoles = Collections.unmodifiableList(Arrays.asList(parentRoles)); 182 m_systemRole = false; 183 initialize(); 184 } 185 186 192 private CmsRole(String roleName, CmsRole[] parentRoles) { 193 194 m_roleName = roleName; 195 m_parentRoles = Collections.unmodifiableList(Arrays.asList(parentRoles)); 196 m_systemRole = true; 197 } 198 199 204 public static List getSystemRoles() { 205 206 return m_systemRoles; 207 } 208 209 219 public static void initialize(CmsDefaultUsers defaultUsers) throws CmsSecurityException { 220 221 if (OpenCms.getRunLevel() > OpenCms.RUNLEVEL_2_INITIALIZING) { 222 throw new CmsSecurityException(Messages.get().container(Messages.ERR_STARTUP_FINISHED_0)); 224 } 225 226 ADMINISTRATOR.m_groupName = defaultUsers.getGroupAdministrators(); 228 PROJECT_MANAGER.m_groupName = defaultUsers.getGroupProjectmanagers(); 229 WORKPLACE_USER.m_groupName = defaultUsers.getGroupUsers(); 230 231 MODULE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 233 ACCOUNT_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 234 EXPORT_DATABASE.m_groupName = defaultUsers.getGroupAdministrators(); 235 IMPORT_DATABASE.m_groupName = defaultUsers.getGroupAdministrators(); 236 DEVELOPER.m_groupName = defaultUsers.getGroupAdministrators(); 237 SCHEDULER_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 238 SEARCH_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 239 VFS_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 240 RESOURCE_TYPE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 241 HISTORY_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 242 PROPERTY_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 243 ROOT_FOLDER_ACCESS.m_groupName = defaultUsers.getGroupAdministrators(); 244 WORKPLACE_MANAGER.m_groupName = defaultUsers.getGroupAdministrators(); 245 SYSTEM_USER.m_groupName = defaultUsers.getGroupUsers(); 246 247 m_systemRoles = Collections.unmodifiableList(Arrays.asList(new CmsRole[] { 249 ADMINISTRATOR, 250 PROJECT_MANAGER, 251 WORKPLACE_USER, 252 MODULE_MANAGER, 253 ACCOUNT_MANAGER, 254 EXPORT_DATABASE, 255 IMPORT_DATABASE, 256 DEVELOPER, 257 SCHEDULER_MANAGER, 258 SEARCH_MANAGER, 259 VFS_MANAGER, 260 RESOURCE_TYPE_MANAGER, 261 HISTORY_MANAGER, 262 PROPERTY_MANAGER, 263 ROOT_FOLDER_ACCESS, 264 WORKPLACE_MANAGER, 265 SYSTEM_USER})); 266 267 for (int i = 0; i < m_systemRoles.size(); i++) { 269 ((CmsRole)m_systemRoles.get(i)).initialize(); 270 } 271 } 272 273 285 public boolean checkDirectAccess(List groups) { 286 287 for (int i = 0; i < groups.size(); i++) { 288 if (m_groupName.equals(((CmsGroup)groups.get(i)).getName())) { 289 return true; 290 } 291 } 292 return false; 293 } 294 295 304 public CmsRoleViolationException createRoleViolationException(CmsRequestContext context) { 305 306 String roleName; 307 if (m_systemRole) { 308 roleName = Messages.get().getBundle(context.getLocale()).key("GUI_ROLENAME_" + m_roleName + "_0"); 310 } else { 311 roleName = getRoleName(); 312 } 313 return new CmsRoleViolationException(Messages.get().container( 314 Messages.ERR_NOT_IN_ROLE_2, 315 context.currentUser().getName(), 316 roleName)); 317 } 318 319 322 public boolean equals(Object obj) { 323 324 if (obj == this) { 325 return true; 326 } 327 if (obj instanceof CmsRole) { 328 return m_roleName.equals(((CmsRole)obj).m_roleName); 329 } 330 return false; 331 } 332 333 338 public String getGroupName() { 339 340 return m_groupName; 341 } 342 343 348 public List getParentRoles() { 349 350 return m_parentRoles; 351 } 352 353 358 public String getRoleName() { 359 360 return m_roleName; 361 } 362 363 366 public int hashCode() { 367 368 return m_roleName.hashCode(); 369 } 370 371 382 public boolean hasRole(List groups) { 383 384 String [] groupNames = new String [groups.size()]; 385 for (int i = 0; i < groups.size(); i++) { 386 groupNames[i] = ((CmsGroup)groups.get(i)).getName(); 387 } 388 return hasRole(groupNames); 389 } 390 391 402 public boolean hasRole(String [] groupNames) { 403 404 for (int i = 0; i < m_distictGroupNames.length; i++) { 405 for (int j = 0; j < groupNames.length; j++) { 406 if (m_distictGroupNames[i].equals(groupNames[j])) { 407 return true; 408 } 409 } 410 } 411 return false; 412 } 413 414 417 public String toString() { 418 419 StringBuffer result = new StringBuffer (); 420 421 result.append("["); 422 result.append(this.getClass().getName()); 423 result.append(", role: "); 424 result.append(getRoleName()); 425 result.append(", group: "); 426 result.append(getGroupName()); 427 result.append("]"); 428 429 return result.toString(); 430 } 431 432 436 private void initialize() { 437 438 ArrayList distinctGroups = new ArrayList (); 440 distinctGroups.add(getGroupName()); 441 for (int i = 0; i < m_parentRoles.size(); i++) { 442 String name = ((CmsRole)m_parentRoles.get(i)).getGroupName(); 443 if (!distinctGroups.contains(name)) { 444 distinctGroups.add(name); 445 } 446 } 447 m_distictGroupNames = distinctGroups.toArray(); 448 } 449 } | Popular Tags |