1 31 32 package org.opencms.db; 33 34 import org.opencms.configuration.CmsConfigurationManager; 35 import org.opencms.configuration.CmsSystemConfiguration; 36 import org.opencms.file.CmsBackupProject; 37 import org.opencms.file.CmsBackupResource; 38 import org.opencms.file.CmsDataAccessException; 39 import org.opencms.file.CmsFile; 40 import org.opencms.file.CmsFolder; 41 import org.opencms.file.CmsGroup; 42 import org.opencms.file.CmsObject; 43 import org.opencms.file.CmsProject; 44 import org.opencms.file.CmsProperty; 45 import org.opencms.file.CmsPropertyDefinition; 46 import org.opencms.file.CmsRequestContext; 47 import org.opencms.file.CmsResource; 48 import org.opencms.file.CmsResourceFilter; 49 import org.opencms.file.CmsUser; 50 import org.opencms.file.CmsVfsException; 51 import org.opencms.file.CmsVfsResourceAlreadyExistsException; 52 import org.opencms.file.CmsVfsResourceNotFoundException; 53 import org.opencms.file.types.CmsResourceTypeFolder; 54 import org.opencms.file.types.CmsResourceTypeJsp; 55 import org.opencms.file.types.I_CmsResourceType; 56 import org.opencms.flex.CmsFlexRequestContextInfo; 57 import org.opencms.i18n.CmsLocaleManager; 58 import org.opencms.i18n.CmsMessageContainer; 59 import org.opencms.lock.CmsLock; 60 import org.opencms.lock.CmsLockException; 61 import org.opencms.lock.CmsLockManager; 62 import org.opencms.main.CmsEvent; 63 import org.opencms.main.CmsException; 64 import org.opencms.main.CmsIllegalArgumentException; 65 import org.opencms.main.CmsIllegalStateException; 66 import org.opencms.main.CmsInitException; 67 import org.opencms.main.CmsLog; 68 import org.opencms.main.I_CmsEventListener; 69 import org.opencms.main.OpenCms; 70 import org.opencms.module.CmsModule; 71 import org.opencms.report.CmsLogReport; 72 import org.opencms.report.I_CmsReport; 73 import org.opencms.security.CmsAccessControlEntry; 74 import org.opencms.security.CmsAccessControlList; 75 import org.opencms.security.CmsAuthentificationException; 76 import org.opencms.security.CmsPasswordEncryptionException; 77 import org.opencms.security.CmsPermissionSet; 78 import org.opencms.security.CmsPermissionSetCustom; 79 import org.opencms.security.CmsRole; 80 import org.opencms.security.CmsSecurityException; 81 import org.opencms.security.I_CmsPrincipal; 82 import org.opencms.util.CmsFileUtil; 83 import org.opencms.util.CmsStringUtil; 84 import org.opencms.util.CmsUUID; 85 import org.opencms.validation.CmsXmlDocumentLinkValidator; 86 import org.opencms.workflow.CmsTask; 87 import org.opencms.workflow.CmsTaskLog; 88 import org.opencms.workflow.CmsTaskService; 89 90 import java.util.ArrayList ; 91 import java.util.Arrays ; 92 import java.util.Collections ; 93 import java.util.HashMap ; 94 import java.util.HashSet ; 95 import java.util.Iterator ; 96 import java.util.List ; 97 import java.util.ListIterator ; 98 import java.util.Map ; 99 import java.util.Set ; 100 import java.util.Stack ; 101 import java.util.Vector ; 102 103 import org.apache.commons.collections.ExtendedProperties; 104 import org.apache.commons.collections.map.LRUMap; 105 import org.apache.commons.dbcp.PoolingDriver; 106 import org.apache.commons.logging.Log; 107 import org.apache.commons.pool.ObjectPool; 108 109 120 public final class CmsDriverManager implements I_CmsEventListener { 121 122 128 private class CacheId extends Object { 129 130 133 public String m_name; 134 135 138 public CmsUUID m_uuid; 139 140 145 public CacheId(CmsGroup group) { 146 147 m_name = group.getName(); 148 m_uuid = group.getId(); 149 } 150 151 156 public CacheId(CmsResource resource) { 157 158 m_name = resource.getName(); 159 m_uuid = resource.getResourceId(); 160 } 161 162 167 public CacheId(CmsUser user) { 168 169 m_name = user.getName() + user.getType(); 170 m_uuid = user.getId(); 171 } 172 173 178 public CacheId(CmsUUID uuid) { 179 180 m_uuid = uuid; 181 } 182 183 188 public CacheId(String str) { 189 190 m_name = str; 191 } 192 193 199 public CacheId(String name, CmsUUID uuid) { 200 201 m_name = name; 202 m_uuid = uuid; 203 } 204 205 208 public boolean equals(Object obj) { 209 210 if (obj == this) { 211 return true; 212 } 213 if (!(obj instanceof CacheId)) { 214 return false; 215 } 216 CacheId other = (CacheId)obj; 217 boolean result; 218 if (m_uuid != null) { 219 result = m_uuid.equals(other.m_uuid); 220 if (result) { 221 return true; 222 } 223 } 224 if (m_name != null) { 225 result = m_name.equals(other.m_name); 226 if (result) { 227 return true; 228 } 229 } 230 return false; 231 } 232 233 236 public int hashCode() { 237 238 if (m_uuid == null) { 239 return 509; 240 } else { 241 return m_uuid.hashCode(); 242 } 243 } 244 245 } 246 247 248 public static final String CACHE_ALL_PROPERTIES = "_CAP_"; 249 250 251 public static final String CONFIGURATION_BACKUP = "driver.backup"; 252 253 254 public static final String CONFIGURATION_CACHE = "cache"; 255 256 257 public static final String CONFIGURATION_DB = "db"; 258 259 260 public static final String CONFIGURATION_PROJECT = "driver.project"; 261 262 263 public static final String CONFIGURATION_USER = "driver.user"; 264 265 266 public static final String CONFIGURATION_VFS = "driver.vfs"; 267 268 269 public static final String CONFIGURATION_WORKFLOW = "driver.workflow"; 270 271 272 public static final String LOST_AND_FOUND_FOLDER = "/system/lost-found"; 273 274 275 public static final int MAX_VFS_RESOURCE_PATH_LENGTH = 512; 276 277 278 public static final int NOTHING_CHANGED = 0; 279 280 281 public static final String READ_IGNORE_PARENT = null; 282 283 284 public static final int READ_IGNORE_STATE = -1; 285 286 287 public static final long READ_IGNORE_TIME = 0L; 288 289 290 public static final int READ_IGNORE_TYPE = -1; 291 292 293 public static final int READMODE_EXCLUDE_STATE = 8; 294 295 296 public static final int READMODE_EXCLUDE_TREE = 1; 297 298 299 public static final int READMODE_EXCLUDE_TYPE = 4; 300 301 302 public static final int READMODE_IGNORESTATE = 0; 303 304 305 public static final int READMODE_INCLUDE_PROJECT = 2; 306 307 308 public static final int READMODE_INCLUDE_TREE = 0; 309 310 311 public static final int READMODE_MATCHSTATE = 1; 312 313 314 public static final int READMODE_ONLY_FILES = 128; 315 316 317 public static final int READMODE_ONLY_FOLDERS = 64; 318 319 320 public static final int READMODE_UNMATCHSTATE = 2; 321 322 323 public static final int UPDATE_ALL = 3; 324 325 326 public static final int UPDATE_RESOURCE = 4; 327 328 329 public static final int UPDATE_RESOURCE_STATE = 1; 330 331 332 public static final int UPDATE_STRUCTURE = 5; 333 334 335 public static final int UPDATE_STRUCTURE_STATE = 2; 336 337 338 private static final Log LOG = CmsLog.getLog(CmsSecurityManager.class); 339 340 341 private static final char USER_CACHE_SEP = '\u0000'; 342 343 344 private Map m_accessControlListCache; 345 346 347 private I_CmsBackupDriver m_backupDriver; 348 349 350 private List m_concurrentCreateResourceLocks; 351 352 353 private Map m_configuration; 354 355 356 private List m_connectionPools; 357 358 359 private Map m_groupCache; 360 361 362 private CmsXmlDocumentLinkValidator m_htmlLinkValidator; 363 364 365 private I_CmsCacheKey m_keyGenerator; 366 367 368 private CmsLockManager m_lockManager = OpenCms.getLockManager(); 369 370 371 private Map m_projectCache; 372 373 374 private I_CmsProjectDriver m_projectDriver; 375 376 377 private Map m_propertyCache; 378 379 380 private Map m_resourceCache; 381 382 383 private Map m_resourceListCache; 384 385 386 private CmsSecurityManager m_securityManager; 387 388 389 private CmsSqlManager m_sqlManager; 390 391 392 private Map m_userCache; 393 394 395 private I_CmsUserDriver m_userDriver; 396 397 398 private Map m_userGroupsCache; 399 400 401 private I_CmsVfsDriver m_vfsDriver; 402 403 404 private I_CmsWorkflowDriver m_workflowDriver; 405 406 409 private CmsDriverManager() { 410 411 m_connectionPools = new ArrayList (); 412 } 413 414 435 public static CmsDriverManager newInstance( 436 CmsConfigurationManager configurationManager, 437 CmsSecurityManager securityManager, 438 I_CmsDbContextFactory runtimeInfoFactory) throws CmsInitException { 439 440 Map configuration = configurationManager.getConfiguration(); 441 442 ExtendedProperties config; 443 if (configuration instanceof ExtendedProperties) { 444 config = (ExtendedProperties)configuration; 445 } else { 446 config = new ExtendedProperties(); 447 config.putAll(configuration); 448 } 449 450 CmsDbUtil.init(); 452 453 List drivers = null; 454 String driverName = null; 455 456 I_CmsVfsDriver vfsDriver = null; 457 I_CmsUserDriver userDriver = null; 458 I_CmsProjectDriver projectDriver = null; 459 I_CmsWorkflowDriver workflowDriver = null; 460 I_CmsBackupDriver backupDriver = null; 461 462 CmsDriverManager driverManager = null; 463 try { 464 driverManager = new CmsDriverManager(); 466 if (CmsLog.INIT.isInfoEnabled()) { 467 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE1_0)); 468 } 469 if ((runtimeInfoFactory == null) && CmsLog.INIT.isDebugEnabled()) { 470 CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_RT_0)); 471 } 472 } catch (Exception exc) { 473 CmsMessageContainer message = Messages.get().container(Messages.LOG_ERR_DRIVER_MANAGER_START_0); 474 if (LOG.isFatalEnabled()) { 475 LOG.fatal(message.key(), exc); 476 } 477 throw new CmsInitException(message, exc); 478 } 479 480 driverManager.m_securityManager = securityManager; 482 483 driverManager.m_sqlManager = new CmsSqlManager(driverManager); 485 486 if (CmsLog.INIT.isInfoEnabled()) { 487 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE2_0)); 488 } 489 490 String [] driverPoolNames = config.getStringArray(CmsDriverManager.CONFIGURATION_DB + ".pools"); 492 if (CmsLog.INIT.isInfoEnabled()) { 493 String names = ""; 494 for (int p = 0; p < driverPoolNames.length; p++) { 495 names += driverPoolNames[p] + " "; 496 } 497 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_POOLS_1, names)); 498 } 499 500 for (int p = 0; p < driverPoolNames.length; p++) { 502 driverManager.newPoolInstance(config, driverPoolNames[p]); 503 } 504 505 if (runtimeInfoFactory != null) { 507 runtimeInfoFactory.initialize(driverManager); 508 } 509 510 if (CmsLog.INIT.isInfoEnabled()) { 511 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE3_0)); 512 } 513 514 drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_VFS)); 516 driverName = config.getString((String )drivers.get(0) + ".vfs.driver"); 517 drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null; 518 vfsDriver = (I_CmsVfsDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers); 519 520 drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_USER)); 522 driverName = config.getString((String )drivers.get(0) + ".user.driver"); 523 drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null; 524 userDriver = (I_CmsUserDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers); 525 526 drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_PROJECT)); 528 driverName = config.getString((String )drivers.get(0) + ".project.driver"); 529 drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null; 530 projectDriver = (I_CmsProjectDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers); 531 532 drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_WORKFLOW)); 534 driverName = config.getString((String )drivers.get(0) + ".workflow.driver"); 535 drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null; 536 workflowDriver = (I_CmsWorkflowDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers); 537 538 drivers = Arrays.asList(config.getStringArray(CmsDriverManager.CONFIGURATION_BACKUP)); 540 driverName = config.getString((String )drivers.get(0) + ".backup.driver"); 541 drivers = (drivers.size() > 1) ? drivers.subList(1, drivers.size()) : null; 542 backupDriver = (I_CmsBackupDriver)driverManager.newDriverInstance(configurationManager, driverName, drivers); 543 544 try { 545 driverManager.init( 547 configurationManager, 548 config, 549 vfsDriver, 550 userDriver, 551 projectDriver, 552 workflowDriver, 553 backupDriver); 554 if (CmsLog.INIT.isInfoEnabled()) { 555 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE4_OK_0)); 556 } 557 } catch (Exception exc) { 558 CmsMessageContainer message = Messages.get().container(Messages.LOG_ERR_DRIVER_MANAGER_START_0); 559 if (LOG.isFatalEnabled()) { 560 LOG.fatal(message.key(), exc); 561 } 562 throw new CmsInitException(message, exc); 563 } 564 565 org.opencms.main.OpenCms.addCmsEventListener(driverManager, new int[] { 567 I_CmsEventListener.EVENT_UPDATE_EXPORTS, 568 I_CmsEventListener.EVENT_CLEAR_CACHES, 569 I_CmsEventListener.EVENT_CLEAR_PRINCIPAL_CACHES, 570 I_CmsEventListener.EVENT_PUBLISH_PROJECT}); 571 572 return driverManager; 574 } 575 576 584 public void acceptTask(CmsDbContext dbc, int taskId) throws CmsException { 585 586 CmsTask task = m_workflowDriver.readTask(dbc, taskId); 587 task.setPercentage(1); 588 task = m_workflowDriver.writeTask(dbc, task); 589 m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Task was accepted from " 591 + dbc.currentUser().getFirstname() 592 + " " 593 + dbc.currentUser().getLastname() 594 + '.'); 595 } 596 597 607 public void addUserToGroup(CmsDbContext dbc, String username, String groupname) 608 throws CmsException, CmsDbEntryNotFoundException { 609 610 if (!userInGroup(dbc, username, groupname)) { 611 CmsUser user; 612 CmsGroup group; 613 try { 614 user = readUser(dbc, username); 615 } catch (CmsDbEntryNotFoundException e) { 616 user = readWebUser(dbc, username); 617 } 618 if (user != null) { 620 if (user.getType() == CmsUser.USER_TYPE_WEBUSER) { 623 List forbidden = new ArrayList (); 624 forbidden.add(OpenCms.getDefaultUsers().getGroupAdministrators()); 625 forbidden.add(OpenCms.getDefaultUsers().getGroupProjectmanagers()); 626 forbidden.add(OpenCms.getDefaultUsers().getGroupUsers()); 627 if (forbidden.contains(groupname)) { 628 throw new CmsSecurityException( 629 Messages.get().container(Messages.ERR_WEBUSER_GROUP_1, forbidden)); 630 } 631 } 632 633 group = readGroup(dbc, groupname); 634 if (group != null) { 636 m_userDriver.createUserInGroup(dbc, user.getId(), group.getId(), null); 638 m_userGroupsCache.clear(); 640 } else { 641 throw new CmsDbEntryNotFoundException(Messages.get().container( 642 Messages.ERR_UNKNOWN_GROUP_1, 643 groupname)); 644 } 645 } else { 646 throw new CmsDbEntryNotFoundException(Messages.get().container( 647 Messages.ERR_UNKNOWN_USER_1, 648 user.getName())); 649 } 650 } 651 } 652 653 677 public CmsUser addWebUser( 678 CmsDbContext dbc, 679 String name, 680 String password, 681 String group, 682 String description, 683 Map additionalInfos) 684 throws CmsException, CmsSecurityException, CmsIllegalArgumentException, CmsDbEntryNotFoundException { 685 686 return addWebUser(dbc, name, password, group, null, description, additionalInfos); 687 } 688 689 711 public CmsUser addWebUser( 712 CmsDbContext dbc, 713 String name, 714 String password, 715 String group, 716 String additionalGroup, 717 String description, 718 Map additionalInfos) 719 throws CmsException, CmsDbEntryNotFoundException, CmsIllegalArgumentException, CmsSecurityException { 720 721 CmsUser newUser = createUser(dbc, name, password, description, additionalInfos, CmsUser.USER_TYPE_WEBUSER); 722 CmsUser user = m_userDriver.readUser(dbc, newUser.getName(), CmsUser.USER_TYPE_WEBUSER); 723 if (user != null) { 725 CmsGroup usergroup = readGroup(dbc, group); 726 if (usergroup != null && isWebgroup(dbc, usergroup)) { 728 m_userDriver.createUserInGroup(dbc, user.getId(), usergroup.getId(), null); 730 m_userGroupsCache.clear(); 732 } else { 733 throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, group)); 734 } 735 if (CmsStringUtil.isNotEmpty(additionalGroup)) { 738 CmsGroup addGroup = readGroup(dbc, additionalGroup); 739 if (addGroup != null && isWebgroup(dbc, addGroup)) { 740 m_userDriver.createUserInGroup(dbc, user.getId(), addGroup.getId(), null); 742 m_userGroupsCache.clear(); 744 } else { 745 throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, group)); 746 } 747 } 748 } else { 749 throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_USER_1, user.getName())); 750 } 751 return newUser; 752 } 753 754 763 public void backupProject(CmsDbContext dbc, int tagId, long publishDate) throws CmsDataAccessException { 764 765 m_backupDriver.writeBackupProject(dbc, tagId, publishDate); 766 } 767 768 780 public void changeLastModifiedProjectId(CmsDbContext dbc, CmsResource resource) throws CmsException { 781 782 m_vfsDriver.writeLastModifiedProjectId(dbc, dbc.currentProject(), dbc.currentProject().getId(), resource); 784 785 clearResourceCache(); 786 787 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 788 "resource", 789 resource))); 790 } 791 792 808 public void changeLock(CmsDbContext dbc, CmsResource resource) throws CmsException, CmsSecurityException { 809 810 CmsLock currentLock = getLock(dbc, resource); 812 if (currentLock.isNullLock()) { 814 throw new CmsLockException(Messages.get().container( 815 Messages.ERR_CHANGE_LOCK_UNLOCKED_RESOURCE_1, 816 dbc.getRequestContext().getSitePath(resource))); 817 } else if (currentLock.getUserId().equals(dbc.currentUser().getId()) 818 && (currentLock.getProjectId() == dbc.currentProject().getId()) 819 && (currentLock.getType() == CmsLock.TYPE_EXCLUSIVE)) { 820 return; 822 } 823 824 int denied = 0; 827 boolean canIgnorePermissions = m_securityManager.hasRole(dbc, CmsRole.VFS_MANAGER); 829 if (!canIgnorePermissions && (resource.getTypeId() == CmsResourceTypeJsp.getStaticTypeId())) { 832 if (!m_securityManager.hasRole(dbc, CmsRole.DEVELOPER)) { 833 denied |= CmsPermissionSet.PERMISSION_WRITE; 834 } 835 } 836 CmsPermissionSetCustom permissions; 837 if (canIgnorePermissions) { 838 permissions = new CmsPermissionSetCustom(~0); 840 } else { 841 permissions = getPermissions(dbc, resource, dbc.currentUser()); 843 } 844 permissions.denyPermissions(denied); 846 if ((CmsPermissionSet.ACCESS_WRITE.getPermissions() & permissions.getPermissions()) != CmsPermissionSet.ACCESS_WRITE.getPermissions()) { 848 m_securityManager.checkPermissions( 850 dbc.getRequestContext(), 851 resource, 852 CmsPermissionSet.ACCESS_WRITE, 853 CmsSecurityManager.PERM_DENIED); 854 } 855 857 m_lockManager.removeResource(this, dbc, resource, true); 859 lockResource(dbc, resource, CmsLock.COMMON); 861 } 862 863 872 public void changeUserType(CmsDbContext dbc, CmsUser user, int userType) throws CmsDataAccessException { 873 874 clearUserCache(user); 876 m_userDriver.writeUserType(dbc, user.getId(), userType); 877 } 878 879 892 public void changeUserType(CmsDbContext dbc, CmsUUID userId, int userType) 893 throws CmsDataAccessException, CmsDbEntryNotFoundException, CmsDbSqlException { 894 895 CmsUser theUser = m_userDriver.readUser(dbc, userId); 896 changeUserType(dbc, theUser, userType); 897 } 898 899 910 public void changeUserType(CmsDbContext dbc, String username, int userType) throws CmsException { 911 912 CmsUser theUser = null; 913 try { 914 theUser = readWebUser(dbc, username); 916 } catch (CmsDbEntryNotFoundException confe) { 917 theUser = readUser(dbc, username); 919 } 920 changeUserType(dbc, theUser, userType); 921 } 922 923 939 public void chflags(CmsDbContext dbc, CmsResource resource, int flags) throws CmsException { 940 941 CmsResource clone = (CmsResource)resource.clone(); 943 clone.setFlags(flags); 944 writeResource(dbc, clone); 945 } 946 947 965 public void chtype(CmsDbContext dbc, CmsResource resource, int type) throws CmsException { 966 967 CmsResource clone = (CmsResource)resource.clone(); 969 I_CmsResourceType newType = OpenCms.getResourceManager().getResourceType(type); 970 clone.setType(newType.getTypeId()); 971 writeResource(dbc, clone); 972 } 973 974 977 public void cmsEvent(CmsEvent event) { 978 979 if (LOG.isDebugEnabled()) { 980 LOG.debug(Messages.get().getBundle().key(Messages.LOG_CMS_EVENT_1, new Integer (event.getType()))); 981 } 982 983 I_CmsReport report; 984 CmsDbContext dbc; 985 986 switch (event.getType()) { 987 988 case I_CmsEventListener.EVENT_UPDATE_EXPORTS: 989 report = (I_CmsReport)event.getData().get(I_CmsEventListener.KEY_REPORT); 990 dbc = (CmsDbContext)event.getData().get(I_CmsEventListener.KEY_DBCONTEXT); 991 updateExportPoints(dbc, report); 992 break; 993 994 case I_CmsEventListener.EVENT_PUBLISH_PROJECT: 995 CmsUUID publishHistoryId = new CmsUUID((String )event.getData().get(I_CmsEventListener.KEY_PUBLISHID)); 996 report = (I_CmsReport)event.getData().get(I_CmsEventListener.KEY_REPORT); 997 dbc = (CmsDbContext)event.getData().get(I_CmsEventListener.KEY_DBCONTEXT); 998 int projectId = ((Integer )event.getData().get(I_CmsEventListener.KEY_PROJECTID)).intValue(); 999 writeExportPoints(dbc, projectId, report, publishHistoryId); 1000 break; 1001 1002 case I_CmsEventListener.EVENT_CLEAR_CACHES: 1003 clearcache(false); 1004 break; 1005 case I_CmsEventListener.EVENT_CLEAR_PRINCIPAL_CACHES: 1006 clearcache(true); 1007 break; 1008 default: 1009 } 1011 } 1012 1013 1024 public void copyAccessControlEntries( 1025 CmsDbContext dbc, 1026 CmsResource source, 1027 CmsResource destination, 1028 boolean updateLastModifiedInfo) throws CmsException { 1029 1030 ListIterator aceList = m_userDriver.readAccessControlEntries( 1032 dbc, 1033 dbc.currentProject(), 1034 source.getResourceId(), 1035 false).listIterator(); 1036 1037 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), destination.getResourceId()); 1039 1040 while (aceList.hasNext()) { 1042 CmsAccessControlEntry ace = (CmsAccessControlEntry)aceList.next(); 1043 m_userDriver.createAccessControlEntry( 1044 dbc, 1045 dbc.currentProject(), 1046 destination.getResourceId(), 1047 ace.getPrincipal(), 1048 ace.getPermissions().getAllowedPermissions(), 1049 ace.getPermissions().getDeniedPermissions(), 1050 ace.getFlags()); 1051 } 1052 1053 if (updateLastModifiedInfo) { 1055 setDateLastModified(dbc, destination, destination.getDateLastModified()); 1056 } 1057 1058 clearAccessControlListCache(); 1060 1061 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 1063 "resource", 1064 destination))); 1065 } 1066 1067 1096 public void copyResource(CmsDbContext dbc, CmsResource source, String destination, int siblingMode) 1097 throws CmsException, CmsIllegalArgumentException { 1098 1099 boolean copyAsSibling = false; 1101 1102 if (!source.isFolder()) { 1104 if (siblingMode == CmsResource.COPY_AS_SIBLING) { 1106 copyAsSibling = true; 1107 } 1108 if (siblingMode == CmsResource.COPY_PRESERVE_SIBLING) { 1110 if (source.getSiblingCount() > 1) { 1111 copyAsSibling = true; 1112 } 1113 } 1114 } 1115 1116 List properties = readPropertyObjects(dbc, source, false); 1118 1119 if (copyAsSibling) { 1120 createSibling(dbc, source, destination, properties); 1122 return; 1124 } 1125 1126 byte[] content = null; 1128 if (source.isFile()) { 1129 CmsFile file; 1130 if (source instanceof CmsFile) { 1131 file = (CmsFile)source; 1133 content = file.getContents(); 1134 } 1135 if ((content == null) || (content.length < 1)) { 1136 file = m_vfsDriver.readFile(dbc, dbc.currentProject().getId(), false, source.getStructureId()); 1138 content = file.getContents(); 1139 } 1140 } 1141 1142 String destinationFoldername = CmsResource.getParentFolder(destination); 1144 String destinationResourceName = destination.substring(destinationFoldername.length()); 1145 1146 if (CmsResource.isFolder(destinationResourceName)) { 1147 destinationResourceName = destinationResourceName.substring(0, destinationResourceName.length() - 1); 1149 } 1150 1151 CmsFolder destinationFolder = m_securityManager.readFolder( 1153 dbc, 1154 destinationFoldername, 1155 CmsResourceFilter.IGNORE_EXPIRATION); 1156 1157 1159 long currentTime = System.currentTimeMillis(); 1161 long dateLastModified; 1162 CmsUUID userLastModified; 1163 if (source.isFolder()) { 1164 dateLastModified = currentTime; 1166 userLastModified = dbc.currentUser().getId(); 1167 } else { 1168 dateLastModified = source.getDateLastModified(); 1170 userLastModified = source.getUserLastModified(); 1171 } 1172 1173 int flags = source.getFlags(); 1175 if (source.isLabeled()) { 1176 flags &= ~CmsResource.FLAG_LABELED; 1178 } 1179 1180 CmsResource newResource = new CmsResource( 1182 new CmsUUID(), 1183 new CmsUUID(), 1184 destination, 1185 source.getTypeId(), 1186 source.isFolder(), 1187 flags, 1188 dbc.currentProject().getId(), 1189 CmsResource.STATE_NEW, 1190 currentTime, 1191 dbc.currentUser().getId(), 1192 dateLastModified, 1193 userLastModified, 1194 source.getDateReleased(), 1195 source.getDateExpired(), 1196 1, 1197 source.getLength()); 1198 1199 newResource.setDateLastModified(dateLastModified); 1201 1202 newResource = createResource(dbc, destination, newResource, content, properties, false); 1204 1205 copyAccessControlEntries(dbc, source, newResource, false); 1207 1208 clearAccessControlListCache(); 1210 1211 List modifiedResources = new ArrayList (); 1212 modifiedResources.add(source); 1213 modifiedResources.add(newResource); 1214 modifiedResources.add(destinationFolder); 1215 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_COPIED, Collections.singletonMap( 1216 "resources", 1217 modifiedResources))); 1218 1219 } 1220 1221 1232 public void copyResourceToProject(CmsDbContext dbc, CmsResource resource) throws CmsException { 1233 1234 if (!isInsideCurrentProject(dbc, resource.getRootPath())) { 1236 if (resource.isFolder()) { 1238 List projectResources = m_projectDriver.readProjectResources(dbc, dbc.currentProject()); 1239 for (int i = 0; i < projectResources.size(); i++) { 1240 String resname = (String )projectResources.get(i); 1241 if (resname.startsWith(resource.getRootPath())) { 1242 m_projectDriver.deleteProjectResource(dbc, dbc.currentProject().getId(), resname); 1244 } 1245 } 1246 } 1247 try { 1248 m_projectDriver.createProjectResource(dbc, dbc.currentProject().getId(), resource.getRootPath(), null); 1249 } catch (CmsException exc) { 1250 } finally { 1252 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap( 1253 "project", 1254 dbc.currentProject()))); 1255 } 1256 } 1257 } 1258 1259 1269 public int countLockedResources(CmsDbContext dbc, String foldername) throws CmsLockException { 1270 1271 if (dbc.currentProject().getFlags() == CmsProject.PROJECT_STATE_UNLOCKED) { 1273 return m_lockManager.countExclusiveLocksInFolder(foldername); 1275 } else { 1276 throw new CmsLockException(org.opencms.lock.Messages.get().container( 1277 org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1, 1278 dbc.currentProject().getName())); 1279 } 1280 } 1281 1282 1291 public int countLockedResources(CmsProject project) throws CmsLockException { 1292 1293 if (project.getFlags() == CmsProject.PROJECT_STATE_UNLOCKED) { 1295 return m_lockManager.countExclusiveLocksInProject(project); 1297 } else { 1298 throw new CmsLockException(org.opencms.lock.Messages.get().container( 1299 org.opencms.lock.Messages.ERR_RESOURCE_LOCKED_1, 1300 project.getName())); 1301 } 1302 } 1303 1304 1322 public CmsGroup createGroup(CmsDbContext dbc, CmsUUID id, String name, String description, int flags, String parent) 1323 throws CmsIllegalArgumentException, CmsDataAccessException { 1324 1325 OpenCms.getValidationHandler().checkGroupName(name); 1327 name = name.trim(); 1329 return m_userDriver.createGroup(dbc, id, name, description, flags, parent, null); 1331 } 1332 1333 1346 public CmsTask createProject(CmsDbContext dbc, String projectName, String roleName, long timeout, int priority) 1347 throws CmsDataAccessException { 1348 1349 CmsGroup role = null; 1350 1351 if (CmsStringUtil.isNotEmpty(roleName)) { 1353 role = readGroup(dbc, roleName); 1354 } 1355 java.sql.Timestamp timestamp = new java.sql.Timestamp (timeout); 1357 java.sql.Timestamp now = new java.sql.Timestamp (System.currentTimeMillis()); 1358 1359 return m_workflowDriver.createTask(dbc, 0, 0, 1, dbc.currentUser().getId(), 1361 dbc.currentUser().getId(), 1362 role.getId(), 1363 projectName, 1364 now, 1365 timestamp, 1366 priority); 1367 } 1368 1369 1385 public CmsProject createProject( 1386 CmsDbContext dbc, 1387 String name, 1388 String description, 1389 String groupname, 1390 String managergroupname, 1391 int projecttype) throws CmsIllegalArgumentException, CmsDataAccessException { 1392 1393 if (CmsProject.ONLINE_PROJECT_NAME.equals(name)) { 1394 throw new CmsIllegalArgumentException(Messages.get().container( 1395 Messages.ERR_CREATE_PROJECT_ONLINE_PROJECT_NAME_1, 1396 CmsProject.ONLINE_PROJECT_NAME)); 1397 } 1398 CmsGroup group = readGroup(dbc, groupname); 1400 CmsGroup managergroup = readGroup(dbc, managergroupname); 1401 1402 CmsTask task = createProject( 1404 dbc, 1405 name, 1406 group.getName(), 1407 System.currentTimeMillis(), 1408 CmsTaskService.TASK_PRIORITY_NORMAL); 1409 1410 return m_projectDriver.createProject( 1411 dbc, 1412 dbc.currentUser(), 1413 group, 1414 managergroup, 1415 task, 1416 name, 1417 description, 1418 CmsProject.PROJECT_STATE_UNLOCKED, 1419 projecttype, 1420 null); 1421 } 1422 1423 1435 public CmsPropertyDefinition createPropertyDefinition(CmsDbContext dbc, String name) throws CmsException { 1436 1437 CmsPropertyDefinition propertyDefinition = null; 1438 1439 name = name.trim(); 1440 CmsPropertyDefinition.checkPropertyName(name); 1442 1443 try { 1444 try { 1445 propertyDefinition = m_vfsDriver.readPropertyDefinition(dbc, name, dbc.currentProject().getId()); 1446 } catch (CmsException e) { 1447 propertyDefinition = m_vfsDriver.createPropertyDefinition(dbc, dbc.currentProject().getId(), name); 1448 } 1449 1450 try { 1451 m_vfsDriver.readPropertyDefinition(dbc, name, CmsProject.ONLINE_PROJECT_ID); 1452 } catch (CmsException e) { 1453 m_vfsDriver.createPropertyDefinition(dbc, CmsProject.ONLINE_PROJECT_ID, name); 1454 } 1455 1456 try { 1457 m_backupDriver.readBackupPropertyDefinition(dbc, name); 1458 } catch (CmsException e) { 1459 m_backupDriver.createBackupPropertyDefinition(dbc, name); 1460 } 1461 } finally { 1462 1463 OpenCms.fireCmsEvent(new CmsEvent( 1465 I_CmsEventListener.EVENT_PROPERTY_DEFINITION_CREATED, 1466 Collections.singletonMap("propertyDefinition", propertyDefinition))); 1467 1468 } 1469 1470 return propertyDefinition; 1471 } 1472 1473 1500 public CmsResource createResource( 1501 CmsDbContext dbc, 1502 String resourcePath, 1503 CmsResource resource, 1504 byte[] content, 1505 List properties, 1506 boolean importCase) throws CmsException { 1507 1508 CmsResource newResource = null; 1509 1510 if (m_concurrentCreateResourceLocks.contains(resourcePath)) { 1511 throw new CmsVfsResourceAlreadyExistsException(org.opencms.db.generic.Messages.get().container( 1513 org.opencms.db.generic.Messages.ERR_RESOURCE_WITH_NAME_CURRENTLY_CREATED_1, 1514 dbc.removeSiteRoot(resourcePath))); 1515 } 1519 1520 try { 1521 m_concurrentCreateResourceLocks.add(resourcePath); 1523 1524 boolean useLostAndFound = importCase && !OpenCms.getImportExportManager().overwriteCollidingResources(); 1526 1527 CmsResource currentResource = null; 1529 1530 try { 1531 currentResource = readResource(dbc, resourcePath, CmsResourceFilter.ALL); 1532 } catch (CmsVfsResourceNotFoundException e) { 1533 } 1536 1537 CmsResource parentFolder; 1538 String parentFolderName; 1539 String createdResourceName = resourcePath; 1540 int contentLength; 1541 1542 if (currentResource != null) { 1543 if (currentResource.getState() == CmsResource.STATE_DELETED) { 1544 if (!currentResource.isFolder()) { 1545 currentResource = null; 1547 } 1548 } else { 1549 if (!importCase) { 1550 throw new CmsVfsResourceAlreadyExistsException(org.opencms.db.generic.Messages.get().container( 1553 org.opencms.db.generic.Messages.ERR_RESOURCE_WITH_NAME_ALREADY_EXISTS_1, 1554 dbc.removeSiteRoot(resource.getRootPath()))); 1555 } 1556 if (!resource.isFolder() 1558 && useLostAndFound 1559 && (!currentResource.getResourceId().equals(resource.getResourceId()))) { 1560 createdResourceName = moveToLostAndFound(dbc, resourcePath, false); 1562 currentResource = null; 1564 } 1565 } 1566 } 1567 1568 parentFolderName = CmsResource.getParentFolder(createdResourceName); 1570 parentFolder = readFolder(dbc, parentFolderName, CmsResourceFilter.IGNORE_EXPIRATION); 1571 1572 if (currentResource == null) { 1574 m_securityManager.checkPermissions( 1576 dbc, 1577 parentFolder, 1578 CmsPermissionSet.ACCESS_WRITE, 1579 false, 1580 CmsResourceFilter.IGNORE_EXPIRATION); 1581 } else { 1582 m_securityManager.checkPermissions( 1584 dbc, 1585 currentResource, 1586 CmsPermissionSet.ACCESS_WRITE, 1587 !importCase, 1588 CmsResourceFilter.ALL); 1589 } 1590 1591 String targetName = CmsResource.getName(createdResourceName); 1593 1594 if (resource.isFolder()) { 1596 contentLength = -1; 1598 if (CmsResource.isFolder(targetName)) { 1600 targetName = targetName.substring(0, targetName.length() - 1); 1601 } 1602 } else { 1603 if (content != null) { 1605 contentLength = content.length; 1607 } else if (currentResource != null) { 1608 contentLength = currentResource.getLength(); 1610 } else { 1611 contentLength = resource.getLength(); 1613 } 1614 } 1615 1616 CmsResource.checkResourceName(targetName); 1620 1621 CmsUUID structureId; 1623 CmsUUID resourceId; 1624 if (currentResource != null) { 1625 structureId = currentResource.getStructureId(); 1627 resourceId = currentResource.getResourceId(); 1628 } else { 1629 structureId = new CmsUUID(); 1631 if (!resource.getResourceId().isNullUUID()) { 1632 resourceId = resource.getResourceId(); 1634 } else { 1635 resourceId = new CmsUUID(); 1637 } 1638 } 1639 1640 newResource = new CmsResource( 1642 structureId, 1643 resourceId, 1644 createdResourceName, 1645 resource.getTypeId(), 1646 resource.isFolder(), 1647 resource.getFlags(), 1648 dbc.currentProject().getId(), 1649 resource.getState(), 1650 resource.getDateCreated(), 1651 resource.getUserCreated(), 1652 resource.getDateLastModified(), 1653 resource.getUserLastModified(), 1654 resource.getDateReleased(), 1655 resource.getDateExpired(), 1656 1, 1657 contentLength); 1658 1659 if (resource.isTouched()) { 1661 newResource.setDateLastModified(resource.getDateLastModified()); 1663 } 1664 1665 if (resource.isFile()) { 1666 if (labelResource(dbc, resource, resourcePath, 2)) { 1668 int flags = resource.getFlags(); 1669 flags |= CmsResource.FLAG_LABELED; 1670 resource.setFlags(flags); 1671 } 1672 if (content == null) { 1674 newResource.setState(CmsResource.STATE_KEEP); 1675 } 1676 } 1677 1678 if (currentResource == null) { 1679 1680 newResource = m_vfsDriver.createResource(dbc, dbc.currentProject(), newResource, content); 1682 1683 } else { 1684 1685 int updateStates = (currentResource.getState() == CmsResource.STATE_NEW) ? CmsDriverManager.NOTHING_CHANGED 1689 : CmsDriverManager.UPDATE_ALL; 1690 m_vfsDriver.writeResource(dbc, dbc.currentProject(), newResource, updateStates); 1691 1692 if ((content != null) && resource.isFile()) { 1693 m_vfsDriver.writeContent(dbc, dbc.currentProject(), currentResource.getResourceId(), content); 1695 } 1696 1697 } 1698 1699 writePropertyObjects(dbc, newResource, properties); 1701 1702 lockResource(dbc, newResource, CmsLock.COMMON); 1704 1705 } finally { 1706 m_concurrentCreateResourceLocks.remove(resourcePath); 1708 1709 clearAccessControlListCache(); 1711 m_propertyCache.clear(); 1712 1713 if (newResource != null) { 1714 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_CREATED, Collections.singletonMap( 1716 "resource", 1717 newResource))); 1718 } 1719 } 1720 1721 return newResource; 1722 } 1723 1724 1746 public CmsResource createResource(CmsDbContext dbc, String resourcename, int type, byte[] content, List properties) 1747 throws CmsException, CmsIllegalArgumentException { 1748 1749 String targetName = resourcename; 1750 1751 if (content == null) { 1752 content = new byte[0]; 1754 } 1755 int size; 1756 1757 if (CmsFolder.isFolderType(type)) { 1758 if (CmsResource.isFolder(targetName)) { 1760 targetName = targetName.substring(0, targetName.length() - 1); 1761 } 1762 size = -1; 1763 } else { 1764 size = content.length; 1765 } 1766 1767 CmsResource newResource = new CmsResource(CmsUUID.getNullUUID(), CmsUUID.getNullUUID(), 1770 targetName, 1771 type, 1772 CmsFolder.isFolderType(type), 1773 0, 1774 dbc.currentProject().getId(), 1775 CmsResource.STATE_NEW, 1776 0, 1777 dbc.currentUser().getId(), 1778 0, 1779 dbc.currentUser().getId(), 1780 CmsResource.DATE_RELEASED_DEFAULT, 1781 CmsResource.DATE_EXPIRED_DEFAULT, 1782 1, 1783 size); 1784 1785 return createResource(dbc, targetName, newResource, content, properties, false); 1786 } 1787 1788 1801 public void createSibling(CmsDbContext dbc, CmsResource source, String destination, List properties) 1802 throws CmsException { 1803 1804 if (source.isFolder()) { 1805 throw new CmsVfsException(Messages.get().container(Messages.ERR_VFS_FOLDERS_DONT_SUPPORT_SIBLINGS_0)); 1806 } 1807 1808 String destinationFoldername = CmsResource.getParentFolder(destination); 1810 1811 CmsFolder destinationFolder = readFolder(dbc, destinationFoldername, CmsResourceFilter.IGNORE_EXPIRATION); 1813 1814 1816 int flags = source.getFlags(); 1818 if (labelResource(dbc, source, destination, 1)) { 1819 flags |= CmsResource.FLAG_LABELED; 1821 } 1822 1823 CmsResource newResource = new CmsResource( 1825 new CmsUUID(), 1826 source.getResourceId(), 1827 destination, 1828 source.getTypeId(), 1829 source.isFolder(), 1830 flags, 1831 dbc.currentProject().getId(), 1832 CmsResource.STATE_KEEP, 1833 source.getDateCreated(), source.getUserCreated(), 1835 source.getDateLastModified(), 1836 source.getUserLastModified(), 1837 source.getDateReleased(), 1838 source.getDateExpired(), 1839 source.getSiblingCount() + 1, 1840 source.getLength()); 1841 1842 newResource.setDateLastModified(newResource.getDateLastModified()); 1844 1845 newResource = createResource(dbc, destination, newResource, null, properties, false); 1847 1848 clearAccessControlListCache(); 1850 1851 List modifiedResources = new ArrayList (); 1852 modifiedResources.add(source); 1853 modifiedResources.add(newResource); 1854 modifiedResources.add(destinationFolder); 1855 OpenCms.fireCmsEvent(new CmsEvent( 1856 I_CmsEventListener.EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, 1857 Collections.singletonMap("resources", modifiedResources))); 1858 } 1859 1860 1878 public CmsTask createTask( 1879 CmsDbContext dbc, 1880 CmsUser currentUser, 1881 int projectid, 1882 String agentName, 1883 String roleName, 1884 String taskName, 1885 String taskComment, 1886 int taskType, 1887 long timeout, 1888 int priority) throws CmsException { 1889 1890 CmsUser agent = readUser(dbc, agentName, CmsUser.USER_TYPE_SYSTEMUSER); 1891 CmsGroup role = m_userDriver.readGroup(dbc, roleName); 1892 java.sql.Timestamp timestamp = new java.sql.Timestamp (timeout); 1893 java.sql.Timestamp now = new java.sql.Timestamp (System.currentTimeMillis()); 1894 1895 CmsTask.checkTaskName(taskName); 1897 1898 CmsTask task = m_workflowDriver.createTask( 1899 dbc, 1900 projectid, 1901 projectid, 1902 taskType, 1903 currentUser.getId(), 1904 agent.getId(), 1905 role.getId(), 1906 taskName, 1907 now, 1908 timestamp, 1909 priority); 1910 1911 if (CmsStringUtil.isNotEmpty(taskComment)) { 1912 m_workflowDriver.writeTaskLog(dbc, task.getId(), currentUser.getId(), new java.sql.Timestamp ( 1913 System.currentTimeMillis()), taskComment, CmsTaskService.TASKLOG_USER); 1914 } 1915 1916 return task; 1917 } 1918 1919 1942 public CmsTask createTask( 1943 CmsDbContext dbc, 1944 String agentName, 1945 String roleName, 1946 String taskname, 1947 long timeout, 1948 int priority) throws CmsException { 1949 1950 CmsGroup role = m_userDriver.readGroup(dbc, roleName); 1951 java.sql.Timestamp timestamp = new java.sql.Timestamp (timeout); 1952 java.sql.Timestamp now = new java.sql.Timestamp (System.currentTimeMillis()); 1953 CmsUUID agentId = CmsUUID.getNullUUID(); 1954 CmsTask.checkTaskName(taskname); 1956 try { 1957 agentId = readUser(dbc, agentName, CmsUser.USER_TYPE_SYSTEMUSER).getId(); 1958 } catch (Exception e) { 1959 } 1961 return m_workflowDriver.createTask(dbc, dbc.currentProject().getTaskId(), dbc.currentProject().getTaskId(), 1, dbc.currentUser().getId(), 1963 agentId, 1964 role.getId(), 1965 taskname, 1966 now, 1967 timestamp, 1968 priority); 1969 } 1970 1971 1980 public CmsProject createTempfileProject(CmsDbContext dbc) throws CmsException { 1981 1982 CmsGroup projectUserGroup = readGroup(dbc, OpenCms.getDefaultUsers().getGroupUsers()); 1984 CmsGroup projectManagerGroup = readGroup(dbc, OpenCms.getDefaultUsers().getGroupAdministrators()); 1985 1986 CmsTask task = createProject( 1988 dbc, 1989 I_CmsProjectDriver.TEMP_FILE_PROJECT_NAME, 1990 projectUserGroup.getName(), 1991 System.currentTimeMillis(), 1992 CmsTaskService.TASK_PRIORITY_NORMAL); 1993 1994 CmsProject tempProject = m_projectDriver.createProject( 1995 dbc, 1996 dbc.currentUser(), 1997 projectUserGroup, 1998 projectManagerGroup, 1999 task, 2000 I_CmsProjectDriver.TEMP_FILE_PROJECT_NAME, 2001 Messages.get().getBundle(dbc.getRequestContext().getLocale()).key( 2002 Messages.GUI_WORKPLACE_TEMPFILE_PROJECT_DESC_0), 2003 CmsProject.PROJECT_STATE_INVISIBLE, 2004 CmsProject.PROJECT_STATE_INVISIBLE, 2005 null); 2006 m_projectDriver.createProjectResource(dbc, tempProject.getId(), "/", null); 2007 2008 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap( 2009 "project", 2010 tempProject))); 2011 2012 return tempProject; 2013 } 2014 2015 2031 public CmsUser createUser(CmsDbContext dbc, String name, String password, String description, Map additionalInfos) 2032 throws CmsException, CmsIllegalArgumentException { 2033 2034 return createUser(dbc, name, password, description, additionalInfos, CmsUser.USER_TYPE_SYSTEMUSER); 2035 } 2036 2037 2050 public void deleteAllProperties(CmsDbContext dbc, String resourcename) throws CmsException { 2051 2052 CmsResource resource = null; 2053 List resources = new ArrayList (); 2054 2055 try { 2056 resource = readResource(dbc, resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 2058 2059 m_securityManager.checkPermissions( 2061 dbc, 2062 resource, 2063 CmsPermissionSet.ACCESS_WRITE, 2064 true, 2065 CmsResourceFilter.ALL); 2066 2067 if (resource.getSiblingCount() > 1) { 2069 m_vfsDriver.deletePropertyObjects( 2071 dbc, 2072 dbc.currentProject().getId(), 2073 resource, 2074 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_VALUES); 2075 resources.addAll(readSiblings(dbc, resource, CmsResourceFilter.ALL)); 2076 2077 } else { 2078 m_vfsDriver.deletePropertyObjects( 2080 dbc, 2081 dbc.currentProject().getId(), 2082 resource, 2083 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 2084 resources.add(resource); 2085 } 2086 } finally { 2087 m_propertyCache.clear(); 2089 2090 OpenCms.fireCmsEvent(new CmsEvent( 2092 I_CmsEventListener.EVENT_RESOURCES_AND_PROPERTIES_MODIFIED, 2093 Collections.singletonMap("resources", resources))); 2094 } 2095 } 2096 2097 2105 public void deleteAllStaticExportPublishedResources(CmsDbContext dbc, int linkType) throws CmsException { 2106 2107 m_projectDriver.deleteAllStaticExportPublishedResources(dbc, dbc.currentProject(), linkType); 2108 } 2109 2110 2118 public void deleteBackup(CmsDbContext dbc, CmsResource res) throws CmsDataAccessException { 2119 2120 List backupFileHeaders = m_backupDriver.readBackupFileHeaders(dbc, res.getRootPath(), res.getResourceId()); 2123 if (backupFileHeaders.size() > 0) { 2125 CmsBackupResource backupResource = (CmsBackupResource)backupFileHeaders.get(0); 2127 long timestamp = System.currentTimeMillis() + 100000; 2129 int maxTag = m_backupDriver.readBackupProjectTag(dbc, timestamp) + 1; 2131 int resVersions = m_backupDriver.readBackupMaxVersion(dbc, res.getResourceId()); 2132 m_backupDriver.deleteBackup(dbc, backupResource, maxTag, resVersions); 2134 } 2135 } 2136 2137 2152 public void deleteBackups(CmsDbContext dbc, long timestamp, int versions, I_CmsReport report) throws CmsException { 2153 2154 List allBackupFiles = m_backupDriver.readBackupFileHeaders(dbc); 2157 int counter = 1; 2158 int size = allBackupFiles.size(); 2159 int maxTag = m_backupDriver.readBackupProjectTag(dbc, timestamp); 2161 Iterator i = allBackupFiles.iterator(); 2162 while (i.hasNext()) { 2163 CmsBackupResource res = (CmsBackupResource)i.next(); 2165 2166 report.print(org.opencms.report.Messages.get().container( 2167 org.opencms.report.Messages.RPT_SUCCESSION_2, 2168 String.valueOf(counter), 2169 String.valueOf(size)), I_CmsReport.FORMAT_NOTE); 2170 report.print(Messages.get().container(Messages.RPT_CHECKING_0), I_CmsReport.FORMAT_NOTE); 2171 report.print(org.opencms.report.Messages.get().container( 2172 org.opencms.report.Messages.RPT_ARGUMENT_1, 2173 res.getRootPath())); 2174 2175 int resVersions = m_backupDriver.readBackupMaxVersion(dbc, res.getResourceId()); 2178 int versionsToDelete = resVersions - versions; 2179 2180 if (versionsToDelete > 0) { 2182 report.print(Messages.get().container(Messages.RPT_DELETE_VERSIONS_0), I_CmsReport.FORMAT_NOTE); 2183 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 2184 m_backupDriver.deleteBackup(dbc, res, maxTag, versionsToDelete); 2185 } else { 2186 report.print(Messages.get().container(Messages.RPT_DELETE_NOTHING_0), I_CmsReport.FORMAT_NOTE); 2187 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 2188 } 2189 2190 report.println( 2191 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 2192 I_CmsReport.FORMAT_OK); 2193 counter++; 2194 2195 int todo = 0; 2197 m_projectDriver.deletePublishHistory(dbc, dbc.currentProject().getId(), maxTag); 2198 } 2199 } 2200 2201 2212 public void deleteGroup(CmsDbContext dbc, CmsGroup group, CmsUUID replacementId) 2213 throws CmsDataAccessException, CmsException { 2214 2215 CmsGroup replacementGroup = null; 2216 if (replacementId != null) { 2217 replacementGroup = readGroup(dbc, replacementId); 2218 } 2219 List childs = getChild(dbc, group.getName()); 2221 List users = getUsersOfGroup(dbc, group.getName()); 2223 CmsProject onlineProject = readProject(dbc, CmsProject.ONLINE_PROJECT_ID); 2225 if (replacementGroup == null) { 2226 Iterator itUsers = users.iterator(); 2228 while (itUsers.hasNext()) { 2229 CmsUser user = (CmsUser)itUsers.next(); 2230 removeUserFromGroup(dbc, user.getName(), group.getName()); 2231 } 2232 CmsUUID parentId = group.getParentId(); 2234 if (parentId == null) { 2235 parentId = CmsUUID.getNullUUID(); 2236 } 2237 Iterator itChilds = childs.iterator(); 2238 while (itChilds.hasNext()) { 2239 CmsGroup child = (CmsGroup)itChilds.next(); 2240 child.setParentId(parentId); 2241 writeGroup(dbc, child); 2242 } 2243 } else { 2244 Iterator itChilds = childs.iterator(); 2246 while (itChilds.hasNext()) { 2247 CmsGroup child = (CmsGroup)itChilds.next(); 2248 child.setParentId(replacementId); 2249 writeGroup(dbc, child); 2250 } 2251 Iterator itUsers = users.iterator(); 2253 while (itUsers.hasNext()) { 2254 CmsUser user = (CmsUser)itUsers.next(); 2255 addUserToGroup(dbc, user.getName(), replacementGroup.getName()); 2256 removeUserFromGroup(dbc, user.getName(), group.getName()); 2257 } 2258 transferPrincipalResources(dbc, dbc.currentProject(), group.getId(), replacementId, true); 2260 transferPrincipalResources(dbc, onlineProject, group.getId(), replacementId, true); 2262 } 2263 m_userDriver.removeAccessControlEntriesForPrincipal(dbc, dbc.currentProject(), onlineProject, group.getId()); 2265 m_userDriver.deleteGroup(dbc, group.getName()); 2266 m_groupCache.remove(new CacheId(group.getName())); 2267 } 2268 2269 2280 public void deleteGroup(CmsDbContext dbc, String name) throws CmsDataAccessException, CmsException { 2281 2282 deleteGroup(dbc, readGroup(dbc, name), null); 2283 } 2284 2285 2295 public void deleteProject(CmsDbContext dbc, CmsProject deleteProject) throws CmsException { 2296 2297 int projectId = deleteProject.getId(); 2298 2299 List modifiedFiles = readChangedResourcesInsideProject(dbc, projectId, 1); 2301 2302 List modifiedFolders = readChangedResourcesInsideProject(dbc, projectId, CmsResourceTypeFolder.RESOURCE_TYPE_ID); 2304 2305 2307 for (int i = 0; i < modifiedFiles.size(); i++) { 2309 2310 CmsResource currentFile = (CmsResource)modifiedFiles.get(i); 2311 2312 if (currentFile.getState() == CmsResource.STATE_NEW) { 2313 2314 CmsLock lock = getLock(dbc, currentFile); 2315 if (lock.isNullLock()) { 2316 lockResource(dbc, currentFile, CmsLock.COMMON); 2318 } else if (!lock.getUserId().equals(dbc.currentUser().getId()) 2319 || lock.getProjectId() != dbc.currentProject().getId()) { 2320 changeLock(dbc, currentFile); 2321 } 2322 2323 m_vfsDriver.deletePropertyObjects( 2325 dbc, 2326 projectId, 2327 currentFile, 2328 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 2329 2330 m_vfsDriver.removeFile(dbc, dbc.currentProject(), currentFile, true); 2332 2333 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), currentFile.getResourceId()); 2335 2336 OpenCms.fireCmsEvent(new CmsEvent( 2337 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 2338 Collections.singletonMap("resource", currentFile))); 2339 } 2340 } 2341 2342 for (int i = 0; i < modifiedFolders.size(); i++) { 2344 2345 CmsResource currentFolder = (CmsResource)modifiedFolders.get(i); 2346 if (currentFolder.getState() == CmsResource.STATE_NEW) { 2347 2348 m_vfsDriver.deletePropertyObjects( 2350 dbc, 2351 projectId, 2352 currentFolder, 2353 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 2354 2355 m_vfsDriver.removeFolder(dbc, dbc.currentProject(), currentFolder); 2356 2357 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), currentFolder.getResourceId()); 2359 2360 OpenCms.fireCmsEvent(new CmsEvent( 2361 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 2362 Collections.singletonMap("resource", currentFolder))); 2363 } 2364 } 2365 2366 for (int i = 0; i < modifiedFolders.size(); i++) { 2368 2369 CmsResource currentFolder = (CmsResource)modifiedFolders.get(i); 2370 2371 if ((currentFolder.getState() == CmsResource.STATE_CHANGED) 2372 || (currentFolder.getState() == CmsResource.STATE_DELETED)) { 2373 CmsLock lock = getLock(dbc, currentFolder); 2374 if (lock.isNullLock()) { 2375 lockResource(dbc, currentFolder, CmsLock.COMMON); 2377 } else if (!lock.getUserId().equals(dbc.currentUser().getId()) 2378 || lock.getProjectId() != dbc.currentProject().getId()) { 2379 changeLock(dbc, currentFolder); 2380 } 2381 2382 undoChanges(dbc, currentFolder); 2384 2385 OpenCms.fireCmsEvent(new CmsEvent( 2386 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 2387 Collections.singletonMap("resource", currentFolder))); 2388 } 2389 } 2390 2391 for (int i = 0; i < modifiedFiles.size(); i++) { 2393 2394 CmsResource currentFile = (CmsResource)modifiedFiles.get(i); 2395 2396 if ((currentFile.getState() == CmsResource.STATE_CHANGED) 2397 || (currentFile.getState() == CmsResource.STATE_DELETED)) { 2398 2399 CmsLock lock = getLock(dbc, currentFile); 2400 if (lock.isNullLock()) { 2401 lockResource(dbc, currentFile, CmsLock.COMMON); 2403 } else if (!lock.getUserId().equals(dbc.currentUser().getId()) 2404 || lock.getProjectId() != dbc.currentProject().getId()) { 2405 changeLock(dbc, currentFile); 2406 } 2407 2408 undoChanges(dbc, currentFile); 2410 2411 OpenCms.fireCmsEvent(new CmsEvent( 2412 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 2413 Collections.singletonMap("resource", currentFile))); 2414 } 2415 } 2416 2417 m_lockManager.removeResourcesInProject(deleteProject.getId()); 2419 clearAccessControlListCache(); 2420 clearResourceCache(); 2421 2422 if (projectId == dbc.currentProject().getId()) { 2424 dbc.getRequestContext().setCurrentProject(readProject(dbc, CmsProject.ONLINE_PROJECT_ID)); 2425 } 2426 2427 m_projectDriver.deleteProject(dbc, deleteProject); 2429 m_projectCache.remove(new Integer (projectId)); 2430 m_projectCache.remove(deleteProject.getName()); 2431 2432 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap( 2433 "project", 2434 deleteProject))); 2435 2436 } 2437 2438 2446 public void deletePropertyDefinition(CmsDbContext dbc, String name) throws CmsException { 2447 2448 CmsPropertyDefinition propertyDefinition = null; 2449 2450 try { 2451 propertyDefinition = readPropertyDefinition(dbc, name); 2453 m_vfsDriver.deletePropertyDefinition(dbc, propertyDefinition); 2454 m_backupDriver.deleteBackupPropertyDefinition(dbc, propertyDefinition); 2455 } finally { 2456 2457 OpenCms.fireCmsEvent(new CmsEvent( 2459 I_CmsEventListener.EVENT_PROPERTY_DEFINITION_MODIFIED, 2460 Collections.singletonMap("propertyDefinition", propertyDefinition))); 2461 } 2462 } 2463 2464 2484 public void deleteResource(CmsDbContext dbc, CmsResource resource, int siblingMode) throws CmsException { 2485 2486 CmsLock currentLock = getLock(dbc, resource); 2488 if (currentLock.getType() == CmsLock.TYPE_INHERITED) { 2489 lockResource(dbc, resource, CmsLock.COMMON); 2491 } 2492 2493 2495 if (resource.isFolder()) { 2496 siblingMode = CmsResource.DELETE_PRESERVE_SIBLINGS; 2498 } 2499 2500 boolean allSiblingsRemoved; 2502 List resources; 2503 if (siblingMode == CmsResource.DELETE_REMOVE_SIBLINGS) { 2504 resources = new ArrayList (readSiblings(dbc, resource, CmsResourceFilter.ALL)); 2505 allSiblingsRemoved = true; 2506 2507 resources.remove(resource); 2510 resources.add(resource); 2511 } else { 2512 resources = Collections.singletonList(resource); 2514 allSiblingsRemoved = false; 2515 } 2516 2517 int size = resources.size(); 2518 if (size > 1) { 2520 for (int i = 0; i < size; i++) { 2522 2523 CmsResource currentResource = (CmsResource)resources.get(i); 2524 currentLock = getLock(dbc, currentResource); 2525 2526 if (!currentLock.equals(CmsLock.getNullLock()) 2527 && !currentLock.getUserId().equals(dbc.currentUser().getId())) { 2528 CmsRequestContext context = dbc.getRequestContext(); 2530 throw new CmsLockException(org.opencms.lock.Messages.get().container( 2531 org.opencms.lock.Messages.ERR_SIBLING_LOCKED_2, 2532 context.getSitePath(currentResource), 2533 context.getSitePath(resource))); 2534 } 2535 } 2536 } 2537 2538 boolean removeAce = true; 2539 2540 for (int i = 0; i < size; i++) { 2542 CmsResource currentResource = (CmsResource)resources.get(i); 2543 2544 if (CmsSecurityManager.PERM_ALLOWED != m_securityManager.hasPermissions( 2546 dbc, 2547 currentResource, 2548 CmsPermissionSet.ACCESS_WRITE, 2549 true, 2550 CmsResourceFilter.ALL)) { 2551 2552 allSiblingsRemoved = false; 2554 2555 } else { 2556 2557 boolean existsOnline = m_vfsDriver.validateStructureIdExists( 2559 dbc, 2560 CmsProject.ONLINE_PROJECT_ID, 2561 currentResource.getStructureId()); 2562 2563 if (!existsOnline) { 2564 2567 deleteAllProperties(dbc, currentResource.getRootPath()); 2569 2570 if (currentResource.isFolder()) { 2571 m_vfsDriver.removeFolder(dbc, dbc.currentProject(), currentResource); 2572 } else { 2573 if (currentResource.isLabeled() && !labelResource(dbc, currentResource, null, 2)) { 2575 int flags = currentResource.getFlags(); 2577 flags &= ~CmsResource.FLAG_LABELED; 2578 currentResource.setFlags(flags); 2579 } 2580 m_vfsDriver.removeFile(dbc, dbc.currentProject(), currentResource, true); 2581 } 2582 2583 m_lockManager.removeDeletedResource(this, dbc, currentResource.getRootPath()); 2587 2588 } else { 2589 removeAce = false; 2593 2594 currentResource.setState(CmsResource.STATE_DELETED); 2596 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), currentResource, UPDATE_STRUCTURE_STATE); 2597 2598 m_vfsDriver.writePropertyObject(dbc, dbc.currentProject(), currentResource, new CmsProperty( 2600 CmsPropertyDefinition.PROPERTY_INTERNAL, 2601 String.valueOf(dbc.currentProject().getId()), 2602 null)); 2603 2604 m_vfsDriver.writeLastModifiedProjectId( 2606 dbc, 2607 dbc.currentProject(), 2608 dbc.currentProject().getId(), 2609 currentResource); 2610 } 2611 } 2612 } 2613 2614 if ((resource.getSiblingCount() <= 1) || allSiblingsRemoved) { 2615 if (removeAce) { 2616 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); 2618 } else { 2619 m_userDriver.deleteAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); 2621 } 2622 } 2623 2624 clearAccessControlListCache(); 2626 m_propertyCache.clear(); 2627 2628 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_DELETED, Collections.singletonMap( 2629 "resources", 2630 resources))); 2631 } 2632 2633 2643 public void deleteStaticExportPublishedResource( 2644 CmsDbContext dbc, 2645 String resourceName, 2646 int linkType, 2647 String linkParameter) throws CmsException { 2648 2649 m_projectDriver.deleteStaticExportPublishedResource( 2650 dbc, 2651 dbc.currentProject(), 2652 resourceName, 2653 linkType, 2654 linkParameter); 2655 } 2656 2657 2670 public void deleteUser(CmsDbContext dbc, CmsProject project, String username, String replacementUsername) 2671 throws CmsException { 2672 2673 CmsUser user = readUser(dbc, username); 2675 CmsUser replacementUser = null; 2676 if (replacementUsername != null) { 2677 replacementUser = readUser(dbc, replacementUsername); 2678 } 2679 2680 CmsProject onlineProject = readProject(dbc, CmsProject.ONLINE_PROJECT_ID); 2681 boolean withACEs = true; 2682 if (replacementUser == null) { 2683 withACEs = false; 2684 replacementUser = readUser(dbc, OpenCms.getDefaultUsers().getUserDeletedResource()); 2685 } 2686 Iterator itGroups = getGroupsOfUser(dbc, username).iterator(); 2687 while (itGroups.hasNext()) { 2688 CmsGroup group = (CmsGroup)itGroups.next(); 2689 if (!m_securityManager.hasRole(dbc, replacementUser, CmsRole.VFS_MANAGER)) { 2690 if (!userInGroup(dbc, replacementUser.getName(), group.getName())) { 2692 addUserToGroup(dbc, replacementUser.getName(), group.getName()); 2693 } 2694 } 2695 if (userInGroup(dbc, username, group.getName())) { 2697 removeUserFromGroup(dbc, username, group.getName()); 2698 } 2699 } 2700 2701 transferPrincipalResources(dbc, project, user.getId(), replacementUser.getId(), withACEs); 2703 transferPrincipalResources(dbc, onlineProject, user.getId(), replacementUser.getId(), withACEs); 2705 m_userDriver.removeAccessControlEntriesForPrincipal(dbc, project, onlineProject, user.getId()); 2706 m_userDriver.deleteUser(dbc, username); 2707 clearUserCache(user); 2709 } 2710 2711 2719 public void deleteWebUser(CmsDbContext dbc, CmsUUID userId) throws CmsException { 2720 2721 CmsUser user = readUser(dbc, userId); 2722 m_userDriver.deleteUser(dbc, user.getName()); 2723 clearUserCache(user); 2725 } 2726 2727 2732 public void destroy() throws Throwable { 2733 2734 finalize(); 2735 if (CmsLog.INIT.isInfoEnabled()) { 2736 CmsLog.INIT.info(Messages.get().getBundle().key( 2737 Messages.INIT_DRIVER_MANAGER_DESTROY_1, 2738 getClass().getName())); 2739 } 2740 } 2741 2742 2750 public void endTask(CmsDbContext dbc, int taskid) throws CmsException { 2751 2752 m_workflowDriver.endTask(dbc, taskid); 2753 if (dbc.currentUser() == null) { 2754 m_workflowDriver.writeSystemTaskLog(dbc, taskid, "Task finished."); 2755 2756 } else { 2757 m_workflowDriver.writeSystemTaskLog(dbc, taskid, "Task finished by " 2758 + dbc.currentUser().getFirstname() 2759 + " " 2760 + dbc.currentUser().getLastname() 2761 + '.'); 2762 } 2763 } 2764 2765 2773 public boolean existsResourceId(CmsDbContext dbc, CmsUUID resourceId) throws CmsException { 2774 2775 return m_vfsDriver.validateResourceIdExists(dbc, dbc.currentProject().getId(), resourceId); 2776 } 2777 2778 2794 public CmsPublishList fillPublishList(CmsDbContext dbc, CmsPublishList publishList) throws CmsException { 2795 2796 if (!publishList.isDirectPublish()) { 2797 2800 List folderList = m_vfsDriver.readResourceTree( 2801 dbc, 2802 dbc.currentProject().getId(), 2803 CmsDriverManager.READ_IGNORE_PARENT, 2804 CmsDriverManager.READ_IGNORE_TYPE, 2805 CmsResource.STATE_UNCHANGED, 2806 CmsDriverManager.READ_IGNORE_TIME, 2807 CmsDriverManager.READ_IGNORE_TIME, 2808 CmsDriverManager.READ_IGNORE_TIME, 2809 CmsDriverManager.READ_IGNORE_TIME, 2810 CmsDriverManager.READ_IGNORE_TIME, 2811 CmsDriverManager.READ_IGNORE_TIME, 2812 CmsDriverManager.READMODE_INCLUDE_TREE 2813 | CmsDriverManager.READMODE_INCLUDE_PROJECT 2814 | CmsDriverManager.READMODE_EXCLUDE_STATE 2815 | CmsDriverManager.READMODE_ONLY_FOLDERS); 2816 2817 publishList.addFolders(filterResources(dbc, folderList, folderList)); 2818 2819 List fileList = m_vfsDriver.readResourceTree( 2820 dbc, 2821 dbc.currentProject().getId(), 2822 CmsDriverManager.READ_IGNORE_PARENT, 2823 CmsDriverManager.READ_IGNORE_TYPE, 2824 CmsResource.STATE_UNCHANGED, 2825 CmsDriverManager.READ_IGNORE_TIME, 2826 CmsDriverManager.READ_IGNORE_TIME, 2827 CmsDriverManager.READ_IGNORE_TIME, 2828 CmsDriverManager.READ_IGNORE_TIME, 2829 CmsDriverManager.READ_IGNORE_TIME, 2830 CmsDriverManager.READ_IGNORE_TIME, 2831 CmsDriverManager.READMODE_INCLUDE_TREE 2832 | CmsDriverManager.READMODE_INCLUDE_PROJECT 2833 | CmsDriverManager.READMODE_EXCLUDE_STATE 2834 | CmsDriverManager.READMODE_ONLY_FILES); 2835 2836 publishList.addFiles(filterResources(dbc, publishList.getFolderList(), fileList)); 2837 2838 } else { 2839 Iterator it = publishList.getDirectPublishResources().iterator(); 2841 while (it.hasNext()) { 2842 CmsResource directPublishResource = (CmsResource)it.next(); 2844 if (directPublishResource.isFolder()) { 2845 2846 2850 if (CmsResource.STATE_UNCHANGED != directPublishResource.getState() 2851 && getLock(dbc, directPublishResource).isNullLock()) { 2852 publishList.addFolder(directPublishResource); 2853 } 2854 2855 if (publishList.isPublishSubResources()) { 2856 2858 List folderList = m_vfsDriver.readResourceTree( 2859 dbc, 2860 dbc.currentProject().getId(), 2861 directPublishResource.getRootPath(), 2862 CmsDriverManager.READ_IGNORE_TYPE, 2863 CmsResource.STATE_UNCHANGED, 2864 CmsDriverManager.READ_IGNORE_TIME, 2865 CmsDriverManager.READ_IGNORE_TIME, 2866 CmsDriverManager.READ_IGNORE_TIME, 2867 CmsDriverManager.READ_IGNORE_TIME, 2868 CmsDriverManager.READ_IGNORE_TIME, 2869 CmsDriverManager.READ_IGNORE_TIME, 2870 CmsDriverManager.READMODE_INCLUDE_TREE 2871 | CmsDriverManager.READMODE_INCLUDE_PROJECT 2872 | CmsDriverManager.READMODE_EXCLUDE_STATE 2873 | CmsDriverManager.READMODE_ONLY_FOLDERS); 2874 2875 publishList.addFolders(filterResources(dbc, publishList.getFolderList(), folderList)); 2876 2877 List fileList = m_vfsDriver.readResourceTree( 2878 dbc, 2879 dbc.currentProject().getId(), 2880 directPublishResource.getRootPath(), 2881 CmsDriverManager.READ_IGNORE_TYPE, 2882 CmsResource.STATE_UNCHANGED, 2883 CmsDriverManager.READ_IGNORE_TIME, 2884 CmsDriverManager.READ_IGNORE_TIME, 2885 CmsDriverManager.READ_IGNORE_TIME, 2886 CmsDriverManager.READ_IGNORE_TIME, 2887 CmsDriverManager.READ_IGNORE_TIME, 2888 CmsDriverManager.READ_IGNORE_TIME, 2889 CmsDriverManager.READMODE_INCLUDE_TREE 2890 | CmsDriverManager.READMODE_INCLUDE_PROJECT 2891 | CmsDriverManager.READMODE_EXCLUDE_STATE 2892 | CmsDriverManager.READMODE_ONLY_FILES); 2893 2894 publishList.addFiles(filterResources(dbc, publishList.getFolderList(), fileList)); 2895 } 2896 } else if (directPublishResource.isFile() 2897 && CmsResource.STATE_UNCHANGED != directPublishResource.getState()) { 2898 2899 2902 if (getLock(dbc, directPublishResource).isNullLock()) { 2903 publishList.addFile(directPublishResource); 2904 } 2905 } 2906 } 2907 } 2908 2909 if (publishList.isPublishSiblings()) { 2911 2912 List publishFiles = publishList.getFileList(); 2913 int size = publishFiles.size(); 2914 2915 for (int i = 0; i < size; i++) { 2916 CmsResource currentFile = (CmsResource)publishFiles.get(i); 2917 if (currentFile.getSiblingCount() > 1) { 2918 publishList.addFiles(filterSiblings(dbc, currentFile, publishList.getFolderList(), readSiblings( 2919 dbc, 2920 currentFile, 2921 CmsResourceFilter.ALL_MODIFIED))); 2922 } 2923 } 2924 } 2925 2926 publishList.initialize(); 2927 return publishList; 2928 } 2929 2930 2940 public void forwardTask(CmsDbContext dbc, int taskid, String newRoleName, String newUserName) throws CmsException { 2941 2942 CmsGroup newRole = m_userDriver.readGroup(dbc, newRoleName); 2943 CmsUser newUser = null; 2944 if (CmsStringUtil.isEmpty(newUserName)) { 2945 newUser = readUser(dbc, m_workflowDriver.readAgent(dbc, newRole.getId())); 2946 } else { 2947 newUser = readUser(dbc, newUserName, CmsUser.USER_TYPE_SYSTEMUSER); 2948 } 2949 2950 m_workflowDriver.forwardTask(dbc, taskid, newRole.getId(), newUser.getId()); 2951 m_workflowDriver.writeSystemTaskLog(dbc, taskid, "Task fowarded from " 2952 + dbc.currentUser().getFirstname() 2953 + " " 2954 + dbc.currentUser().getLastname() 2955 + " to " 2956 + newUser.getFirstname() 2957 + " " 2958 + newUser.getLastname() 2959 + '.'); 2960 } 2961 2962 2973 public List getAccessControlEntries(CmsDbContext dbc, CmsResource resource, boolean getInherited) 2974 throws CmsException { 2975 2976 List ace = m_userDriver.readAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId(), false); 2978 2979 String parentPath = CmsResource.getParentFolder(resource.getRootPath()); 2983 int d = (resource.isFolder()) ? 1 : 0; 2984 2985 while (getInherited && parentPath != null) { 2986 resource = m_vfsDriver.readFolder(dbc, dbc.currentProject().getId(), parentPath); 2987 List entries = m_userDriver.readAccessControlEntries( 2988 dbc, 2989 dbc.currentProject(), 2990 resource.getResourceId(), 2991 d > 0); 2992 2993 for (Iterator i = entries.iterator(); i.hasNext();) { 2994 CmsAccessControlEntry e = (CmsAccessControlEntry)i.next(); 2995 e.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_INHERITED); 2996 } 2997 2998 ace.addAll(entries); 2999 parentPath = CmsResource.getParentFolder(resource.getRootPath()); 3000 d++; 3001 } 3002 3003 return ace; 3004 } 3005 3006 3016 public CmsAccessControlList getAccessControlList(CmsDbContext dbc, CmsResource resource) throws CmsException { 3017 3018 return getAccessControlList(dbc, resource, false); 3019 } 3020 3021 3038 public CmsAccessControlList getAccessControlList(CmsDbContext dbc, CmsResource resource, boolean inheritedOnly) 3039 throws CmsException { 3040 3041 return getAccessControlList(dbc, resource, inheritedOnly, resource.isFolder(), 0); 3042 } 3043 3044 3051 public int getActiveConnections(String dbPoolUrl) throws CmsDbException { 3052 3053 try { 3054 for (Iterator i = m_connectionPools.iterator(); i.hasNext();) { 3055 PoolingDriver d = (PoolingDriver)i.next(); 3056 ObjectPool p = d.getConnectionPool(dbPoolUrl); 3057 return p.getNumActive(); 3058 } 3059 } catch (Exception exc) { 3060 CmsMessageContainer message = Messages.get().container(Messages.ERR_ACCESSING_POOL_1, dbPoolUrl); 3061 throw new CmsDbException(message, exc); 3062 } 3063 3064 CmsMessageContainer message = Messages.get().container(Messages.ERR_UNKNOWN_POOL_URL_1, dbPoolUrl); 3065 throw new CmsDbException(message); 3066 } 3067 3068 3078 public List getAllAccessibleProjects(CmsDbContext dbc) throws CmsException { 3079 3080 if (m_securityManager.hasRole(dbc, CmsRole.PROJECT_MANAGER)) { 3081 return m_projectDriver.readProjects(dbc, CmsProject.PROJECT_STATE_UNLOCKED); 3083 } 3084 3085 List groups = getGroupsOfUser(dbc, dbc.currentUser().getName()); 3087 3088 Set projects = new HashSet (m_projectDriver.readProjectsForUser(dbc, dbc.currentUser())); 3090 3091 for (int i = 0, n = groups.size(); i < n; i++) { 3093 projects.addAll(m_projectDriver.readProjectsForGroup(dbc, (CmsGroup)groups.get(i))); 3094 } 3095 3096 ArrayList accessibleProjects = new ArrayList (projects); 3098 Collections.sort(accessibleProjects); 3099 return accessibleProjects; 3100 } 3101 3102 3112 public List getAllBackupProjects(CmsDbContext dbc) throws CmsException { 3113 3114 return m_backupDriver.readBackupProjects(dbc); 3115 } 3116 3117 3127 public List getAllManageableProjects(CmsDbContext dbc) throws CmsException { 3128 3129 Set projects = new HashSet (); 3131 3132 if (m_securityManager.hasRole(dbc, CmsRole.PROJECT_MANAGER)) { 3133 3134 projects.addAll(m_projectDriver.readProjects(dbc, CmsProject.PROJECT_STATE_UNLOCKED)); 3136 } else { 3137 3138 projects.addAll(m_projectDriver.readProjectsForUser(dbc, dbc.currentUser())); 3140 3141 List groups = getGroupsOfUser(dbc, dbc.currentUser().getName()); 3143 3144 for (int i = 0, n = groups.size(); i < n; i++) { 3146 projects.addAll(m_projectDriver.readProjectsForManagerGroup(dbc, (CmsGroup)groups.get(i))); 3147 } 3148 } 3149 3150 projects.remove(readProject(dbc, CmsProject.ONLINE_PROJECT_ID)); 3152 3153 return new ArrayList (projects); 3155 } 3156 3157 3162 public I_CmsBackupDriver getBackupDriver() { 3163 3164 return m_backupDriver; 3165 } 3166 3167 3174 public int getBackupTagId(CmsDbContext dbc) { 3175 3176 return m_backupDriver.readNextBackupTagId(dbc); 3177 } 3178 3179 3189 public List getChild(CmsDbContext dbc, String groupname) throws CmsException { 3190 3191 return m_userDriver.readChildGroups(dbc, groupname); 3192 } 3193 3194 3206 public List getChilds(CmsDbContext dbc, String groupname) throws CmsException { 3207 3208 Set allChilds = new HashSet (); 3209 Iterator it = m_userDriver.readChildGroups(dbc, groupname).iterator(); 3211 while (it.hasNext()) { 3212 CmsGroup group = (CmsGroup)it.next(); 3213 allChilds.add(group); 3215 allChilds.addAll(getChilds(dbc, group.getName())); 3217 } 3218 return new ArrayList (allChilds); 3219 } 3220 3221 3228 public Map getConfigurations() { 3229 3230 return m_configuration; 3231 } 3232 3233 3243 public List getDirectGroupsOfUser(CmsDbContext dbc, String username) throws CmsException { 3244 3245 CmsUser user = readUser(dbc, username); 3246 return m_userDriver.readGroupsOfUser(dbc, user.getId(), dbc.getRequestContext().getRemoteAddress()); 3247 } 3248 3249 3258 public List getGroups(CmsDbContext dbc) throws CmsException { 3259 3260 return m_userDriver.readGroups(dbc); 3261 } 3262 3263 3273 public List getGroupsOfUser(CmsDbContext dbc, String username) throws CmsException { 3274 3275 return getGroupsOfUser(dbc, username, dbc.getRequestContext().getRemoteAddress()); 3276 } 3277 3278 3289 public List getGroupsOfUser(CmsDbContext dbc, String username, String remoteAddress) throws CmsException { 3290 3291 CmsUser user = readUser(dbc, username); 3292 String cacheKey = m_keyGenerator.getCacheKeyForUserGroups(remoteAddress, dbc, user); 3293 3294 List allGroups = (List)m_userGroupsCache.get(cacheKey); 3295 if (allGroups == null) { 3296 3297 List groups = m_userDriver.readGroupsOfUser(dbc, user.getId(), remoteAddress); 3299 allGroups = new ArrayList (groups); 3300 for (int i = 0; i < groups.size(); i++) { 3302 3303 CmsGroup parent = getParent(dbc, ((CmsGroup)groups.get(i)).getName()); 3304 while ((parent != null) && (!allGroups.contains(parent))) { 3305 3306 allGroups.add(parent); 3307 parent = getParent(dbc, parent.getName()); 3309 } 3310 } 3311 allGroups = Collections.unmodifiableList(allGroups); 3313 m_userGroupsCache.put(cacheKey, allGroups); 3314 } 3315 3316 return allGroups; 3317 } 3318 3319 3325 public CmsXmlDocumentLinkValidator getHtmlLinkValidator() { 3326 3327 return m_htmlLinkValidator; 3328 } 3329 3330 3337 public int getIdleConnections(String dbPoolUrl) throws CmsDbException { 3338 3339 try { 3340 for (Iterator i = m_connectionPools.iterator(); i.hasNext();) { 3341 PoolingDriver d = (PoolingDriver)i.next(); 3342 ObjectPool p = d.getConnectionPool(dbPoolUrl); 3343 return p.getNumIdle(); 3344 } 3345 } catch (Exception exc) { 3346 CmsMessageContainer message = Messages.get().container(Messages.ERR_ACCESSING_POOL_1, dbPoolUrl); 3347 throw new CmsDbException(message, exc); 3348 } 3349 3350 CmsMessageContainer message = Messages.get().container(Messages.ERR_UNKNOWN_POOL_URL_1, dbPoolUrl); 3351 throw new CmsDbException(message); 3352 } 3353 3354 3364 public CmsLock getLock(CmsDbContext dbc, CmsResource resource) throws CmsException { 3365 3366 return m_lockManager.getLock(this, dbc, resource); 3367 } 3368 3369 3379 public CmsGroup getParent(CmsDbContext dbc, String groupname) throws CmsException { 3380 3381 CmsGroup group = readGroup(dbc, groupname); 3382 if (group.getParentId().isNullUUID()) { 3383 return null; 3384 } 3385 3386 CmsGroup parent = (CmsGroup)m_groupCache.get(new CacheId(group.getParentId())); 3388 if (parent == null) { 3389 parent = m_userDriver.readGroup(dbc, group.getParentId()); 3390 m_groupCache.put(new CacheId(parent), parent); 3391 } 3392 return parent; 3393 } 3394 3395 3406 public CmsPermissionSetCustom getPermissions(CmsDbContext dbc, CmsResource resource, CmsUser user) 3407 throws CmsException { 3408 3409 CmsAccessControlList acList = getAccessControlList(dbc, resource, false); 3410 return acList.getPermissions(user, getGroupsOfUser(dbc, user.getName())); 3411 } 3412 3413 3418 public I_CmsProjectDriver getProjectDriver() { 3419 3420 return m_projectDriver; 3421 } 3422 3423 3444 public List getResourcesForPrincipal( 3445 CmsDbContext dbc, 3446 CmsProject project, 3447 CmsUUID principalId, 3448 CmsPermissionSet permissions, 3449 boolean includeAttr) throws CmsException { 3450 3451 List resources = m_vfsDriver.readResourcesForPrincipalACE(dbc, project, principalId); 3452 if (permissions != null) { 3453 Iterator itRes = resources.iterator(); 3454 while (itRes.hasNext()) { 3455 CmsAccessControlEntry ace = readAccessControlEntry(dbc, (CmsResource)itRes.next(), principalId); 3456 if ((ace.getPermissions().getPermissions() & permissions.getPermissions()) != permissions.getPermissions()) { 3457 itRes.remove(); 3459 } 3460 } 3461 } 3462 if (includeAttr) { 3463 resources.addAll(m_vfsDriver.readResourcesForPrincipalAttr(dbc, project, principalId)); 3464 } 3465 Set resNames = new HashSet (); 3467 Iterator itRes = resources.iterator(); 3468 while (itRes.hasNext()) { 3469 String resName = ((CmsResource)itRes.next()).getRootPath(); 3470 if (resNames.contains(resName)) { 3471 itRes.remove(); 3472 } else { 3473 resNames.add(resName); 3474 } 3475 } 3476 return resources; 3477 } 3478 3479 3484 public CmsSqlManager getSqlManager() { 3485 3486 return m_sqlManager; 3487 } 3488 3489 3500 public String getTaskPar(CmsDbContext dbc, int taskId, String parName) throws CmsException { 3501 3502 return m_workflowDriver.readTaskParameter(dbc, taskId, parName); 3503 } 3504 3505 3515 public int getTaskType(CmsDbContext dbc, String taskName) throws CmsException { 3516 3517 return m_workflowDriver.readTaskType(dbc, taskName); 3518 } 3519 3520 3525 public I_CmsUserDriver getUserDriver() { 3526 3527 return m_userDriver; 3528 } 3529 3530 3539 public List getUsers(CmsDbContext dbc) throws CmsException { 3540 3541 return m_userDriver.readUsers(dbc, CmsUser.USER_TYPE_SYSTEMUSER); 3542 } 3543 3544 3554 public List getUsers(CmsDbContext dbc, int type) throws CmsException { 3555 3556 return m_userDriver.readUsers(dbc, type); 3557 } 3558 3559 3569 public List getUsersOfGroup(CmsDbContext dbc, String groupname) throws CmsException { 3570 3571 return m_userDriver.readUsersOfGroup(dbc, groupname, CmsUser.USER_TYPE_SYSTEMUSER); 3572 } 3573 3574 3579 public I_CmsVfsDriver getVfsDriver() { 3580 3581 return m_vfsDriver; 3582 } 3583 3584 3589 public I_CmsWorkflowDriver getWorkflowDriver() { 3590 3591 return m_workflowDriver; 3592 } 3593 3594 3609 public void importAccessControlEntries(CmsDbContext dbc, CmsResource resource, List acEntries) throws CmsException { 3610 3611 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); 3612 3613 Iterator i = acEntries.iterator(); 3614 while (i.hasNext()) { 3615 m_userDriver.writeAccessControlEntry(dbc, dbc.currentProject(), (CmsAccessControlEntry)i.next()); 3616 } 3617 clearAccessControlListCache(); 3618 } 3619 3620 3640 public CmsUser importUser( 3641 CmsDbContext dbc, 3642 String id, 3643 String name, 3644 String password, 3645 String description, 3646 String firstname, 3647 String lastname, 3648 String email, 3649 String address, 3650 int flags, 3651 int type, 3652 Map additionalInfos) throws CmsException { 3653 3654 name = name.trim(); 3656 OpenCms.getValidationHandler().checkUserName(name); 3658 3659 CmsUser newUser = m_userDriver.importUser( 3660 dbc, 3661 new CmsUUID(id), 3662 name, 3663 password, 3664 description, 3665 firstname, 3666 lastname, 3667 email, 3668 0, 3669 flags, 3670 additionalInfos, 3671 address, 3672 type, 3673 null); 3674 return newUser; 3675 } 3676 3677 3691 public void init( 3692 CmsConfigurationManager configurationManager, 3693 Map configuration, 3694 I_CmsVfsDriver vfsDriver, 3695 I_CmsUserDriver userDriver, 3696 I_CmsProjectDriver projectDriver, 3697 I_CmsWorkflowDriver workflowDriver, 3698 I_CmsBackupDriver backupDriver) throws CmsException, Exception { 3699 3700 if (CmsLog.INIT.isInfoEnabled()) { 3702 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_MANAGER_START_PHASE4_0)); 3703 } 3704 3705 m_vfsDriver = vfsDriver; 3707 m_userDriver = userDriver; 3708 m_projectDriver = projectDriver; 3709 m_workflowDriver = workflowDriver; 3710 m_backupDriver = backupDriver; 3711 3712 m_configuration = configuration; 3713 3714 ExtendedProperties config; 3715 if (configuration instanceof ExtendedProperties) { 3716 config = (ExtendedProperties)configuration; 3717 } else { 3718 config = new ExtendedProperties(); 3719 config.putAll(configuration); 3720 } 3721 3722 CmsSystemConfiguration systemConfiguation = (CmsSystemConfiguration)configurationManager.getConfiguration(CmsSystemConfiguration.class); 3723 CmsCacheSettings settings = systemConfiguation.getCacheSettings(); 3724 3725 m_keyGenerator = (I_CmsCacheKey)Class.forName(settings.getCacheKeyGenerator()).newInstance(); 3727 3728 LRUMap lruMap = new LRUMap(settings.getUserCacheSize()); 3730 m_userCache = Collections.synchronizedMap(lruMap); 3731 if (OpenCms.getMemoryMonitor().enabled()) { 3732 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_userCache", lruMap); 3733 } 3734 3735 lruMap = new LRUMap(settings.getGroupCacheSize()); 3736 m_groupCache = Collections.synchronizedMap(lruMap); 3737 if (OpenCms.getMemoryMonitor().enabled()) { 3738 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_groupCache", lruMap); 3739 } 3740 3741 lruMap = new LRUMap(settings.getUserGroupsCacheSize()); 3742 m_userGroupsCache = Collections.synchronizedMap(lruMap); 3743 if (OpenCms.getMemoryMonitor().enabled()) { 3744 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_userGroupsCache", lruMap); 3745 } 3746 3747 lruMap = new LRUMap(settings.getProjectCacheSize()); 3748 m_projectCache = Collections.synchronizedMap(lruMap); 3749 if (OpenCms.getMemoryMonitor().enabled()) { 3750 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_projectCache", lruMap); 3751 } 3752 3753 lruMap = new LRUMap(settings.getResourceCacheSize()); 3754 m_resourceCache = Collections.synchronizedMap(lruMap); 3755 if (OpenCms.getMemoryMonitor().enabled()) { 3756 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_resourceCache", lruMap); 3757 } 3758 3759 lruMap = new LRUMap(settings.getResourcelistCacheSize()); 3760 m_resourceListCache = Collections.synchronizedMap(lruMap); 3761 if (OpenCms.getMemoryMonitor().enabled()) { 3762 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_resourceListCache", lruMap); 3763 } 3764 3765 lruMap = new LRUMap(settings.getPropertyCacheSize()); 3766 m_propertyCache = Collections.synchronizedMap(lruMap); 3767 if (OpenCms.getMemoryMonitor().enabled()) { 3768 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_propertyCache", lruMap); 3769 } 3770 3771 lruMap = new LRUMap(settings.getAclCacheSize()); 3772 m_accessControlListCache = Collections.synchronizedMap(lruMap); 3773 if (OpenCms.getMemoryMonitor().enabled()) { 3774 OpenCms.getMemoryMonitor().register(this.getClass().getName() + ".m_accessControlListCache", lruMap); 3775 } 3776 3777 getProjectDriver().fillDefaults(new CmsDbContext()); 3778 3779 m_htmlLinkValidator = new CmsXmlDocumentLinkValidator(this); 3781 m_concurrentCreateResourceLocks = new Vector (); 3783 } 3784 3785 3797 public boolean isInsideCurrentProject(CmsDbContext dbc, String resourcename) { 3798 3799 List projectResources = null; 3800 3801 try { 3802 projectResources = readProjectResources(dbc, dbc.currentProject()); 3803 } catch (CmsException e) { 3804 if (LOG.isErrorEnabled()) { 3805 LOG.error(Messages.get().getBundle().key( 3806 Messages.LOG_CHECK_RESOURCE_INSIDE_CURRENT_PROJECT_1, 3807 resourcename), e); 3808 } 3809 return false; 3810 } 3811 return CmsProject.isInsideProject(projectResources, resourcename); 3812 } 3813 3814 3826 public boolean isLocked(CmsDbContext dbc, CmsResource resource) throws CmsException { 3827 3828 return m_lockManager.isLocked(this, dbc, resource); 3829 } 3830 3831 3836 public boolean isTempfileProject(CmsProject project) { 3837 3838 return project.getName().equals("tempFileProject"); 3839 } 3840 3841 3850 public boolean isUser(CmsDbContext dbc) throws CmsException { 3851 3852 return userInGroup(dbc, dbc.currentUser().getName(), OpenCms.getDefaultUsers().getGroupUsers()); 3853 } 3854 3855 3870 public boolean labelResource(CmsDbContext dbc, CmsResource resource, String newResource, int action) 3871 throws CmsDataAccessException { 3872 3873 List labeledSites = OpenCms.getWorkplaceManager().getLabelSiteFolders(); 3875 3876 if (labeledSites.size() == 0) { 3877 return false; 3879 } 3880 3881 if (action == 1) { 3882 if (!resource.isLabeled()) { 3884 boolean linkInside = false; 3886 boolean sourceInside = false; 3887 for (int i = 0; i < labeledSites.size(); i++) { 3888 String curSite = (String )labeledSites.get(i); 3889 if (newResource.startsWith(curSite)) { 3890 linkInside = true; 3892 } 3893 if (resource.getRootPath().startsWith(curSite)) { 3894 sourceInside = true; 3896 } 3897 if (linkInside && sourceInside) { 3898 break; 3899 } 3900 } 3901 return (linkInside != sourceInside); 3903 } 3904 return false; 3906 3907 } else { 3908 boolean isInside = false; 3912 boolean isOutside = false; 3913 List siblings = m_vfsDriver.readSiblings(dbc, dbc.currentProject(), resource, false); 3915 updateContextDates(dbc, siblings); 3916 Iterator i = siblings.iterator(); 3917 while (i.hasNext() && (!isInside || !isOutside)) { 3918 CmsResource currentResource = (CmsResource)i.next(); 3919 if (currentResource.equals(resource)) { 3920 continue; 3922 } 3923 String curPath = currentResource.getRootPath(); 3924 boolean curInside = false; 3925 for (int k = 0; k < labeledSites.size(); k++) { 3926 if (curPath.startsWith((String )labeledSites.get(k))) { 3927 isInside = true; 3929 curInside = true; 3930 break; 3931 } 3932 } 3933 if (!curInside) { 3934 isOutside = true; 3936 } 3937 } 3938 if (newResource != null) { 3940 boolean curInside = false; 3941 for (int k = 0; k < labeledSites.size(); k++) { 3942 if (newResource.startsWith((String )labeledSites.get(k))) { 3943 isInside = true; 3945 curInside = true; 3946 break; 3947 } 3948 } 3949 if (!curInside) { 3950 isOutside = true; 3952 } 3953 } 3954 return (isInside && isOutside); 3955 } 3956 } 3957 3958 3971 public CmsUser lockedBy(CmsDbContext dbc, CmsResource resource) throws CmsException { 3972 3973 return readUser(dbc, m_lockManager.getLock(this, dbc, resource).getUserId()); 3974 } 3975 3976 3995 public void lockResource(CmsDbContext dbc, CmsResource resource, int mode) throws CmsException { 3996 3997 clearResourceCache(); 3999 4000 m_lockManager.addResource(this, dbc, resource, dbc.currentUser().getId(), dbc.currentProject().getId(), mode); 4002 4003 if ((resource.getState() != CmsResource.STATE_UNCHANGED) && (resource.getState() != CmsResource.STATE_KEEP)) { 4004 m_vfsDriver.writeLastModifiedProjectId(dbc, dbc.currentProject(), dbc.currentProject().getId(), resource); 4006 } 4007 4008 m_securityManager.clearPermissionCache(); 4010 4011 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 4013 "resource", 4014 resource))); 4015 } 4016 4017 4032 public CmsUser loginUser(CmsDbContext dbc, String userName, String password, String remoteAddress, int userType) 4033 throws CmsAuthentificationException, CmsDataAccessException, CmsPasswordEncryptionException { 4034 4035 if (CmsStringUtil.isEmptyOrWhitespaceOnly(password)) { 4036 throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_USER_1, userName)); 4037 } 4038 CmsUser newUser; 4039 try { 4040 newUser = m_userDriver.readUser(dbc, userName, password, remoteAddress, userType); 4042 } catch (CmsDbEntryNotFoundException e) { 4043 4046 boolean userExists = true; 4048 try { 4049 readUser(dbc, userName, userType); 4050 } catch (CmsDataAccessException e2) { 4051 userExists = false; 4053 } 4054 4055 if (userExists) { 4056 if (dbc.currentUser().isGuestUser()) { 4057 OpenCms.getLoginManager().addInvalidLogin(userName, userType, remoteAddress); 4059 } 4060 throw new CmsAuthentificationException(org.opencms.security.Messages.get().container( 4061 org.opencms.security.Messages.ERR_LOGIN_FAILED_3, 4062 userName, 4063 new Integer (userType), 4064 remoteAddress), e); 4065 } else { 4066 throw new CmsAuthentificationException(org.opencms.security.Messages.get().container( 4067 org.opencms.security.Messages.ERR_LOGIN_FAILED_NO_USER_3, 4068 userName, 4069 new Integer (userType), 4070 remoteAddress), e); 4071 } 4072 } 4073 if (!newUser.isEnabled()) { 4075 throw new CmsAuthentificationException(org.opencms.security.Messages.get().container( 4077 org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_3, 4078 userName, 4079 new Integer (userType), 4080 remoteAddress)); 4081 } 4082 4083 if (dbc.currentUser().isGuestUser()) { 4084 OpenCms.getLoginManager().checkInvalidLogins(userName, userType, remoteAddress); 4087 OpenCms.getLoginManager().removeInvalidLogins(userName, userType, remoteAddress); 4089 } 4090 4091 if (!m_securityManager.hasRole(dbc, newUser, CmsRole.ADMINISTRATOR)) { 4092 OpenCms.getLoginManager().checkLoginAllowed(); 4094 } 4095 4096 newUser.setLastlogin(System.currentTimeMillis()); 4098 4099 m_userDriver.writeUser(dbc, newUser); 4101 4102 putUserInCache(newUser); 4104 4105 m_accessControlListCache.clear(); 4107 m_groupCache.clear(); 4108 m_userGroupsCache.clear(); 4109 m_resourceListCache.clear(); 4110 m_securityManager.clearPermissionCache(); 4111 4112 return newUser; 4114 } 4115 4116 4124 public I_CmsPrincipal lookupPrincipal(CmsDbContext dbc, CmsUUID principalId) { 4125 4126 try { 4127 CmsGroup group = m_userDriver.readGroup(dbc, principalId); 4128 if (group != null) { 4129 return group; 4130 } 4131 } catch (Exception e) { 4132 } 4134 4135 try { 4136 CmsUser user = readUser(dbc, principalId); 4137 if (user != null) { 4138 return user; 4139 } 4140 } catch (Exception e) { 4141 } 4143 4144 return null; 4145 } 4146 4147 4155 public I_CmsPrincipal lookupPrincipal(CmsDbContext dbc, String principalName) { 4156 4157 try { 4158 CmsGroup group = m_userDriver.readGroup(dbc, principalName); 4159 if (group != null) { 4160 return group; 4161 } 4162 } catch (Exception e) { 4163 } 4165 4166 try { 4167 CmsUser user = readUser(dbc, principalName, CmsUser.USER_TYPE_SYSTEMUSER); 4168 if (user != null) { 4169 return user; 4170 } 4171 } catch (Exception e) { 4172 } 4174 4175 return null; 4176 } 4177 4178 4199 public String moveToLostAndFound(CmsDbContext dbc, String resourcename, boolean returnNameOnly) 4200 throws CmsException, CmsIllegalArgumentException { 4201 4202 CmsRequestContext context = dbc.getRequestContext(); 4203 String siteRoot = context.getSiteRoot(); 4204 Stack storage = new Stack (); 4205 context.setSiteRoot("/"); 4206 String destination = CmsDriverManager.LOST_AND_FOUND_FOLDER + resourcename; 4207 String des = destination; 4209 try { 4211 while (des.indexOf('/') == 0) { 4212 des = des.substring(0, des.lastIndexOf('/')); 4213 storage.push(des.concat("/")); 4214 } 4215 while (storage.size() != 0) { 4217 des = (String )storage.pop(); 4218 try { 4219 readFolder(dbc, des, CmsResourceFilter.IGNORE_EXPIRATION); 4220 } catch (Exception e1) { 4221 createResource(dbc, des, CmsResourceTypeFolder.RESOURCE_TYPE_ID, null, Collections.EMPTY_LIST); 4223 } 4224 } 4225 des = destination; 4228 int postfix = 1; 4229 boolean found = true; 4230 while (found) { 4231 try { 4232 found = true; 4234 readResource(dbc, des, CmsResourceFilter.ALL); 4235 String path = destination.substring(0, destination.lastIndexOf('/') + 1); 4237 String filename = destination.substring(destination.lastIndexOf('/') + 1, destination.length()); 4238 4239 des = path; 4240 4241 if (filename.lastIndexOf('.') > 0) { 4242 des += filename.substring(0, filename.lastIndexOf('.')); 4243 } else { 4244 des += filename; 4245 } 4246 des += "_" + postfix; 4247 if (filename.lastIndexOf('.') > 0) { 4248 des += filename.substring(filename.lastIndexOf('.'), filename.length()); 4249 } 4250 postfix++; 4251 } catch (CmsException e3) { 4252 found = false; 4254 } 4255 } 4256 destination = des; 4257 4258 if (!returnNameOnly) { 4259 CmsResource resource = readResource(dbc, resourcename, CmsResourceFilter.ALL); 4261 copyResource(dbc, resource, destination, CmsResource.COPY_AS_SIBLING); 4262 deleteResource(dbc, resource, CmsResource.DELETE_PRESERVE_SIBLINGS); 4263 } 4264 } catch (CmsException e2) { 4265 throw e2; 4266 } finally { 4267 context.setSiteRoot(siteRoot); 4269 } 4270 return destination; 4271 } 4272 4273 4283 public Object newDriverInstance( 4284 CmsConfigurationManager configurationManager, 4285 String driverName, 4286 List successiveDrivers) throws CmsInitException { 4287 4288 Class driverClass = null; 4289 I_CmsDriver driver = null; 4290 CmsDbContext dbc = new CmsDbContext(); 4291 4292 try { 4293 driverClass = Class.forName(driverName); 4295 if (CmsLog.INIT.isInfoEnabled()) { 4296 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_START_1, driverName)); 4297 } 4298 4299 driver = (I_CmsDriver)driverClass.newInstance(); 4301 if (CmsLog.INIT.isInfoEnabled()) { 4302 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_INITIALIZING_1, driverName)); 4303 } 4304 4305 driver.init(dbc, configurationManager, successiveDrivers, this); 4307 if (CmsLog.INIT.isInfoEnabled()) { 4308 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_INIT_FINISHED_0)); 4309 } 4310 4311 } catch (Throwable t) { 4312 CmsMessageContainer message = Messages.get().container(Messages.ERR_ERROR_INITIALIZING_DRIVER_1, driverName); 4313 if (LOG.isErrorEnabled()) { 4314 LOG.error(message.key(), t); 4315 } 4316 throw new CmsInitException(message, t); 4317 } 4318 4319 return driver; 4320 } 4321 4322 4331 public Object newDriverInstance(ExtendedProperties configuration, String driverName, String driverPoolUrl) 4332 throws CmsException { 4333 4334 Class [] initParamClasses = {ExtendedProperties.class, String .class, CmsDriverManager.class}; 4335 Object [] initParams = {configuration, driverPoolUrl, this}; 4336 4337 Class driverClass = null; 4338 Object driver = null; 4339 4340 try { 4341 driverClass = Class.forName(driverName); 4343 if (CmsLog.INIT.isInfoEnabled()) { 4344 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_START_1, driverName)); 4345 } 4346 4347 driver = driverClass.newInstance(); 4349 if (CmsLog.INIT.isInfoEnabled()) { 4350 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_INITIALIZING_1, driverName)); 4351 } 4352 4353 driver.getClass().getMethod("init", initParamClasses).invoke(driver, initParams); 4355 if (CmsLog.INIT.isInfoEnabled()) { 4356 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DRIVER_INIT_FINISHED_1, driverPoolUrl)); 4357 } 4358 4359 } catch (Exception exc) { 4360 4361 CmsMessageContainer message = Messages.get().container(Messages.ERR_INIT_DRIVER_MANAGER_1); 4362 if (LOG.isFatalEnabled()) { 4363 LOG.fatal(message.key(), exc); 4364 } 4365 throw new CmsDbException(message, exc); 4366 4367 } 4368 4369 return driver; 4370 } 4371 4372 4380 public void newPoolInstance(Map configuration, String poolName) throws CmsInitException { 4381 4382 PoolingDriver driver; 4383 4384 try { 4385 driver = CmsDbPool.createDriverManagerConnectionPool(configuration, poolName); 4386 } catch (Exception e) { 4387 4388 CmsMessageContainer message = Messages.get().container(Messages.ERR_INIT_CONN_POOL_1, poolName); 4389 if (LOG.isErrorEnabled()) { 4390 LOG.error(message.key(), e); 4391 } 4392 throw new CmsInitException(message, e); 4393 } 4394 4395 m_connectionPools.add(driver); 4396 } 4397 4398 4409 public void publishProject(CmsObject cms, CmsDbContext dbc, CmsPublishList publishList, I_CmsReport report) 4410 throws CmsException { 4411 4412 int publishProjectId = dbc.currentProject().getId(); 4413 boolean temporaryProject = (dbc.currentProject().getType() == CmsProject.PROJECT_TYPE_TEMPORARY); 4414 boolean backupEnabled = OpenCms.getSystemInfo().isVersionHistoryEnabled(); 4415 boolean directPublish = publishList.isDirectPublish(); 4416 int backupTagId = 0; 4417 4418 if (backupEnabled) { 4419 backupTagId = getBackupTagId(dbc); 4420 } else { 4421 backupTagId = 0; 4422 } 4423 4424 int maxVersions = OpenCms.getSystemInfo().getVersionHistoryMaxCount(); 4425 4426 if (directPublish) { 4428 Iterator it = publishList.getDirectPublishResources().iterator(); 4430 List parentFolderNames = new ArrayList (); 4431 while (it.hasNext()) { 4432 CmsResource res = (CmsResource)it.next(); 4433 String parentFolderName = CmsResource.getParentFolder(res.getRootPath()); 4434 if (parentFolderName != null) { 4435 parentFolderNames.add(parentFolderName); 4436 } 4437 } 4438 parentFolderNames = CmsFileUtil.removeRedundancies(parentFolderNames); 4440 String parentFolderName = null; 4441 try { 4442 Iterator parentIt = parentFolderNames.iterator(); 4444 while (parentIt.hasNext()) { 4445 parentFolderName = (String )parentIt.next(); 4446 getVfsDriver().readFolder(dbc, CmsProject.ONLINE_PROJECT_ID, parentFolderName); 4447 } 4448 } catch (CmsException e) { 4449 report.println( 4450 Messages.get().container(Messages.RPT_PARENT_FOLDER_NOT_PUBLISHED_1, parentFolderName), 4451 I_CmsReport.FORMAT_ERROR); 4452 return; 4453 } 4454 } 4455 4456 synchronized (this) { 4457 try { 4459 4460 Map eventData = new HashMap (); 4462 eventData.put(I_CmsEventListener.KEY_REPORT, report); 4463 eventData.put(I_CmsEventListener.KEY_PUBLISHLIST, publishList); 4464 eventData.put(I_CmsEventListener.KEY_PROJECTID, new Integer (publishProjectId)); 4465 eventData.put(I_CmsEventListener.KEY_DBCONTEXT, dbc); 4466 CmsEvent beforePublishEvent = new CmsEvent(I_CmsEventListener.EVENT_BEFORE_PUBLISH_PROJECT, eventData); 4467 OpenCms.fireCmsEvent(beforePublishEvent); 4468 4469 clearcache(false); 4471 4472 m_projectDriver.publishProject( 4473 dbc, 4474 report, 4475 readProject(dbc, CmsProject.ONLINE_PROJECT_ID), 4476 publishList, 4477 OpenCms.getSystemInfo().isVersionHistoryEnabled(), 4478 backupTagId, 4479 maxVersions); 4480 4481 Iterator i = OpenCms.getModuleManager().getModuleNames().iterator(); 4483 while (i.hasNext()) { 4484 CmsModule module = OpenCms.getModuleManager().getModule(i.next().toString()); 4485 if (module != null && module.getActionInstance() != null) { 4486 module.getActionInstance().publishProject(cms, publishList, backupTagId, report); 4487 } 4488 } 4489 4490 if ((temporaryProject) && (!directPublish)) { 4493 try { 4494 m_projectDriver.deleteProject(dbc, dbc.currentProject()); 4495 } catch (CmsException e) { 4496 LOG.error(Messages.get().getBundle().key( 4497 Messages.LOG_DELETE_TEMP_PROJECT_FAILED_1, 4498 new Integer (publishProjectId))); 4499 } 4500 cms.getRequestContext().setCurrentProject(readProject(dbc, CmsProject.ONLINE_PROJECT_ID)); 4502 } 4503 } finally { 4504 clearcache(false); 4506 4507 Map eventData = new HashMap (); 4509 eventData.put(I_CmsEventListener.KEY_REPORT, report); 4510 eventData.put(I_CmsEventListener.KEY_PUBLISHID, publishList.getPublishHistoryId().toString()); 4511 eventData.put(I_CmsEventListener.KEY_PROJECTID, new Integer (publishProjectId)); 4512 eventData.put(I_CmsEventListener.KEY_DBCONTEXT, dbc); 4513 CmsEvent afterPublishEvent = new CmsEvent(I_CmsEventListener.EVENT_PUBLISH_PROJECT, eventData); 4514 OpenCms.fireCmsEvent(afterPublishEvent); 4515 } 4516 } 4517 } 4518 4519 4530 public void reactivateTask(CmsDbContext dbc, int taskId) throws CmsException { 4531 4532 CmsTask task = m_workflowDriver.readTask(dbc, taskId); 4533 task.setState(CmsTaskService.TASK_STATE_STARTED); 4534 task.setPercentage(0); 4535 task = m_workflowDriver.writeTask(dbc, task); 4536 m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Task was reactivated from " 4537 + dbc.currentUser().getFirstname() 4538 + " " 4539 + dbc.currentUser().getLastname() 4540 + '.'); 4541 } 4542 4543 4554 public CmsAccessControlEntry readAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsUUID principal) 4555 throws CmsException { 4556 4557 return m_userDriver.readAccessControlEntry(dbc, dbc.currentProject(), resource.getResourceId(), principal); 4558 } 4559 4560 4570 public CmsUser readAgent(CmsDbContext dbc, CmsTask task) throws CmsException { 4571 4572 return readUser(dbc, task.getAgentUser()); 4573 } 4574 4575 4590 public List readAllBackupFileHeaders(CmsDbContext dbc, CmsResource resource) throws CmsException { 4591 4592 List backupFileHeaders = m_backupDriver.readBackupFileHeaders( 4594 dbc, 4595 resource.getRootPath(), 4596 resource.getResourceId()); 4597 4598 if (backupFileHeaders != null && backupFileHeaders.size() > 1) { 4599 Collections.reverse(backupFileHeaders); 4601 } 4602 4603 return backupFileHeaders; 4604 } 4605 4606 4615 public List readAllPropertyDefinitions(CmsDbContext dbc) throws CmsException { 4616 4617 List returnValue = m_vfsDriver.readPropertyDefinitions(dbc, dbc.currentProject().getId()); 4618 Collections.sort(returnValue); 4619 return returnValue; 4620 } 4621 4622 4633 public CmsBackupResource readBackupFile(CmsDbContext dbc, int tagId, CmsResource resource) throws CmsException { 4634 4635 return m_backupDriver.readBackupFile(dbc, tagId, resource.getRootPath()); 4636 } 4637 4638 4648 public CmsBackupProject readBackupProject(CmsDbContext dbc, int tagId) throws CmsException { 4649 4650 return m_backupDriver.readBackupProject(dbc, tagId); 4651 } 4652 4653 4663 public List readBackupPropertyObjects(CmsDbContext dbc, CmsBackupResource resource) throws CmsException { 4664 4665 return m_backupDriver.readBackupProperties(dbc, resource); 4666 } 4667 4668 4677 public List readChangedResourcesInsideProject(CmsDbContext dbc, int projectId, int resourceType) 4678 throws CmsException { 4679 4680 List projectResources = readProjectResources(dbc, readProject(dbc, projectId)); 4681 List result = new ArrayList (); 4682 String currentProjectResource = null; 4683 List resources = new ArrayList (); 4684 CmsResource currentResource = null; 4685 CmsLock currentLock = null; 4686 4687 for (int i = 0; i < projectResources.size(); i++) { 4688 currentProjectResource = (String )projectResources.get(i); 4690 4691 try { 4692 currentResource = readResource(dbc, currentProjectResource, CmsResourceFilter.ALL); 4693 4694 if (currentResource.isFolder()) { 4695 resources.addAll(readResources(dbc, currentResource, CmsResourceFilter.ALL, true)); 4696 } else { 4697 resources.add(currentResource); 4698 } 4699 } catch (CmsException e) { 4700 if (!(e instanceof CmsVfsResourceNotFoundException)) { 4702 throw e; 4703 } 4704 } 4705 } 4706 4707 for (int j = 0; j < resources.size(); j++) { 4708 currentResource = (CmsResource)resources.get(j); 4709 currentLock = getLock(dbc, currentResource); 4710 4711 if (currentResource.getState() != CmsResource.STATE_UNCHANGED) { 4712 if ((currentLock.isNullLock() && currentResource.getProjectLastModified() == projectId) 4713 || (currentLock.getUserId().equals(dbc.currentUser().getId()) && currentLock.getProjectId() == projectId)) { 4714 if ((currentResource.isFolder() && resourceType <= 0) 4719 || (currentResource.isFile() && resourceType != 0)) { 4720 result.add(currentResource); 4721 } 4722 } 4723 } 4724 } 4725 4726 resources.clear(); 4727 resources = null; 4728 4729 4731 return result; 4732 } 4733 4734 4754 public List readChildResources( 4755 CmsDbContext dbc, 4756 CmsResource resource, 4757 CmsResourceFilter filter, 4758 boolean getFolders, 4759 boolean getFiles) throws CmsException { 4760 4761 String cacheKey = getCacheKey(new String [] { 4763 dbc.currentUser().getName(), 4764 getFolders ? (getFiles ? CmsCacheKey.CACHE_KEY_SUBALL : CmsCacheKey.CACHE_KEY_SUBFOLDERS) 4765 : CmsCacheKey.CACHE_KEY_SUBFILES, 4766 filter.getCacheId(), 4767 resource.getRootPath()}, dbc.currentProject()); 4768 4769 List subResources = (List)m_resourceListCache.get(cacheKey); 4770 4771 if (subResources != null && subResources.size() > 0) { 4772 return updateContextDates(dbc, subResources, filter); 4775 } 4776 4777 subResources = m_vfsDriver.readChildResources(dbc, dbc.currentProject(), resource, getFolders, getFiles); 4779 4780 for (int i = 0; i < subResources.size(); i++) { 4781 CmsResource currentResource = (CmsResource)subResources.get(i); 4782 int perms = m_securityManager.hasPermissions( 4783 dbc, 4784 currentResource, 4785 CmsPermissionSet.ACCESS_READ, 4786 true, 4787 filter); 4788 if (CmsSecurityManager.PERM_DENIED == perms) { 4789 subResources.remove(i--); 4790 } 4791 } 4792 4793 m_resourceListCache.put(cacheKey, subResources); 4795 4796 return updateContextDates(dbc, subResources, filter); 4798 } 4799 4800 4819 public CmsFile readFile(CmsDbContext dbc, CmsResource resource, CmsResourceFilter filter) throws CmsException { 4820 4821 if (resource.isFolder()) { 4822 throw new CmsVfsResourceNotFoundException(Messages.get().container( 4823 Messages.ERR_ACCESS_FOLDER_AS_FILE_1, 4824 dbc.removeSiteRoot(resource.getRootPath()))); 4825 } 4826 4827 CmsFile file = m_vfsDriver.readFile( 4828 dbc, 4829 dbc.currentProject().getId(), 4830 filter.includeDeleted(), 4831 resource.getStructureId()); 4832 4833 return file; 4834 } 4835 4836 4852 public CmsFolder readFolder(CmsDbContext dbc, String resourcename, CmsResourceFilter filter) 4853 throws CmsDataAccessException { 4854 4855 CmsResource resource = readResource(dbc, resourcename, filter); 4856 4857 return convertResourceToFolder(resource); 4858 } 4859 4860 4883 public List readGivenTasks( 4884 CmsDbContext dbc, 4885 int projectId, 4886 String ownerName, 4887 int taskType, 4888 String orderBy, 4889 String sort) throws CmsException { 4890 4891 CmsProject project = null; 4892 4893 CmsUser owner = null; 4894 4895 if (ownerName != null) { 4896 owner = readUser(dbc, ownerName); 4897 } 4898 4899 if (projectId != CmsDbUtil.UNKNOWN_ID) { 4900 project = readProject(dbc, projectId); 4901 } 4902 4903 return m_workflowDriver.readTasks(dbc, project, null, owner, null, taskType, orderBy, sort); 4904 } 4905 4906 4914 public CmsGroup readGroup(CmsDbContext dbc, CmsProject project) { 4915 4916 CmsGroup group = (CmsGroup)m_groupCache.get(new CacheId(project.getGroupId())); 4918 if (group == null) { 4919 try { 4920 group = m_userDriver.readGroup(dbc, project.getGroupId()); 4921 } catch (CmsDataAccessException exc) { 4922 return new CmsGroup( 4923 CmsUUID.getNullUUID(), 4924 CmsUUID.getNullUUID(), 4925 project.getGroupId() + "", 4926 "deleted group", 4927 0); 4928 } 4929 m_groupCache.put(new CacheId(group), group); 4930 } 4931 4932 return group; 4933 } 4934 4935 4945 public CmsGroup readGroup(CmsDbContext dbc, CmsTask task) throws CmsException { 4946 4947 return m_userDriver.readGroup(dbc, task.getRole()); 4948 } 4949 4950 4960 public CmsGroup readGroup(CmsDbContext dbc, CmsUUID groupId) throws CmsException { 4961 4962 return m_userDriver.readGroup(dbc, groupId); 4963 } 4964 4965 4975 public CmsGroup readGroup(CmsDbContext dbc, String groupname) throws CmsDataAccessException { 4976 4977 CmsGroup group = null; 4978 group = (CmsGroup)m_groupCache.get(new CacheId(groupname)); 4980 if (group == null) { 4981 group = m_userDriver.readGroup(dbc, groupname); 4982 m_groupCache.put(new CacheId(group), group); 4983 } 4984 return group; 4985 } 4986 4987 4995 public CmsGroup readManagerGroup(CmsDbContext dbc, CmsProject project) { 4996 4997 CmsGroup group = null; 4998 group = (CmsGroup)m_groupCache.get(new CacheId(project.getManagerGroupId())); 5000 if (group == null) { 5001 try { 5002 group = m_userDriver.readGroup(dbc, project.getManagerGroupId()); 5003 } catch (CmsDataAccessException exc) { 5004 return new CmsGroup( 5006 CmsUUID.getNullUUID(), 5007 CmsUUID.getNullUUID(), 5008 project.getManagerGroupId() + "", 5009 "deleted group", 5010 0); 5011 } 5012 m_groupCache.put(new CacheId(group), group); 5013 } 5014 return group; 5015 } 5016 5017 5027 public CmsUser readOriginalAgent(CmsDbContext dbc, CmsTask task) throws CmsException { 5028 5029 return readUser(dbc, task.getOriginalUser()); 5030 } 5031 5032 5041 public CmsUser readOwner(CmsDbContext dbc, CmsProject project) throws CmsException { 5042 5043 return readUser(dbc, project.getOwnerId()); 5044 } 5045 5046 5056 public CmsUser readOwner(CmsDbContext dbc, CmsTask task) throws CmsException { 5057 5058 return readUser(dbc, task.getInitiatorUser()); 5059 } 5060 5061 5071 public CmsUser readOwner(CmsDbContext dbc, CmsTaskLog log) throws CmsException { 5072 5073 return readUser(dbc, log.getUser()); 5074 } 5075 5076 5088 public List readPath(CmsDbContext dbc, int projectId, String path, CmsResourceFilter filter) throws CmsException { 5089 5090 int folderCount = 0; 5092 boolean lastResourceIsFile = false; 5094 List pathList = null; 5096 String currentResourceName = null; 5098 CmsResource currentResource = null; 5100 int i = 0, count = 0; 5102 String cacheKey = null; 5104 5105 List tokens = CmsStringUtil.splitAsList(path, '/'); 5107 5108 count = tokens.size() + 1; 5110 pathList = new ArrayList (count); 5111 5112 folderCount = count; 5113 if (!path.endsWith("/")) { 5114 folderCount--; 5115 lastResourceIsFile = true; 5116 } 5117 5118 currentResourceName = "/"; 5120 StringBuffer currentPath = new StringBuffer (64); 5121 currentPath.append('/'); 5122 5123 String cp = currentPath.toString(); 5124 cacheKey = getCacheKey(null, false, projectId, cp); 5125 currentResource = (CmsResource)m_resourceCache.get(cacheKey); 5126 if (currentResource == null) { 5127 currentResource = m_vfsDriver.readFolder(dbc, projectId, cp); 5128 m_resourceCache.put(cacheKey, currentResource); 5129 } 5130 5131 pathList.add(0, currentResource); 5132 5133 if (count == 1) { 5134 return pathList; 5136 } 5137 5138 Iterator it = tokens.iterator(); 5139 currentResourceName = (String )it.next(); 5140 5141 for (i = 1; i < folderCount; i++) { 5143 currentPath.append(currentResourceName); 5144 currentPath.append('/'); 5145 cp = currentPath.toString(); 5147 cacheKey = getCacheKey(null, false, projectId, cp); 5148 currentResource = (CmsResource)m_resourceCache.get(cacheKey); 5149 if (currentResource == null) { 5150 currentResource = m_vfsDriver.readFolder(dbc, projectId, cp); 5151 m_resourceCache.put(cacheKey, currentResource); 5152 } 5153 5154 pathList.add(i, currentResource); 5155 5156 if (i < folderCount - 1) { 5157 currentResourceName = (String )it.next(); 5158 } 5159 } 5160 5161 if (lastResourceIsFile) { 5163 if (it.hasNext()) { 5164 currentResourceName = (String )it.next(); 5167 } 5168 currentPath.append(currentResourceName); 5169 5170 cp = currentPath.toString(); 5172 cacheKey = getCacheKey(null, false, projectId, cp); 5173 currentResource = (CmsResource)m_resourceCache.get(cacheKey); 5174 if (currentResource == null) { 5175 currentResource = m_vfsDriver.readResource(dbc, projectId, cp, filter.includeDeleted()); 5176 m_resourceCache.put(cacheKey, currentResource); 5177 } 5178 5179 pathList.add(i, currentResource); 5180 } 5181 5182 return pathList; 5183 } 5184 5185 5195 public CmsProject readProject(CmsDbContext dbc, CmsTask task) throws CmsException { 5196 5197 while (task.getParent() != 0) { 5199 task = readTask(dbc, task.getParent()); 5200 } 5201 return m_workflowDriver.readProject(dbc, task); 5202 } 5203 5204 5214 public CmsProject readProject(CmsDbContext dbc, int id) throws CmsDataAccessException { 5215 5216 CmsProject project = null; 5217 project = (CmsProject)m_projectCache.get(new Integer (id)); 5218 if (project == null) { 5219 project = m_projectDriver.readProject(dbc, id); 5220 m_projectCache.put(new Integer (id), project); 5221 } 5222 return project; 5223 } 5224 5225 5240 public CmsProject readProject(CmsDbContext dbc, String name) throws CmsException { 5241 5242 CmsProject project = null; 5243 project = (CmsProject)m_projectCache.get(name); 5244 if (project == null) { 5245 project = m_projectDriver.readProject(dbc, name); 5246 m_projectCache.put(name, project); 5247 } 5248 return project; 5249 } 5250 5251 5261 public List readProjectLogs(CmsDbContext dbc, int projectId) throws CmsException { 5262 5263 return m_workflowDriver.readProjectLogs(dbc, projectId); 5264 } 5265 5266 5277 public List readProjectResources(CmsDbContext dbc, CmsProject project) throws CmsException { 5278 5279 return m_projectDriver.readProjectResources(dbc, project); 5280 } 5281 5282 5303 public List readProjectView(CmsDbContext dbc, int projectId, int state) throws CmsException { 5304 5305 List resources; 5306 if ((state == CmsResource.STATE_NEW) 5307 || (state == CmsResource.STATE_CHANGED) 5308 || (state == CmsResource.STATE_DELETED)) { 5309 resources = m_vfsDriver.readResources(dbc, projectId, state, CmsDriverManager.READMODE_MATCHSTATE); 5311 } else { 5312 resources = m_vfsDriver.readResources( 5314 dbc, 5315 projectId, 5316 CmsResource.STATE_UNCHANGED, 5317 CmsDriverManager.READMODE_UNMATCHSTATE); 5318 } 5319 5320 List result = filterPermissions(dbc, resources, CmsResourceFilter.ALL); 5322 Collections.sort(result); 5324 return updateContextDates(dbc, result); 5326 } 5327 5328 5342 public CmsPropertyDefinition readPropertyDefinition(CmsDbContext dbc, String name) throws CmsException { 5343 5344 return m_vfsDriver.readPropertyDefinition(dbc, name, dbc.currentProject().getId()); 5345 } 5346 5347 5362 public CmsProperty readPropertyObject(CmsDbContext dbc, CmsResource resource, String key, boolean search) 5363 throws CmsException { 5364 5365 String cacheKey = getCacheKey(key, search, dbc.currentProject().getId(), resource.getRootPath()); 5367 CmsProperty value = (CmsProperty)m_propertyCache.get(cacheKey); 5368 5369 if (value == null) { 5370 String cacheKey2 = getCacheKey( 5372 CACHE_ALL_PROPERTIES, 5373 search, 5374 dbc.currentProject().getId(), 5375 resource.getRootPath()); 5376 5377 List allProperties = (List)m_propertyCache.get(cacheKey2); 5378 5379 if (allProperties != null) { 5380 for (int i = 0; i < allProperties.size(); i++) { 5382 CmsProperty property = (CmsProperty)allProperties.get(i); 5383 if (property.getName().equals(key)) { 5384 value = property; 5385 break; 5386 } 5387 } 5388 } else if (search) { 5389 String cacheKey3 = getCacheKey(key, search, dbc.currentProject().getId(), resource.getRootPath()); 5391 value = (CmsProperty)m_propertyCache.get(cacheKey3); 5392 5393 if ((value == null) || value.isNullProperty()) { 5394 boolean cont; 5395 do { 5396 try { 5397 value = readPropertyObject(dbc, resource, key, false); 5398 cont = value.isNullProperty() && (resource.getRootPath().length() > 1); 5399 } catch (CmsSecurityException se) { 5400 cont = false; 5402 } 5403 if (cont) { 5404 resource = readResource( 5407 dbc, 5408 CmsResource.getParentFolder(resource.getRootPath()), 5409 CmsResourceFilter.ALL); 5410 } 5411 } while (cont); 5412 } 5413 } else { 5414 value = m_vfsDriver.readPropertyObject(dbc, key, dbc.currentProject(), resource); 5416 } 5417 if (value == null) { 5418 value = CmsProperty.getNullProperty(); 5419 } 5420 5421 value.setFrozen(true); 5423 m_propertyCache.put(cacheKey, value); 5425 } 5426 5427 return value.cloneAsProperty(); 5429 } 5430 5431 5448 public List readPropertyObjects(CmsDbContext dbc, CmsResource resource, boolean search) throws CmsException { 5449 5450 String cacheKey = getCacheKey( 5452 CACHE_ALL_PROPERTIES, 5453 search, 5454 dbc.currentProject().getId(), 5455 resource.getRootPath()); 5456 5457 List properties = (List)m_propertyCache.get(cacheKey); 5458 5459 if (properties == null) { 5460 if (search) { 5462 boolean cont; 5463 properties = new ArrayList (); 5464 List parentProperties = null; 5465 5466 do { 5467 try { 5468 parentProperties = readPropertyObjects(dbc, resource, false); 5469 5470 parentProperties.removeAll(properties); 5472 parentProperties.addAll(properties); 5473 5474 properties.clear(); 5475 properties.addAll(parentProperties); 5476 5477 cont = resource.getRootPath().length() > 1; 5478 } catch (CmsSecurityException se) { 5479 cont = false; 5481 } 5482 if (cont) { 5483 resource = readResource( 5486 dbc, 5487 CmsResource.getParentFolder(resource.getRootPath()), 5488 CmsResourceFilter.ALL); 5489 } 5490 } while (cont); 5491 } else { 5492 properties = m_vfsDriver.readPropertyObjects(dbc, dbc.currentProject(), resource); 5493 } 5494 5495 CmsProperty.setFrozen(properties); 5497 m_propertyCache.put(cacheKey, properties); 5499 } 5500 5501 return new ArrayList (properties); 5502 } 5503 5504 5514 public List readPublishedResources(CmsDbContext dbc, CmsUUID publishHistoryId) throws CmsException { 5515 5516 return m_projectDriver.readPublishedResources(dbc, dbc.currentProject().getId(), publishHistoryId); 5517 } 5518 5519 5533 public List readPublishProjectView(CmsDbContext dbc, int projectId, String criteria) throws CmsException { 5534 5535 List retValue = new ArrayList (); 5536 List resources = m_projectDriver.readProjectView(dbc, projectId, criteria); 5537 boolean onlyLocked = false; 5538 5539 if ("locked".equalsIgnoreCase(criteria)) { 5541 onlyLocked = true; 5542 } 5543 5544 Iterator i = resources.iterator(); 5546 while (i.hasNext()) { 5547 CmsResource currentResource = (CmsResource)i.next(); 5548 if (CmsSecurityManager.PERM_ALLOWED == m_securityManager.hasPermissions( 5549 dbc, 5550 currentResource, 5551 CmsPermissionSet.ACCESS_READ, 5552 true, 5553 CmsResourceFilter.ALL)) { 5554 5555 if (onlyLocked) { 5556 CmsLock lock = getLock(dbc, currentResource); 5558 if (!lock.isNullLock()) { 5559 retValue.add(currentResource); 5560 } 5561 } else { 5562 retValue.add(currentResource); 5564 } 5565 } 5566 } 5567 5568 return retValue; 5569 5570 } 5571 5572 5587 public CmsResource readResource(CmsDbContext dbc, String resourcePath, CmsResourceFilter filter) 5588 throws CmsDataAccessException { 5589 5590 CmsResource resource = m_vfsDriver.readResource( 5591 dbc, 5592 dbc.currentProject().getId(), 5593 resourcePath, 5594 filter.includeDeleted()); 5595 5596 updateContextDates(dbc, resource); 5598 5599 return resource; 5601 } 5602 5603 5618 public List readResources(CmsDbContext dbc, CmsResource parent, CmsResourceFilter filter, boolean readTree) 5619 throws CmsException, CmsDataAccessException { 5620 5621 String cacheKey = getCacheKey(new String [] { 5623 dbc.currentUser().getName(), 5624 filter.getCacheId(), 5625 readTree ? "+" : "-", 5626 parent.getRootPath()}, dbc.currentProject()); 5627 5628 List resourceList = (List)m_resourceListCache.get(cacheKey); 5629 if (resourceList == null) { 5630 resourceList = m_vfsDriver.readResourceTree( 5632 dbc, 5633 dbc.currentProject().getId(), 5634 (readTree ? parent.getRootPath() : parent.getStructureId().toString()), 5635 filter.getType(), 5636 filter.getState(), 5637 filter.getModifiedAfter(), 5638 filter.getModifiedBefore(), 5639 filter.getReleaseAfter(), 5640 filter.getReleaseBefore(), 5641 filter.getExpireAfter(), 5642 filter.getExpireBefore(), 5643 (readTree ? CmsDriverManager.READMODE_INCLUDE_TREE : CmsDriverManager.READMODE_EXCLUDE_TREE) 5644 | (filter.excludeType() ? CmsDriverManager.READMODE_EXCLUDE_TYPE : 0) 5645 | (filter.excludeState() ? CmsDriverManager.READMODE_EXCLUDE_STATE : 0) 5646 | ((filter.getOnlyFolders() != null) ? (filter.getOnlyFolders().booleanValue() ? CmsDriverManager.READMODE_ONLY_FOLDERS 5647 : CmsDriverManager.READMODE_ONLY_FILES) 5648 : 0)); 5649 5650 resourceList = filterPermissions(dbc, resourceList, filter); 5652 m_resourceListCache.put(cacheKey, resourceList); 5654 } 5655 return updateContextDates(dbc, resourceList, filter); 5657 } 5658 5659 5673 public List readResourcesWithProperty(CmsDbContext dbc, String path, String propertyDefinition) throws CmsException { 5674 5675 String cacheKey = getCacheKey( 5676 new String [] {dbc.currentUser().getName(), path, propertyDefinition}, 5677 dbc.currentProject()); 5678 List resourceList = (List)m_resourceListCache.get(cacheKey); 5679 if (resourceList == null) { 5680 CmsPropertyDefinition propDef = readPropertyDefinition(dbc, propertyDefinition); 5682 resourceList = m_vfsDriver.readResourcesWithProperty( 5684 dbc, 5685 dbc.currentProject().getId(), 5686 propDef.getId(), 5687 path); 5688 resourceList = filterPermissions(dbc, resourceList, CmsResourceFilter.ALL); 5690 m_resourceListCache.put(cacheKey, resourceList); 5692 } 5693 return resourceList; 5694 } 5695 5696 5712 public List readResourcesWithProperty(CmsDbContext dbc, String path, String propertyDefinition, String value) 5713 throws CmsException { 5714 5715 String cacheKey = getCacheKey( 5716 new String [] {dbc.currentUser().getName(), path, propertyDefinition, value}, 5717 dbc.currentProject()); 5718 List resourceList = (List)m_resourceListCache.get(cacheKey); 5719 if (resourceList == null) { 5720 CmsPropertyDefinition propDef = readPropertyDefinition(dbc, propertyDefinition); 5722 resourceList = m_vfsDriver.readResourcesWithProperty( 5724 dbc, 5725 dbc.currentProject().getId(), 5726 propDef.getId(), 5727 path, 5728 value); 5729 resourceList = filterPermissions(dbc, resourceList, CmsResourceFilter.ALL); 5731 m_resourceListCache.put(cacheKey, resourceList); 5733 } 5734 return resourceList; 5735 } 5736 5737 5747 public Set readResponsiblePrincipals(CmsDbContext dbc, CmsResource resource) throws CmsException { 5748 5749 Set result = new HashSet (); 5750 Iterator aces = getAccessControlEntries(dbc, resource, true).iterator(); 5751 while (aces.hasNext()) { 5752 CmsAccessControlEntry ace = (CmsAccessControlEntry)aces.next(); 5753 if (ace.isResponsible()) { 5754 result.add(lookupPrincipal(dbc, ace.getPrincipal())); 5755 } 5756 } 5757 return result; 5758 } 5759 5760 5770 public Set readResponsibleUsers(CmsDbContext dbc, CmsResource resource) throws CmsException { 5771 5772 Set result = new HashSet (); 5773 Iterator principals = readResponsiblePrincipals(dbc, resource).iterator(); 5774 while (principals.hasNext()) { 5775 I_CmsPrincipal principal = (I_CmsPrincipal)principals.next(); 5776 if (principal instanceof CmsGroup) { 5777 try { 5778 result.addAll(getUsersOfGroup(dbc, principal.getName())); 5779 } catch (CmsException e) { 5780 if (LOG.isInfoEnabled()) { 5781 LOG.info(e); 5782 } 5783 } 5784 } else { 5785 result.add(principal); 5786 } 5787 } 5788 return result; 5789 } 5790 5791 5807 public List readSiblings(CmsDbContext dbc, CmsResource resource, CmsResourceFilter filter) throws CmsException { 5808 5809 List siblings = m_vfsDriver.readSiblings(dbc, dbc.currentProject(), resource, filter.includeDeleted()); 5810 5811 5816 return updateContextDates(dbc, siblings, filter); 5817 } 5818 5819 5829 public String readStaticExportPublishedResourceParameters(CmsDbContext dbc, String rfsName) throws CmsException { 5830 5831 return m_projectDriver.readStaticExportPublishedResourceParameters(dbc, dbc.currentProject(), rfsName); 5832 } 5833 5834 5845 public List readStaticExportResources(CmsDbContext dbc, int parameterResources, long timestamp) throws CmsException { 5846 5847 return m_projectDriver.readStaticExportResources(dbc, dbc.currentProject(), parameterResources, timestamp); 5848 } 5849 5850 5860 public CmsTask readTask(CmsDbContext dbc, int id) throws CmsException { 5861 5862 return m_workflowDriver.readTask(dbc, id); 5863 } 5864 5865 5875 public List readTaskLogs(CmsDbContext dbc, int taskid) throws CmsException { 5876 5877 return m_workflowDriver.readTaskLogs(dbc, taskid); 5878 } 5879 5880 5902 public List readTasksForProject(CmsDbContext dbc, int projectId, int tasktype, String orderBy, String sort) 5903 throws CmsException { 5904 5905 CmsProject project = null; 5906 5907 if (projectId != CmsDbUtil.UNKNOWN_ID) { 5908 project = readProject(dbc, projectId); 5909 } 5910 return m_workflowDriver.readTasks(dbc, project, null, null, null, tasktype, orderBy, sort); 5911 } 5912 5913 5936 public List readTasksForRole( 5937 CmsDbContext dbc, 5938 int projectId, 5939 String roleName, 5940 int tasktype, 5941 String orderBy, 5942 String sort) throws CmsException { 5943 5944 CmsProject project = null; 5945 CmsGroup role = null; 5946 5947 if (roleName != null) { 5948 role = readGroup(dbc, roleName); 5949 } 5950 5951 if (projectId != CmsDbUtil.UNKNOWN_ID) { 5952 project = readProject(dbc, projectId); 5953 } 5954 5955 return m_workflowDriver.readTasks(dbc, project, null, null, role, tasktype, orderBy, sort); 5956 } 5957 5958 5981 public List readTasksForUser( 5982 CmsDbContext dbc, 5983 int projectId, 5984 String userName, 5985 int taskType, 5986 String orderBy, 5987 String sort) throws CmsException { 5988 5989 CmsUser user = readUser(dbc, userName, CmsUser.USER_TYPE_SYSTEMUSER); 5990 CmsProject project = null; 5991 if (projectId != CmsDbUtil.UNKNOWN_ID) { 5993 project = m_projectDriver.readProject(dbc, projectId); 5994 } 5995 return m_workflowDriver.readTasks(dbc, project, user, null, null, taskType, orderBy, sort); 5996 } 5997 5998 6008 public CmsUser readUser(CmsDbContext dbc, CmsUUID id) throws CmsException { 6009 6010 CmsUser user = null; 6011 user = getUserFromCache(id); 6012 if (user == null) { 6013 user = m_userDriver.readUser(dbc, id); 6014 putUserInCache(user); 6015 } 6016 return user; 6017 } 6018 6019 6029 public CmsUser readUser(CmsDbContext dbc, String username) throws CmsDataAccessException { 6030 6031 return readUser(dbc, username, CmsUser.USER_TYPE_SYSTEMUSER); 6032 } 6033 6034 6047 public CmsUser readUser(CmsDbContext dbc, String username, int type) 6048 throws CmsDataAccessException, CmsDbSqlException, CmsDbEntryNotFoundException { 6049 6050 CmsUser user = getUserFromCache(username, type); 6051 if (user == null) { 6052 user = m_userDriver.readUser(dbc, username, type); 6053 putUserInCache(user); 6054 } 6055 return user; 6056 } 6057 6058 6071 public CmsUser readUser(CmsDbContext dbc, String username, String password) throws CmsException { 6072 6073 CmsUser user = m_userDriver.readUser(dbc, username, password, CmsUser.USER_TYPE_SYSTEMUSER); 6075 putUserInCache(user); 6076 return user; 6077 } 6078 6079 6089 public CmsUser readWebUser(CmsDbContext dbc, String username) throws CmsException { 6090 6091 return readUser(dbc, username, CmsUser.USER_TYPE_WEBUSER); 6092 } 6093 6094 6107 public CmsUser readWebUser(CmsDbContext dbc, String username, String password) throws CmsException { 6108 6109 CmsUser user = m_userDriver.readUser(dbc, username, password, CmsUser.USER_TYPE_WEBUSER); 6111 putUserInCache(user); 6112 return user; 6113 } 6114 6115 6124 public void removeAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsUUID principal) throws CmsException { 6125 6126 m_userDriver.removeAccessControlEntry(dbc, dbc.currentProject(), resource.getResourceId(), principal); 6128 6129 setDateLastModified(dbc, resource, resource.getDateLastModified()); 6131 6132 clearAccessControlListCache(); 6134 6135 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6137 "resource", 6138 resource))); 6139 } 6140 6141 6152 public void removeResourceFromProject(CmsDbContext dbc, CmsResource resource) throws CmsException { 6153 6154 if (isInsideCurrentProject(dbc, resource.getRootPath())) { 6156 if (resource.isFolder()) { 6158 List projectResources = m_projectDriver.readProjectResources(dbc, dbc.currentProject()); 6159 for (int i = 0; i < projectResources.size(); i++) { 6160 String resname = (String )projectResources.get(i); 6161 if (resname.startsWith(resource.getRootPath())) { 6162 m_projectDriver.deleteProjectResource(dbc, dbc.currentProject().getId(), resname); 6164 } 6165 } 6166 } 6167 try { 6168 m_projectDriver.deleteProjectResource(dbc, dbc.currentProject().getId(), resource.getRootPath()); 6169 } catch (CmsException exc) { 6170 } finally { 6172 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROJECT_MODIFIED, Collections.singletonMap( 6173 "project", 6174 dbc.currentProject()))); 6175 } 6176 } 6177 } 6178 6179 6191 public void removeUserFromGroup(CmsDbContext dbc, String username, String groupname) 6192 throws CmsException, CmsIllegalArgumentException, CmsDbEntryNotFoundException, CmsSecurityException { 6193 6194 if (!userInGroup(dbc, username, groupname)) { 6196 throw new CmsIllegalArgumentException(Messages.get().container( 6198 Messages.ERR_USER_NOT_IN_GROUP_2, 6199 username, 6200 groupname)); 6201 } 6202 6203 if (username.equals(OpenCms.getDefaultUsers().getUserAdmin()) 6204 && groupname.equals(OpenCms.getDefaultUsers().getGroupAdministrators())) { 6205 throw new CmsIllegalStateException(Messages.get().container( 6207 Messages.ERR_ADMIN_REMOVED_FROM_ADMINISTRATORS_0)); 6208 } 6209 CmsUser user; 6210 CmsGroup group; 6211 6212 user = readUser(dbc, username); 6213 6214 if (user != null) { 6216 group = readGroup(dbc, groupname); 6217 if (group != null) { 6219 m_userDriver.deleteUserInGroup(dbc, user.getId(), group.getId()); 6220 m_userGroupsCache.clear(); 6221 } else { 6222 throw new CmsDbEntryNotFoundException(Messages.get().container(Messages.ERR_UNKNOWN_GROUP_1, groupname)); 6223 } 6224 } else { 6225 throw new CmsIllegalArgumentException(Messages.get().container( 6226 Messages.ERR_USER_NOT_IN_GROUP_2, 6227 username, 6228 groupname)); 6229 } 6230 } 6231 6232 6246 public void replaceResource(CmsDbContext dbc, CmsResource resource, int type, byte[] content, List properties) 6247 throws CmsException { 6248 6249 m_vfsDriver.replaceResource(dbc, resource, content, type); 6251 6252 if ((properties != null) && (properties != Collections.EMPTY_LIST)) { 6253 m_vfsDriver.writePropertyObjects(dbc, dbc.currentProject(), resource, properties); 6255 m_propertyCache.clear(); 6256 } 6257 6258 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 6260 resource.setState(CmsResource.STATE_CHANGED); 6261 } 6262 resource.setUserLastModified(dbc.currentUser().getId()); 6263 6264 setDateLastModified(dbc, resource, System.currentTimeMillis()); 6265 6266 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE); 6267 6268 clearResourceCache(); 6270 content = null; 6271 6272 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6273 "resource", 6274 resource))); 6275 } 6276 6277 6288 public void resetPassword(CmsDbContext dbc, String username, String oldPassword, String newPassword) 6289 throws CmsException, CmsSecurityException { 6290 6291 if (oldPassword != null && newPassword != null) { 6292 6293 CmsUser user = null; 6294 6295 validatePassword(newPassword); 6296 6297 try { 6299 user = m_userDriver.readUser(dbc, username, oldPassword, CmsUser.USER_TYPE_SYSTEMUSER); 6300 } catch (CmsDbEntryNotFoundException e) { 6301 throw new CmsDataAccessException(Messages.get().container(Messages.ERR_RESET_PASSWORD_1, username), e); 6302 } 6303 6304 try { 6306 user = (user != null) ? user : m_userDriver.readUser( 6307 dbc, 6308 username, 6309 oldPassword, 6310 CmsUser.USER_TYPE_WEBUSER); 6311 } catch (CmsDbEntryNotFoundException e) { 6312 throw new CmsDataAccessException(Messages.get().container(Messages.ERR_RESET_PASSWORD_1, username), e); 6313 } 6314 6315 if (user == null) { 6316 throw new CmsDataAccessException(Messages.get().container(Messages.ERR_RESET_PASSWORD_1, username)); 6317 } 6318 6319 m_userDriver.writePassword(dbc, username, user.getType(), oldPassword, newPassword); 6320 6321 } else if (CmsStringUtil.isEmpty(oldPassword)) { 6322 throw new CmsDataAccessException(Messages.get().container(Messages.ERR_PWD_OLD_MISSING_0)); 6323 } else if (CmsStringUtil.isEmpty(newPassword)) { 6324 throw new CmsDataAccessException(Messages.get().container(Messages.ERR_PWD_NEW_MISSING_0)); 6325 } 6326 } 6327 6328 6340 public void restoreResource(CmsDbContext dbc, CmsResource resource, int tag) throws CmsException { 6341 6342 int state = CmsResource.STATE_CHANGED; 6343 6344 CmsBackupResource backupFile = readBackupFile(dbc, tag, resource); 6345 if (resource.getState() == CmsResource.STATE_NEW) { 6346 state = CmsResource.STATE_NEW; 6347 } 6348 6349 if (backupFile != null) { 6350 int flags = backupFile.getFlags(); 6352 if (resource.isLabeled()) { 6353 flags |= CmsResource.FLAG_LABELED; 6355 } 6356 6357 CmsFile newFile = new CmsFile( 6358 resource.getStructureId(), 6359 resource.getResourceId(), 6360 backupFile.getContentId(), 6361 resource.getRootPath(), 6362 backupFile.getTypeId(), 6363 flags, 6364 dbc.currentProject().getId(), 6365 state, 6366 resource.getDateCreated(), 6367 backupFile.getUserCreated(), 6368 resource.getDateLastModified(), 6369 dbc.currentUser().getId(), 6370 backupFile.getDateReleased(), 6371 backupFile.getDateExpired(), 6372 backupFile.getSiblingCount(), 6373 backupFile.getLength(), 6374 backupFile.getContents()); 6375 6376 writeFile(dbc, newFile); 6377 6378 List backupProperties = m_backupDriver.readBackupProperties(dbc, backupFile); 6380 deleteAllProperties(dbc, newFile.getRootPath()); 6382 writePropertyObjects(dbc, newFile, backupProperties); 6384 6385 clearResourceCache(); 6386 } 6387 6388 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6389 "resource", 6390 resource))); 6391 } 6392 6393 6405 public void setDateExpired(CmsDbContext dbc, CmsResource resource, long dateExpired) throws CmsDataAccessException { 6406 6407 resource.setDateExpired(dateExpired); 6408 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 6409 resource.setState(CmsResource.STATE_CHANGED); 6410 } 6411 resource.setUserLastModified(dbc.currentUser().getId()); 6412 6413 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_STRUCTURE); 6414 6415 clearResourceCache(); 6417 6418 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6420 "resource", 6421 resource))); 6422 } 6423 6424 6436 public void setDateLastModified(CmsDbContext dbc, CmsResource resource, long dateLastModified) 6437 throws CmsDataAccessException { 6438 6439 resource.setDateLastModified(dateLastModified); 6441 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 6442 resource.setState(CmsResource.STATE_CHANGED); 6443 } else if ((resource.getState() == CmsResource.STATE_NEW) && (resource.getSiblingCount() > 1)) { 6444 resource.setState(CmsResource.STATE_CHANGED); 6446 } 6447 resource.setUserLastModified(dbc.currentUser().getId()); 6448 6449 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE); 6450 6451 clearResourceCache(); 6453 6454 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6456 "resource", 6457 resource))); 6458 } 6459 6460 6472 public void setDateReleased(CmsDbContext dbc, CmsResource resource, long dateReleased) 6473 throws CmsDataAccessException { 6474 6475 resource.setDateReleased(dateReleased); 6477 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 6478 resource.setState(CmsResource.STATE_CHANGED); 6479 } 6480 resource.setUserLastModified(dbc.currentUser().getId()); 6481 6482 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), resource, UPDATE_STRUCTURE); 6483 6484 clearResourceCache(); 6486 6487 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6489 "resource", 6490 resource))); 6491 } 6492 6493 6504 public void setName(CmsDbContext dbc, int taskId, String name) 6505 throws CmsException, CmsDataAccessException, CmsIllegalArgumentException { 6506 6507 if ((name == null) || name.length() == 0) { 6508 throw new CmsIllegalArgumentException(org.opencms.main.Messages.get().container( 6509 org.opencms.main.Messages.ERR_ILLEGAL_ARG_2, 6510 "name", 6511 name)); 6512 } 6513 CmsTask task = m_workflowDriver.readTask(dbc, taskId); 6514 task.setName(name); 6515 task = m_workflowDriver.writeTask(dbc, task); 6516 m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Name was set to " 6517 + name 6518 + "% from " 6519 + dbc.currentUser().getFirstname() 6520 + " " 6521 + dbc.currentUser().getLastname() 6522 + '.'); 6523 } 6524 6525 6537 public void setParentGroup(CmsDbContext dbc, String groupName, String parentGroupName) 6538 throws CmsException, CmsDataAccessException { 6539 6540 CmsGroup group = readGroup(dbc, groupName); 6541 CmsUUID parentGroupId = CmsUUID.getNullUUID(); 6542 6543 if (parentGroupName != null) { 6545 parentGroupId = readGroup(dbc, parentGroupName).getId(); 6546 } 6547 6548 group.setParentId(parentGroupId); 6549 6550 writeGroup(dbc, group); 6552 } 6553 6554 6564 public void setPassword(CmsDbContext dbc, String username, String newPassword) 6565 throws CmsException, CmsIllegalArgumentException { 6566 6567 CmsUser user = null; 6568 6569 validatePassword(newPassword); 6570 6571 try { 6573 user = m_userDriver.readUser(dbc, username, CmsUser.USER_TYPE_SYSTEMUSER); 6574 } catch (CmsDbEntryNotFoundException confe) { 6575 } 6577 6578 user = (user != null) ? user : m_userDriver.readUser(dbc, username, CmsUser.USER_TYPE_WEBUSER); 6581 m_userDriver.writePassword(dbc, username, user.getType(), null, newPassword); 6582 } 6583 6584 6594 public void setPriority(CmsDbContext dbc, int taskId, int priority) throws CmsException, CmsDataAccessException { 6595 6596 CmsTask task = m_workflowDriver.readTask(dbc, taskId); 6597 task.setPriority(priority); 6598 task = m_workflowDriver.writeTask(dbc, task); 6599 m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Priority was set to " 6600 + priority 6601 + " from " 6602 + dbc.currentUser().getFirstname() 6603 + " " 6604 + dbc.currentUser().getLastname() 6605 + '.'); 6606 } 6607 6608 6618 public void setTaskPar(CmsDbContext dbc, int taskId, String parName, String parValue) throws CmsDataAccessException { 6619 6620 m_workflowDriver.writeTaskParameter(dbc, taskId, parName, parValue); 6621 } 6622 6623 6633 public void setTimeout(CmsDbContext dbc, int taskId, long timeout) throws CmsException, CmsDataAccessException { 6634 6635 CmsTask task = m_workflowDriver.readTask(dbc, taskId); 6636 java.sql.Timestamp timestamp = new java.sql.Timestamp (timeout); 6637 task.setTimeOut(timestamp); 6638 task = m_workflowDriver.writeTask(dbc, task); 6639 m_workflowDriver.writeSystemTaskLog(dbc, taskId, "Timeout was set to " 6640 + timeout 6641 + " from " 6642 + dbc.currentUser().getFirstname() 6643 + " " 6644 + dbc.currentUser().getLastname() 6645 + '.'); 6646 } 6647 6648 6660 public void undoChanges(CmsDbContext dbc, CmsResource resource) throws CmsException { 6661 6662 if (resource.getState() == CmsResource.STATE_NEW) { 6663 throw new CmsVfsException(Messages.get().container(Messages.ERR_UNDO_CHANGES_FOR_RESOURCE_NEW_0)); 6665 } 6666 6667 CmsProject onlineProject = readProject(dbc, CmsProject.ONLINE_PROJECT_ID); 6669 6670 if (resource.isFolder()) { 6672 6673 CmsFolder onlineFolder = m_vfsDriver.readFolder(dbc, CmsProject.ONLINE_PROJECT_ID, resource.getRootPath()); 6675 6676 CmsFolder restoredFolder = new CmsFolder( 6677 resource.getStructureId(), 6678 resource.getResourceId(), 6679 resource.getRootPath(), 6680 onlineFolder.getTypeId(), 6681 onlineFolder.getFlags(), 6682 dbc.currentProject().getId(), 6683 CmsResource.STATE_UNCHANGED, 6684 onlineFolder.getDateCreated(), 6685 onlineFolder.getUserCreated(), 6686 onlineFolder.getDateLastModified(), 6687 onlineFolder.getUserLastModified(), 6688 resource.getSiblingCount(), 6689 onlineFolder.getDateReleased(), 6690 onlineFolder.getDateExpired()); 6691 6692 restoredFolder.setDateLastModified(onlineFolder.getDateLastModified()); 6695 6696 m_vfsDriver.writeResource(dbc, dbc.currentProject(), restoredFolder, NOTHING_CHANGED); 6698 6699 m_vfsDriver.deletePropertyObjects( 6701 dbc, 6702 dbc.currentProject().getId(), 6703 restoredFolder, 6704 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 6705 6706 List propertyInfos = m_vfsDriver.readPropertyObjects(dbc, onlineProject, onlineFolder); 6707 m_vfsDriver.writePropertyObjects(dbc, dbc.currentProject(), restoredFolder, propertyInfos); 6708 6709 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); 6711 ListIterator aceList = m_userDriver.readAccessControlEntries( 6712 dbc, 6713 onlineProject, 6714 resource.getResourceId(), 6715 false).listIterator(); 6716 6717 while (aceList.hasNext()) { 6718 CmsAccessControlEntry ace = (CmsAccessControlEntry)aceList.next(); 6719 m_userDriver.createAccessControlEntry( 6720 dbc, 6721 dbc.currentProject(), 6722 resource.getResourceId(), 6723 ace.getPrincipal(), 6724 ace.getPermissions().getAllowedPermissions(), 6725 ace.getPermissions().getDeniedPermissions(), 6726 ace.getFlags()); 6727 } 6728 } else { 6729 6730 CmsFile onlineFile = this.m_vfsDriver.readFile( 6732 dbc, 6733 CmsProject.ONLINE_PROJECT_ID, 6734 true, 6735 resource.getStructureId()); 6736 6737 CmsFile restoredFile = new CmsFile( 6738 onlineFile.getStructureId(), 6739 onlineFile.getResourceId(), 6740 onlineFile.getContentId(), 6741 resource.getRootPath(), 6742 onlineFile.getTypeId(), 6743 onlineFile.getFlags(), 6744 dbc.currentProject().getId(), 6745 CmsResource.STATE_UNCHANGED, 6746 onlineFile.getDateCreated(), 6747 onlineFile.getUserCreated(), 6748 onlineFile.getDateLastModified(), 6749 onlineFile.getUserLastModified(), 6750 onlineFile.getDateReleased(), 6751 onlineFile.getDateExpired(), 6752 0, 6753 onlineFile.getLength(), 6754 onlineFile.getContents()); 6755 6756 restoredFile.setDateLastModified(onlineFile.getDateLastModified()); 6759 6760 List properties = m_vfsDriver.readPropertyObjects(dbc, onlineProject, onlineFile); 6762 6763 m_vfsDriver.deletePropertyObjects( 6766 dbc, 6767 dbc.currentProject().getId(), 6768 resource, 6769 CmsProperty.DELETE_OPTION_DELETE_STRUCTURE_AND_RESOURCE_VALUES); 6770 6771 deleteResource(dbc, resource, CmsResource.DELETE_PRESERVE_SIBLINGS); 6779 6780 CmsResource res = createResource( 6781 dbc, 6782 restoredFile.getRootPath(), 6783 restoredFile, 6784 restoredFile.getContents(), 6785 properties, 6786 false); 6787 6788 m_userDriver.removeAccessControlEntries(dbc, dbc.currentProject(), resource.getResourceId()); 6790 ListIterator aceList = m_userDriver.readAccessControlEntries( 6791 dbc, 6792 onlineProject, 6793 onlineFile.getResourceId(), 6794 false).listIterator(); 6795 6796 while (aceList.hasNext()) { 6797 CmsAccessControlEntry ace = (CmsAccessControlEntry)aceList.next(); 6798 m_userDriver.createAccessControlEntry( 6799 dbc, 6800 dbc.currentProject(), 6801 res.getResourceId(), 6802 ace.getPrincipal(), 6803 ace.getPermissions().getAllowedPermissions(), 6804 ace.getPermissions().getDeniedPermissions(), 6805 ace.getFlags()); 6806 } 6807 6808 res.setState(CmsResource.STATE_UNCHANGED); 6810 m_vfsDriver.writeResourceState(dbc, dbc.currentProject(), res, UPDATE_ALL); 6811 } 6812 6813 clearResourceCache(); 6815 m_propertyCache.clear(); 6816 6817 OpenCms.fireCmsEvent(new CmsEvent( 6818 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 6819 Collections.singletonMap("resource", resource))); 6820 } 6821 6822 6828 public void unlockProject(CmsProject project) throws CmsLockException { 6829 6830 if (project.getFlags() == CmsProject.PROJECT_STATE_UNLOCKED) { 6832 6833 m_lockManager.removeResourcesInProject(project.getId()); 6835 clearResourceCache(); 6836 m_projectCache.clear(); 6837 m_securityManager.clearPermissionCache(); 6839 6840 } else { 6841 throw new CmsLockException(Messages.get().container( 6842 Messages.ERR_UNLOCK_ALL_PROJECT_LOCKED_1, 6843 project.getName())); 6844 } 6845 } 6846 6847 6858 public void unlockResource(CmsDbContext dbc, CmsResource resource) throws CmsException { 6859 6860 clearResourceCache(); 6862 6863 m_lockManager.removeResource(this, dbc, resource, false); 6865 6866 m_securityManager.clearPermissionCache(); 6868 6869 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 6871 "resource", 6872 resource))); 6873 } 6874 6875 6883 public void updateExportPoints(CmsDbContext dbc, I_CmsReport report) { 6884 6885 try { 6886 Set exportPoints = new HashSet (); 6888 exportPoints.addAll(OpenCms.getExportPoints()); 6889 exportPoints.addAll(OpenCms.getModuleManager().getExportPoints()); 6890 if (exportPoints.size() == 0) { 6891 if (LOG.isWarnEnabled()) { 6892 LOG.warn(Messages.get().getBundle().key(Messages.LOG_NO_EXPORT_POINTS_CONFIGURED_0)); 6893 } 6894 return; 6895 } 6896 6897 CmsExportPointDriver exportPointDriver = new CmsExportPointDriver(exportPoints); 6899 6900 if (report == null) { 6902 if (dbc.getRequestContext() != null) { 6903 report = new CmsLogReport(dbc.getRequestContext().getLocale(), getClass()); 6904 } else { 6905 report = new CmsLogReport(CmsLocaleManager.getDefaultLocale(), getClass()); 6906 } 6907 } 6908 6909 Iterator i = exportPointDriver.getExportPointPaths().iterator(); 6911 while (i.hasNext()) { 6912 String currentExportPoint = (String )i.next(); 6913 6914 if (LOG.isInfoEnabled()) { 6916 LOG.info(Messages.get().getBundle().key(Messages.LOG_WRITE_EXPORT_POINT_1, currentExportPoint)); 6917 } 6918 6919 try { 6920 CmsResourceFilter filter = CmsResourceFilter.DEFAULT; 6921 List resources = m_vfsDriver.readResourceTree( 6922 dbc, 6923 CmsProject.ONLINE_PROJECT_ID, 6924 currentExportPoint, 6925 filter.getType(), 6926 filter.getState(), 6927 filter.getModifiedAfter(), 6928 filter.getModifiedBefore(), 6929 filter.getReleaseAfter(), 6930 filter.getReleaseBefore(), 6931 filter.getExpireAfter(), 6932 filter.getExpireBefore(), 6933 CmsDriverManager.READMODE_INCLUDE_TREE 6934 | (filter.excludeType() ? CmsDriverManager.READMODE_EXCLUDE_TYPE : 0) 6935 | (filter.excludeState() ? CmsDriverManager.READMODE_EXCLUDE_STATE : 0)); 6936 6937 Iterator j = resources.iterator(); 6938 while (j.hasNext()) { 6939 CmsResource currentResource = (CmsResource)j.next(); 6940 6941 if (currentResource.isFolder()) { 6942 exportPointDriver.createFolder(currentResource.getRootPath(), currentExportPoint); 6944 } else { 6945 exportPointDriver.createFolder(currentExportPoint, currentExportPoint); 6947 CmsFile file = getVfsDriver().readFile( 6949 dbc, 6950 CmsProject.ONLINE_PROJECT_ID, 6951 false, 6952 currentResource.getStructureId()); 6953 exportPointDriver.writeFile(file.getRootPath(), currentExportPoint, file.getContents()); 6954 } 6955 } 6956 } catch (CmsException e) { 6957 if (e instanceof CmsVfsResourceNotFoundException) { 6960 if (LOG.isErrorEnabled()) { 6961 LOG.error(Messages.get().getBundle().key(Messages.LOG_UPDATE_EXORT_POINTS_ERROR_0), e); 6962 } 6963 } 6964 } 6965 } 6966 } catch (Exception e) { 6967 if (LOG.isErrorEnabled()) { 6968 LOG.error(Messages.get().getBundle().key(Messages.LOG_UPDATE_EXORT_POINTS_ERROR_0), e); 6969 } 6970 } 6971 } 6972 6973 6984 public boolean userInGroup(CmsDbContext dbc, String username, String groupname) throws CmsException { 6985 6986 List groups = getGroupsOfUser(dbc, username); 6987 for (int i = 0; i < groups.size(); i++) { 6988 if (groupname.equals(((CmsGroup)groups.get(i)).getName())) { 6989 return true; 6990 } 6991 } 6992 return false; 6993 } 6994 6995 7010 public Map validateHtmlLinks(CmsObject cms, CmsPublishList publishList, I_CmsReport report) throws Exception { 7011 7012 return getHtmlLinkValidator().validateResources(cms, publishList.getFileList(), report); 7013 } 7014 7015 7027 public void validatePassword(String password) throws CmsSecurityException { 7028 7029 OpenCms.getPasswordHandler().validatePassword(password); 7030 } 7031 7032 7041 public void writeAccessControlEntry(CmsDbContext dbc, CmsResource resource, CmsAccessControlEntry ace) 7042 throws CmsException { 7043 7044 m_userDriver.writeAccessControlEntry(dbc, dbc.currentProject(), ace); 7046 7047 setDateLastModified(dbc, resource, resource.getDateLastModified()); 7049 7050 clearAccessControlListCache(); 7052 7053 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 7055 "resource", 7056 resource))); 7057 } 7058 7059 7069 public void writeExportPoints(CmsDbContext dbc, int projectId, I_CmsReport report, CmsUUID publishHistoryId) { 7070 7071 boolean printReportHeaders = false; 7072 try { 7073 List publishedResources = m_projectDriver.readPublishedResources(dbc, projectId, publishHistoryId); 7075 if (publishedResources.size() == 0) { 7076 if (LOG.isWarnEnabled()) { 7077 LOG.warn(Messages.get().getBundle().key(Messages.LOG_EMPTY_PUBLISH_HISTORY_1, publishHistoryId)); 7078 } 7079 return; 7080 } 7081 7082 Set exportPoints = new HashSet (); 7084 exportPoints.addAll(OpenCms.getExportPoints()); 7085 exportPoints.addAll(OpenCms.getModuleManager().getExportPoints()); 7086 if (exportPoints.size() == 0) { 7087 if (LOG.isWarnEnabled()) { 7088 LOG.warn(Messages.get().getBundle().key(Messages.LOG_NO_EXPORT_POINTS_CONFIGURED_0)); 7089 } 7090 return; 7091 } 7092 7093 CmsExportPointDriver exportPointDriver = new CmsExportPointDriver(exportPoints); 7095 7096 if (report == null) { 7098 if (dbc.getRequestContext() != null) { 7099 report = new CmsLogReport(dbc.getRequestContext().getLocale(), getClass()); 7100 } else { 7101 report = new CmsLogReport(CmsLocaleManager.getDefaultLocale(), getClass()); 7102 } 7103 } 7104 7105 Iterator i = publishedResources.iterator(); 7107 while (i.hasNext()) { 7108 CmsPublishedResource currentPublishedResource = (CmsPublishedResource)i.next(); 7109 String currentExportPoint = exportPointDriver.getExportPoint(currentPublishedResource.getRootPath()); 7110 7111 if (currentExportPoint != null) { 7112 if (!printReportHeaders) { 7113 report.println( 7114 Messages.get().container(Messages.RPT_EXPORT_POINTS_WRITE_BEGIN_0), 7115 I_CmsReport.FORMAT_HEADLINE); 7116 printReportHeaders = true; 7117 } 7118 7119 if (currentPublishedResource.isFolder()) { 7120 if (currentPublishedResource.getState() == CmsResource.STATE_DELETED) { 7122 exportPointDriver.deleteResource(currentPublishedResource.getRootPath(), currentExportPoint); 7123 } else { 7124 exportPointDriver.createFolder(currentPublishedResource.getRootPath(), currentExportPoint); 7125 } 7126 } else { 7127 if (currentPublishedResource.getState() == CmsResource.STATE_DELETED) { 7129 exportPointDriver.deleteResource(currentPublishedResource.getRootPath(), currentExportPoint); 7130 } else { 7131 CmsFile file = getVfsDriver().readFile( 7133 dbc, 7134 CmsProject.ONLINE_PROJECT_ID, 7135 false, 7136 currentPublishedResource.getStructureId()); 7137 exportPointDriver.writeFile(file.getRootPath(), currentExportPoint, file.getContents()); 7138 } 7139 } 7140 7141 if (currentPublishedResource.getState() == CmsResource.STATE_DELETED) { 7143 7144 report.print( 7145 Messages.get().container(Messages.RPT_EXPORT_POINTS_DELETE_0), 7146 I_CmsReport.FORMAT_NOTE); 7147 report.print(org.opencms.report.Messages.get().container( 7148 org.opencms.report.Messages.RPT_ARGUMENT_1, 7149 currentPublishedResource.getRootPath())); 7150 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 7151 report.println( 7152 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 7153 I_CmsReport.FORMAT_OK); 7154 } else { 7155 7156 report.print( 7157 Messages.get().container(Messages.RPT_EXPORT_POINTS_WRITE_0), 7158 I_CmsReport.FORMAT_NOTE); 7159 report.print(org.opencms.report.Messages.get().container( 7160 org.opencms.report.Messages.RPT_ARGUMENT_1, 7161 currentPublishedResource.getRootPath())); 7162 report.print(org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_DOTS_0)); 7163 report.println( 7164 org.opencms.report.Messages.get().container(org.opencms.report.Messages.RPT_OK_0), 7165 I_CmsReport.FORMAT_OK); 7166 } 7167 } 7168 } 7169 } catch (CmsException e) { 7170 if (LOG.isErrorEnabled()) { 7171 LOG.error(Messages.get().getBundle().key(Messages.LOG_WRITE_EXPORT_POINTS_ERROR_0), e); 7172 } 7173 } finally { 7174 if (printReportHeaders) { 7175 report.println( 7176 Messages.get().container(Messages.RPT_EXPORT_POINTS_WRITE_END_0), 7177 I_CmsReport.FORMAT_HEADLINE); 7178 } 7179 } 7180 } 7181 7182 7202 public CmsFile writeFile(CmsDbContext dbc, CmsFile resource) throws CmsException { 7203 7204 resource.setUserLastModified(dbc.currentUser().getId()); 7205 7206 m_vfsDriver.writeResource(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE_STATE); 7207 7208 m_vfsDriver.writeContent(dbc, dbc.currentProject(), resource.getResourceId(), resource.getContents()); 7209 7210 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 7211 resource.setState(CmsResource.STATE_CHANGED); 7212 } 7213 7214 clearResourceCache(); 7216 7217 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 7218 "resource", 7219 resource))); 7220 7221 return resource; 7222 } 7223 7224 7237 public void writeGroup(CmsDbContext dbc, CmsGroup group) throws CmsException { 7238 7239 m_groupCache.remove(new CacheId(group)); 7240 m_userDriver.writeGroup(dbc, group); 7241 m_groupCache.put(new CacheId(group), group); 7242 } 7243 7244 7257 public void writeProject(CmsDbContext dbc, CmsProject project) throws CmsException { 7258 7259 m_projectDriver.writeProject(dbc, project); 7260 m_projectCache.put(project.getName(), project); 7261 m_projectCache.put(new Integer (project.getId()), project); 7262 } 7263 7264 7276 public void writePropertyObject(CmsDbContext dbc, CmsResource resource, CmsProperty property) throws CmsException { 7277 7278 try { 7279 if (property == CmsProperty.getNullProperty()) { 7280 return; 7282 } 7283 7284 m_vfsDriver.writePropertyObject(dbc, dbc.currentProject(), resource, property); 7286 7287 resource.setUserLastModified(dbc.currentUser().getId()); 7289 m_vfsDriver.writeResource(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE_STATE); 7290 7291 } finally { 7292 clearResourceCache(); 7294 m_propertyCache.clear(); 7295 7296 Map data = new HashMap (); 7298 data.put("resource", resource); 7299 data.put("property", property); 7300 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_PROPERTY_MODIFIED, data)); 7301 } 7302 } 7303 7304 7320 public void writePropertyObjects(CmsDbContext dbc, CmsResource resource, List properties) throws CmsException { 7321 7322 if ((properties == null) || (properties.size() == 0)) { 7323 return; 7325 } 7326 7327 try { 7328 7329 for (int i = 0, n = properties.size(); i < n; i++) { 7331 Set keyValidationSet = new HashSet (); 7332 CmsProperty property = (CmsProperty)properties.get(i); 7333 if (!keyValidationSet.contains(property.getName())) { 7334 keyValidationSet.add(property.getName()); 7335 } else { 7336 throw new CmsVfsException(Messages.get().container( 7337 Messages.ERR_VFS_INVALID_PROPERTY_LIST_1, 7338 property.getName())); 7339 } 7340 } 7341 7342 for (int i = 0; i < properties.size(); i++) { 7343 CmsProperty property = (CmsProperty)properties.get(i); 7345 m_vfsDriver.writePropertyObject(dbc, dbc.currentProject(), resource, property); 7346 } 7347 } finally { 7348 clearResourceCache(); 7350 m_propertyCache.clear(); 7351 7352 OpenCms.fireCmsEvent(new CmsEvent( 7354 I_CmsEventListener.EVENT_RESOURCE_AND_PROPERTIES_MODIFIED, 7355 Collections.singletonMap("resource", resource))); 7356 } 7357 } 7358 7359 7367 public void writeResource(CmsDbContext dbc, CmsResource resource) throws CmsException { 7368 7369 resource.setUserLastModified(dbc.currentUser().getId()); 7371 7372 m_vfsDriver.writeResource(dbc, dbc.currentProject(), resource, UPDATE_RESOURCE_STATE); 7373 7374 if (resource.getState() == CmsResource.STATE_UNCHANGED) { 7376 resource.setState(CmsResource.STATE_CHANGED); 7377 } 7378 7379 clearResourceCache(); 7381 7382 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 7383 "resource", 7384 resource))); 7385 } 7386 7387 7400 public void writeStaticExportPublishedResource( 7401 CmsDbContext dbc, 7402 String resourceName, 7403 int linkType, 7404 String linkParameter, 7405 long timestamp) throws CmsException { 7406 7407 m_projectDriver.writeStaticExportPublishedResource( 7408 dbc, 7409 dbc.currentProject(), 7410 resourceName, 7411 linkType, 7412 linkParameter, 7413 timestamp); 7414 } 7415 7416 7425 public void writeTaskLog(CmsDbContext dbc, int taskid, String comment) throws CmsException { 7426 7427 m_workflowDriver.writeTaskLog(dbc, taskid, dbc.currentUser().getId(), new java.sql.Timestamp ( 7428 System.currentTimeMillis()), comment, CmsTaskService.TASKLOG_USER); 7429 } 7430 7431 7441 public void writeTaskLog(CmsDbContext dbc, int taskId, String comment, int type) throws CmsException { 7442 7443 m_workflowDriver.writeTaskLog(dbc, taskId, dbc.currentUser().getId(), new java.sql.Timestamp ( 7444 System.currentTimeMillis()), comment, type); 7445 } 7446 7447 7460 public void writeUser(CmsDbContext dbc, CmsUser user) throws CmsException { 7461 7462 clearUserCache(user); 7463 m_userDriver.writeUser(dbc, user); 7464 putUserInCache(user); 7466 } 7467 7468 7483 public void writeWebUser(CmsDbContext dbc, CmsUser user) throws CmsException { 7484 7485 clearUserCache(user); 7486 m_userDriver.writeUser(dbc, user); 7487 putUserInCache(user); 7489 } 7490 7491 7499 protected CmsFolder convertResourceToFolder(CmsResource resource) throws CmsVfsResourceNotFoundException { 7500 7501 if (resource.isFolder()) { 7502 return new CmsFolder(resource); 7503 } 7504 7505 throw new CmsVfsResourceNotFoundException(Messages.get().container( 7506 Messages.ERR_ACCESS_FILE_AS_FOLDER_1, 7507 resource.getRootPath())); 7508 } 7509 7510 7515 protected void finalize() throws Throwable { 7516 7517 try { 7518 clearcache(false); 7519 7520 try { 7521 m_projectDriver.destroy(); 7522 } catch (Throwable t) { 7523 LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_PROJECT_DRIVER_0), t); 7524 } 7525 try { 7526 m_userDriver.destroy(); 7527 } catch (Throwable t) { 7528 LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_USER_DRIVER_0), t); 7529 } 7530 try { 7531 m_vfsDriver.destroy(); 7532 } catch (Throwable t) { 7533 LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_VFS_DRIVER_0), t); 7534 } 7535 try { 7536 m_workflowDriver.destroy(); 7537 } catch (Throwable t) { 7538 LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_WORKFLOW_DRIVER_0), t); 7539 } 7540 try { 7541 m_backupDriver.destroy(); 7542 } catch (Throwable t) { 7543 LOG.error(Messages.get().getBundle().key(Messages.ERR_CLOSE_BACKUP_DRIVER_0), t); 7544 } 7545 7546 for (int i = 0; i < m_connectionPools.size(); i++) { 7547 PoolingDriver driver = (PoolingDriver)m_connectionPools.get(i); 7548 String [] pools = driver.getPoolNames(); 7549 for (int j = 0; j < pools.length; j++) { 7550 try { 7551 driver.closePool(pools[j]); 7552 if (CmsLog.INIT.isDebugEnabled()) { 7553 CmsLog.INIT.debug(Messages.get().getBundle().key(Messages.INIT_CLOSE_CONN_POOL_1, pools[j])); 7554 } 7555 } catch (Throwable t) { 7556 LOG.error(Messages.get().getBundle().key(Messages.LOG_CLOSE_CONN_POOL_ERROR_1, pools[j]), t); 7557 } 7558 } 7559 } 7560 7561 m_userCache = null; 7562 m_groupCache = null; 7563 m_userGroupsCache = null; 7564 m_projectCache = null; 7565 m_propertyCache = null; 7566 m_resourceCache = null; 7567 m_resourceListCache = null; 7568 m_accessControlListCache = null; 7569 7570 m_projectDriver = null; 7571 m_userDriver = null; 7572 m_vfsDriver = null; 7573 m_workflowDriver = null; 7574 m_backupDriver = null; 7575 7576 m_htmlLinkValidator = null; 7577 } catch (Throwable t) { 7578 } 7580 super.finalize(); 7581 } 7582 7583 7592 protected boolean isWebgroup(CmsDbContext dbc, CmsGroup group) throws CmsException { 7593 7594 CmsUUID user = m_userDriver.readGroup(dbc, OpenCms.getDefaultUsers().getGroupUsers()).getId(); 7595 CmsUUID admin = m_userDriver.readGroup(dbc, OpenCms.getDefaultUsers().getGroupAdministrators()).getId(); 7596 CmsUUID manager = m_userDriver.readGroup(dbc, OpenCms.getDefaultUsers().getGroupProjectmanagers()).getId(); 7597 7598 if ((group.getId().equals(user)) || (group.getId().equals(admin)) || (group.getId().equals(manager))) { 7599 return false; 7600 } else { 7601 if (!group.getParentId().isNullUUID()) { 7603 return isWebgroup(dbc, m_userDriver.readGroup(dbc, group.getParentId())); 7605 } 7606 } 7607 7608 return true; 7609 } 7610 7611 7620 private boolean checkParentResource(CmsDbContext dbc, List folderList, CmsResource res) { 7621 7622 String parentPath = CmsResource.getParentFolder(res.getRootPath()); 7623 CmsResource parent; 7624 7625 if (parentPath == null) { 7626 return true; 7628 } 7629 7630 try { 7631 parent = readResource(dbc, parentPath, CmsResourceFilter.ALL); 7632 } catch (Exception e) { 7633 return false; 7635 } 7636 7637 if (parent.getState() != CmsResource.STATE_NEW) { 7638 return true; 7640 } 7641 7642 for (int j = 0; j < folderList.size(); j++) { 7643 if (((CmsResource)folderList.get(j)).getStructureId().equals(parent.getStructureId())) { 7644 return true; 7646 } 7647 } 7648 7649 return false; 7651 } 7652 7653 7656 private void clearAccessControlListCache() { 7657 7658 m_accessControlListCache.clear(); 7659 m_securityManager.clearPermissionCache(); 7660 clearResourceCache(); 7661 } 7662 7663 7668 private void clearcache(boolean principalsOnly) { 7669 7670 m_userCache.clear(); 7671 m_groupCache.clear(); 7672 m_userGroupsCache.clear(); 7673 m_accessControlListCache.clear(); 7674 m_securityManager.clearPermissionCache(); 7675 7676 if (!principalsOnly) { 7677 m_projectCache.clear(); 7678 m_resourceCache.clear(); 7679 m_resourceListCache.clear(); 7680 m_propertyCache.clear(); 7681 } 7682 } 7683 7684 7687 private void clearResourceCache() { 7688 7689 m_resourceCache.clear(); 7690 m_resourceListCache.clear(); 7691 } 7692 7693 7697 private void clearUserCache(CmsUser user) { 7698 7699 removeUserFromCache(user); 7700 m_resourceListCache.clear(); 7701 } 7702 7703 7720 private CmsUser createUser( 7721 CmsDbContext dbc, 7722 String name, 7723 String password, 7724 String description, 7725 Map additionalInfos, 7726 int type) throws CmsException, CmsIllegalArgumentException { 7727 7728 name = name.trim(); 7730 OpenCms.getValidationHandler().checkUserName(name); 7732 validatePassword(password); 7734 7735 if ((name.length() > 0)) { 7736 return m_userDriver.createUser( 7737 dbc, 7738 name, 7739 password, 7740 description, 7741 " ", 7742 " ", 7743 " ", 7744 0, 7745 I_CmsPrincipal.FLAG_ENABLED, 7746 additionalInfos, 7747 " ", 7748 type); 7749 } else { 7750 throw new CmsIllegalArgumentException(Messages.get().container(Messages.ERR_BAD_USER_1, name)); 7751 } 7752 } 7753 7754 7766 private List filterPermissions(CmsDbContext dbc, List resourceList, CmsResourceFilter filter) throws CmsException { 7767 7768 if (filter.requireTimerange()) { 7769 filter = filter.addExcludeTimerange(); 7771 } 7772 ArrayList result = new ArrayList (resourceList.size()); 7773 for (int i = 0; i < resourceList.size(); i++) { 7774 CmsResource currentResource = (CmsResource)resourceList.get(i); 7776 int perms = m_securityManager.hasPermissions( 7777 dbc, 7778 currentResource, 7779 CmsPermissionSet.ACCESS_READ, 7780 true, 7781 filter); 7782 if (perms == CmsSecurityManager.PERM_ALLOWED) { 7783 result.add(currentResource); 7785 } 7786 } 7787 return result; 7789 } 7790 7791 7801 private List filterResources(CmsDbContext dbc, List folderList, List resourceList) { 7802 7803 List result = new ArrayList (); 7804 7805 List newFolderList = folderList == null ? new ArrayList () : new ArrayList (folderList); 7808 7809 for (int i = 0; i < resourceList.size(); i++) { 7810 CmsResource res = (CmsResource)resourceList.get(i); 7811 try { 7812 CmsLock lock = getLock(dbc, res); 7813 if (!lock.isNullLock()) { 7814 if (lock.getType() == CmsLock.TYPE_SHARED_INHERITED 7817 || lock.getType() == CmsLock.TYPE_SHARED_EXCLUSIVE) { 7818 if (res.getState() != CmsResource.STATE_DELETED) { 7819 continue; 7820 } 7821 } else { 7822 continue; 7824 } 7825 } 7826 7827 if (!"/".equals(res.getRootPath()) && !checkParentResource(dbc, newFolderList, res)) { 7828 continue; 7829 } 7830 7831 if (res.isFolder()) { 7832 newFolderList.add(res); 7833 } 7834 7835 result.add(res); 7836 7837 } catch (Exception e) { 7838 } 7840 } 7841 return result; 7842 } 7843 7844 7857 private List filterSiblings(CmsDbContext dbc, CmsResource currentResource, List folderList, List resourceList) { 7858 7859 List result = new ArrayList (); 7860 7861 List newFolderList = folderList == null ? new ArrayList () : new ArrayList (folderList); 7864 7865 for (int i = 0; i < resourceList.size(); i++) { 7866 CmsResource res = (CmsResource)resourceList.get(i); 7867 try { 7868 if (res.getStructureId().equals(currentResource.getStructureId())) { 7869 continue; 7873 } 7874 7875 CmsLock lock = getLock(dbc, res); 7876 if (!lock.isNullLock()) { 7877 if (lock.getType() == CmsLock.TYPE_SHARED_INHERITED 7880 || lock.getType() == CmsLock.TYPE_SHARED_EXCLUSIVE) { 7881 if (res.getState() != CmsResource.STATE_DELETED) { 7882 continue; 7883 } 7884 } else { 7885 continue; 7887 } 7888 } 7889 7890 if (!"/".equals(res.getRootPath()) && !checkParentResource(dbc, newFolderList, res)) { 7891 continue; 7893 } 7894 7895 if (res.isFolder()) { 7896 newFolderList.add(res); 7897 } 7898 7899 result.add(res); 7900 7901 } catch (Exception e) { 7902 } 7904 } 7905 return result; 7906 } 7907 7908 7921 private CmsAccessControlList getAccessControlList( 7922 CmsDbContext dbc, 7923 CmsResource resource, 7924 boolean inheritedOnly, 7925 boolean forFolder, 7926 int depth) throws CmsException { 7927 7928 String cacheKey = getCacheKey(new String [] { 7929 inheritedOnly ? "+" : "-", 7930 forFolder ? "+" : "-", 7931 Integer.toString(depth), 7932 resource.getRootPath()}, dbc.currentProject()); 7933 7934 CmsAccessControlList acl = (CmsAccessControlList)m_accessControlListCache.get(cacheKey); 7935 7936 if (acl != null) { 7938 return acl; 7939 } 7940 7941 String parentPath = CmsResource.getParentFolder(resource.getRootPath()); 7942 if (parentPath != null) { 7944 CmsResource parentResource = m_vfsDriver.readFolder(dbc, dbc.currentProject().getId(), parentPath); 7945 acl = (CmsAccessControlList)getAccessControlList(dbc, parentResource, inheritedOnly, forFolder, depth + 1).clone(); 7947 } else { 7948 acl = new CmsAccessControlList(); 7949 } 7950 7951 if (!(depth == 0 && inheritedOnly)) { 7952 7953 ListIterator ace = m_userDriver.readAccessControlEntries( 7954 dbc, 7955 dbc.currentProject(), 7956 resource.getResourceId(), 7957 depth > 1 || (depth > 0 && forFolder)).listIterator(); 7958 7959 while (ace.hasNext()) { 7960 CmsAccessControlEntry acEntry = (CmsAccessControlEntry)ace.next(); 7961 if (depth > 0) { 7962 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_INHERITED); 7963 } 7964 7965 acl.add(acEntry); 7966 7967 if ((acEntry.getFlags() & CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE) > 0) { 7970 acl.setAllowedPermissions(acEntry); 7971 } 7972 } 7973 } 7974 7975 m_accessControlListCache.put(cacheKey, acl); 7976 return acl; 7977 } 7978 7979 7988 private String getCacheKey(String prefix, boolean flag, int projectId, String resource) { 7989 7990 StringBuffer b = new StringBuffer (64); 7991 if (prefix != null) { 7992 b.append(prefix); 7993 b.append(flag ? '+' : '-'); 7994 } 7995 if (projectId >= CmsProject.ONLINE_PROJECT_ID) { 7996 b.append(CmsProject.isOnlineProject(projectId) ? '+' : '-'); 7997 } 7998 return b.append(resource).toString(); 7999 } 8000 8001 8009 private String getCacheKey(String [] keys, CmsProject project) { 8010 8011 StringBuffer b = new StringBuffer (64); 8012 int len = keys.length; 8013 if (len > 0) { 8014 for (int i = 0; i < len; i++) { 8015 b.append(keys[i]); 8016 b.append('_'); 8017 } 8018 } 8019 if (project != null) { 8020 b.append(project.isOnlineProject() ? '+' : '-'); 8021 } 8022 return b.toString(); 8023 } 8024 8025 8031 private String getUserCacheKey(CmsUUID id) { 8032 8033 return id.toString(); 8034 } 8035 8036 8043 private String getUserCacheKey(String username, int type) { 8044 8045 StringBuffer result = new StringBuffer (32); 8046 result.append(username); 8047 result.append(USER_CACHE_SEP); 8048 result.append(CmsUser.isSystemUser(type)); 8049 return result.toString(); 8050 } 8051 8052 8058 private CmsUser getUserFromCache(CmsUUID id) { 8059 8060 return (CmsUser)m_userCache.get(getUserCacheKey(id)); 8061 } 8062 8063 8070 private CmsUser getUserFromCache(String username, int type) { 8071 8072 return (CmsUser)m_userCache.get(getUserCacheKey(username, type)); 8073 } 8074 8075 8080 private void putUserInCache(CmsUser user) { 8081 8082 m_userCache.put(getUserCacheKey(user.getName(), user.getType()), user); 8083 m_userCache.put(getUserCacheKey(user.getId()), user); 8084 } 8085 8086 8091 private void removeUserFromCache(CmsUser user) { 8092 8093 m_userCache.remove(getUserCacheKey(user.getName(), user.getType())); 8094 m_userCache.remove(getUserCacheKey(user.getId())); 8095 } 8096 8097 8109 private void transferPrincipalResources( 8110 CmsDbContext dbc, 8111 CmsProject project, 8112 CmsUUID principalId, 8113 CmsUUID replacementId, 8114 boolean withACEs) throws CmsException { 8115 8116 List resources = getResourcesForPrincipal(dbc, project, principalId, null, true); 8118 Iterator it = resources.iterator(); 8119 while (it.hasNext()) { 8120 CmsResource resource = (CmsResource)it.next(); 8121 boolean attrModified = false; 8123 CmsUUID createdUser = null; 8124 if (resource.getUserCreated().equals(principalId)) { 8125 createdUser = replacementId; 8126 attrModified = true; 8127 } 8128 CmsUUID lastModUser = null; 8129 if (resource.getUserLastModified().equals(principalId)) { 8130 lastModUser = replacementId; 8131 attrModified = true; 8132 } 8133 if (attrModified) { 8134 m_vfsDriver.transferResource(dbc, project, resource, createdUser, lastModUser); 8135 clearResourceCache(); 8137 } 8138 boolean aceModified = false; 8140 if (withACEs) { 8141 Iterator itAces = m_userDriver.readAccessControlEntries(dbc, project, resource.getResourceId(), false).iterator(); 8142 while (itAces.hasNext()) { 8143 CmsAccessControlEntry ace = (CmsAccessControlEntry)itAces.next(); 8144 if (ace.getPrincipal().equals(principalId)) { 8145 CmsAccessControlEntry newAce = new CmsAccessControlEntry( 8146 ace.getResource(), 8147 replacementId, 8148 ace.getAllowedPermissions(), 8149 ace.getDeniedPermissions(), 8150 ace.getFlags()); 8151 m_userDriver.writeAccessControlEntry(dbc, project, newAce); 8153 aceModified = true; 8154 } 8155 } 8156 } 8157 if (aceModified) { 8158 clearAccessControlListCache(); 8160 } 8161 if (attrModified || aceModified) { 8162 OpenCms.fireCmsEvent(new CmsEvent(I_CmsEventListener.EVENT_RESOURCE_MODIFIED, Collections.singletonMap( 8164 "resource", 8165 resource))); 8166 } 8167 } 8168 } 8169 8170 8176 private void updateContextDates(CmsDbContext dbc, CmsResource resource) { 8177 8178 CmsFlexRequestContextInfo info = dbc.getFlexRequestContextInfo(); 8179 8180 if (info != null) { 8181 info.updateFromResource(resource); 8182 } 8183 } 8184 8185 8197 private List updateContextDates(CmsDbContext dbc, List resourceList) { 8198 8199 CmsFlexRequestContextInfo info = dbc.getFlexRequestContextInfo(); 8200 if (info != null) { 8201 for (int i = 0; i < resourceList.size(); i++) { 8202 CmsResource resource = (CmsResource)resourceList.get(i); 8203 info.updateFromResource(resource); 8204 } 8205 } 8206 return resourceList; 8207 } 8208 8209 8222 private List updateContextDates(CmsDbContext dbc, List resourceList, CmsResourceFilter filter) { 8223 8224 if (CmsResourceFilter.ALL == filter) { 8225 if (resourceList instanceof ArrayList ) { 8227 return (List)((ArrayList )(updateContextDates(dbc, resourceList))).clone(); 8229 } else { 8230 return new ArrayList (updateContextDates(dbc, resourceList)); 8231 } 8232 } 8233 8234 CmsFlexRequestContextInfo info = dbc.getFlexRequestContextInfo(); 8235 ArrayList result = new ArrayList (resourceList.size()); 8236 for (int i = 0; i < resourceList.size(); i++) { 8237 CmsResource resource = (CmsResource)resourceList.get(i); 8238 if (filter.isValid(dbc.getRequestContext(), resource)) { 8239 result.add(resource); 8240 } 8241 if (info != null) { 8244 info.updateFromResource(resource); 8245 } 8246 } 8247 return result; 8248 } 8249} | Popular Tags |