001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.file; 029 030import org.opencms.db.CmsDbEntryNotFoundException; 031import org.opencms.db.CmsPublishedResource; 032import org.opencms.db.CmsResourceState; 033import org.opencms.db.CmsSecurityManager; 034import org.opencms.db.log.CmsLogEntry; 035import org.opencms.db.log.CmsLogFilter; 036import org.opencms.db.urlname.CmsUrlNameMappingEntry; 037import org.opencms.db.urlname.CmsUrlNameMappingFilter; 038import org.opencms.file.CmsResource.CmsResourceDeleteMode; 039import org.opencms.file.history.CmsHistoryPrincipal; 040import org.opencms.file.history.CmsHistoryProject; 041import org.opencms.file.history.I_CmsHistoryResource; 042import org.opencms.file.types.I_CmsResourceType; 043import org.opencms.i18n.CmsLocaleGroupService; 044import org.opencms.lock.CmsLock; 045import org.opencms.lock.CmsLockFilter; 046import org.opencms.lock.CmsLockType; 047import org.opencms.main.CmsException; 048import org.opencms.main.CmsIllegalArgumentException; 049import org.opencms.main.I_CmsEventListener; 050import org.opencms.main.OpenCms; 051import org.opencms.relations.CmsRelation; 052import org.opencms.relations.CmsRelationFilter; 053import org.opencms.relations.CmsRelationType; 054import org.opencms.report.I_CmsReport; 055import org.opencms.security.CmsAccessControlEntry; 056import org.opencms.security.CmsAccessControlList; 057import org.opencms.security.CmsOrganizationalUnit; 058import org.opencms.security.CmsPermissionSet; 059import org.opencms.security.CmsPrincipal; 060import org.opencms.security.CmsRole; 061import org.opencms.security.CmsRoleViolationException; 062import org.opencms.security.CmsSecurityException; 063import org.opencms.security.I_CmsPermissionHandler; 064import org.opencms.security.I_CmsPrincipal; 065import org.opencms.util.CmsPair; 066import org.opencms.util.CmsStringUtil; 067import org.opencms.util.CmsUUID; 068import org.opencms.xml.content.CmsNumberSuffixNameSequence; 069 070import java.util.ArrayList; 071import java.util.Collections; 072import java.util.Iterator; 073import java.util.List; 074import java.util.Locale; 075import java.util.Map; 076import java.util.Set; 077 078/** 079 * This pivotal class provides all authorized access to the OpenCms VFS resources.<p> 080 * 081 * It encapsulates user identification and permissions. 082 * Think of it as an initialized "shell" to access the OpenCms VFS. 083 * Every call to a method here will be checked for user permissions 084 * according to the <code>{@link org.opencms.file.CmsRequestContext}</code> this CmsObject instance was created with.<p> 085 * 086 * From a JSP page running in OpenCms, use <code>{@link org.opencms.jsp.CmsJspBean#getCmsObject()}</code> to gain 087 * access to the current users CmsObject. Usually this is done with a <code>{@link org.opencms.jsp.CmsJspActionElement}</code>.<p> 088 * 089 * To generate a new instance of this class in your application, use 090 * <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>. The argument String should be 091 * the name of the guest user, usually "Guest" and more formally obtained by <code>{@link org.opencms.db.CmsDefaultUsers#getUserGuest()}</code>. 092 * This will give you an initialized context with guest user permissions. 093 * Then use <code>{@link CmsObject#loginUser(String, String)}</code> to log in the user you want. 094 * Obviously you need the password for the new user. 095 * You should never try to create an instance of this class using the constructor, 096 * this is reserved for internal operation only.<p> 097 * 098 * @since 6.0.0 099 */ 100public final class CmsObject { 101 102 /** The request context. */ 103 protected CmsRequestContext m_context; 104 105 /** The security manager to access the cms. */ 106 protected CmsSecurityManager m_securityManager; 107 108 /** 109 * Connects an OpenCms user context to a running database.<p> 110 * 111 * <b>Please note:</b> This constructor is internal to OpenCms and not for public use. 112 * If you want to create a new instance of a <code>{@link CmsObject}</code> in your application, 113 * use <code>{@link org.opencms.main.OpenCms#initCmsObject(String)}</code>.<p> 114 * 115 * @param securityManager the security manager 116 * @param context the request context that contains the user authentication 117 */ 118 public CmsObject(CmsSecurityManager securityManager, CmsRequestContext context) { 119 120 init(securityManager, context); 121 } 122 123 /** 124 * Adds a new relation to the given resource.<p> 125 * 126 * @param resource the source resource 127 * @param target the target resource 128 * @param type the type of the relation 129 * 130 * @throws CmsException if something goes wrong 131 */ 132 public void addRelationToResource(CmsResource resource, CmsResource target, String type) throws CmsException { 133 134 createRelation(resource, target, type, false); 135 } 136 137 /** 138 * Adds a new relation to the given resource.<p> 139 * 140 * @param resourceName the name of the source resource 141 * @param targetPath the path of the target resource 142 * @param type the type of the relation 143 * 144 * @throws CmsException if something goes wrong 145 */ 146 public void addRelationToResource(String resourceName, String targetPath, String type) throws CmsException { 147 148 createRelation(resourceName, targetPath, type, false); 149 } 150 151 /** 152 * Convenience method to add the site root from the current user's 153 * request context to the given resource name.<p> 154 * 155 * @param resourcename the resource name 156 * 157 * @return the resource name with the site root added 158 * 159 * @see CmsRequestContext#addSiteRoot(String) 160 */ 161 public String addSiteRoot(String resourcename) { 162 163 return m_context.addSiteRoot(resourcename); 164 } 165 166 /** 167 * Adds a user to a group.<p> 168 * 169 * @param username the name of the user that is to be added to the group 170 * @param groupname the name of the group 171 * 172 * @throws CmsException if something goes wrong 173 */ 174 public void addUserToGroup(String username, String groupname) throws CmsException { 175 176 m_securityManager.addUserToGroup(m_context, username, groupname, false); 177 } 178 179 /** 180 * This method works just like {@link CmsObject#adjustLinks(String, String)}, but you can specify multiple source 181 * files, and the target folder is interpreted as the folder into which the source files have been copied.<p> 182 * 183 * @param sourceFiles the list of source files 184 * @param targetParentFolder the folder into which the source files have been copied 185 * 186 * @throws CmsException if something goes wrong 187 */ 188 public void adjustLinks(List<String> sourceFiles, String targetParentFolder) throws CmsException { 189 190 CmsObject cms = OpenCms.initCmsObject(this); 191 cms.getRequestContext().setSiteRoot(""); 192 List<String> rootSourceFiles = new ArrayList<String>(); 193 for (String sourceFile : sourceFiles) { 194 rootSourceFiles.add(addSiteRoot(sourceFile)); 195 } 196 String rootTargetParentFolder = addSiteRoot(targetParentFolder); 197 198 CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootSourceFiles, rootTargetParentFolder); 199 rewriter.rewriteLinks(); 200 } 201 202 /** 203 * This method works just like {@link CmsObject#adjustLinks(String, String)}, but instead of specifying 204 * a single source and target folder, you can specify multiple sources and the corresponding targets in 205 * a map of strings. 206 * 207 * @param sourceTargetMap a map with the source files as keys and the corresponding targets as values 208 * @param targetParentFolder the folder into which the source files have been copied 209 * 210 * @throws CmsException if something goes wrong 211 */ 212 public void adjustLinks(Map<String, String> sourceTargetMap, String targetParentFolder) throws CmsException { 213 214 CmsObject cms = OpenCms.initCmsObject(this); 215 cms.getRequestContext().setSiteRoot(""); 216 List<CmsPair<String, String>> sourcesAndTargets = new ArrayList<CmsPair<String, String>>(); 217 for (Map.Entry<String, String> entry : sourceTargetMap.entrySet()) { 218 String rootSource = addSiteRoot(entry.getKey()); 219 String rootTarget = addSiteRoot(entry.getValue()); 220 sourcesAndTargets.add(CmsPair.create(rootSource, rootTarget)); 221 } 222 String rootTargetParentFolder = addSiteRoot(targetParentFolder); 223 CmsLinkRewriter rewriter = new CmsLinkRewriter(cms, rootTargetParentFolder, sourcesAndTargets); 224 rewriter.rewriteLinks(); 225 } 226 227 /** 228 * Adjusts all links in the target folder that point to the source folder 229 * so that they are kept "relative" in the target folder where possible. 230 * 231 * If a link is found from the target folder to the source folder, 232 * then the target folder is checked if a target of the same name 233 * is found also "relative" inside the target Folder, and if so, 234 * the link is changed to that "relative" target. This is mainly used to keep 235 * relative links inside a copied folder structure intact. 236 * 237 * Example: Image we have folder /folderA/ that contains files 238 * /folderA/x1 and /folderA/y1. x1 has a link to y1 and y1 to x1. 239 * Now someone copies /folderA/ to /folderB/. So we end up with 240 * /folderB/x2 and /folderB/y2. Because of the link mechanism in OpenCms, 241 * x2 will have a link to y1 and y2 to x1. By using this method, 242 * the links from x2 to y1 will be replaced by a link x2 to y2, 243 * and y2 to x1 with y2 to x2. 244 * 245 * Link replacement works for links in XML files as well as relation only 246 * type links. 247 * 248 * @param sourceFolder the source folder 249 * @param targetFolder the target folder 250 * 251 * @throws CmsException if something goes wrong 252 */ 253 public void adjustLinks(String sourceFolder, String targetFolder) throws CmsException { 254 255 String rootSourceFolder = addSiteRoot(sourceFolder); 256 String rootTargetFolder = addSiteRoot(targetFolder); 257 String siteRoot = getRequestContext().getSiteRoot(); 258 getRequestContext().setSiteRoot(""); 259 try { 260 CmsLinkRewriter linkRewriter = new CmsLinkRewriter(this, rootSourceFolder, rootTargetFolder); 261 linkRewriter.rewriteLinks(); 262 } finally { 263 getRequestContext().setSiteRoot(siteRoot); 264 } 265 } 266 267 /** 268 * Changes the access control for a given resource and a given principal(user/group).<p> 269 * 270 * @param resourceName name of the resource 271 * @param principalType the type of the principal (currently group or user): 272 * <ul> 273 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li> 274 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li> 275 * </ul> 276 * @param principalName name of the principal 277 * @param allowedPermissions bit set of allowed permissions 278 * @param deniedPermissions bit set of denied permissions 279 * @param flags additional flags of the access control entry 280 * 281 * @throws CmsException if something goes wrong 282 */ 283 public void chacc( 284 String resourceName, 285 String principalType, 286 String principalName, 287 int allowedPermissions, 288 int deniedPermissions, 289 int flags) 290 throws CmsException { 291 292 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 293 294 CmsAccessControlEntry acEntry = null; 295 try { 296 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 297 acEntry = new CmsAccessControlEntry( 298 res.getResourceId(), 299 principal.getId(), 300 allowedPermissions, 301 deniedPermissions, 302 flags); 303 acEntry.setFlagsForPrincipal(principal); 304 } catch (CmsDbEntryNotFoundException e) { 305 // check for special ids 306 if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) { 307 acEntry = new CmsAccessControlEntry( 308 res.getResourceId(), 309 CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID, 310 allowedPermissions, 311 deniedPermissions, 312 flags); 313 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS); 314 } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) { 315 acEntry = new CmsAccessControlEntry( 316 res.getResourceId(), 317 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID, 318 allowedPermissions, 319 deniedPermissions, 320 flags); 321 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL); 322 } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) { 323 // only vfs managers can set role based permissions 324 m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res); 325 // check for role 326 CmsRole role = CmsRole.valueOfRoleName(principalName); 327 // role based permissions can only be set in the system folder 328 if (role == null) { 329 throw e; 330 } 331 acEntry = new CmsAccessControlEntry( 332 res.getResourceId(), 333 role.getId(), 334 allowedPermissions, 335 deniedPermissions, 336 flags); 337 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE); 338 } else { 339 throw e; 340 } 341 } 342 343 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 344 } 345 346 /** 347 * Changes the access control for a given resource and a given principal(user/group).<p> 348 * 349 * @param resourceName name of the resource 350 * @param principalType the type of the principal (group or user): 351 * <ul> 352 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_USER}</code></li> 353 * <li><code>{@link I_CmsPrincipal#PRINCIPAL_GROUP}</code></li> 354 * </ul> 355 * @param principalName name of the principal 356 * @param permissionString the permissions in the format ((+|-)(r|w|v|c|i|o))* 357 * 358 * @throws CmsException if something goes wrong 359 */ 360 public void chacc(String resourceName, String principalType, String principalName, String permissionString) 361 throws CmsException { 362 363 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 364 365 CmsAccessControlEntry acEntry = null; 366 try { 367 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 368 acEntry = new CmsAccessControlEntry(res.getResourceId(), principal.getId(), permissionString); 369 acEntry.setFlagsForPrincipal(principal); 370 } catch (CmsDbEntryNotFoundException e) { 371 // check for special ids 372 if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME)) { 373 acEntry = new CmsAccessControlEntry( 374 res.getResourceId(), 375 CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID, 376 permissionString); 377 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ALLOTHERS); 378 } else if (principalName.equalsIgnoreCase(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME)) { 379 acEntry = new CmsAccessControlEntry( 380 res.getResourceId(), 381 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID, 382 permissionString); 383 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE_ALL); 384 } else if (principalType.equalsIgnoreCase(CmsRole.PRINCIPAL_ROLE)) { 385 // only vfs managers can set role based permissions 386 m_securityManager.checkRoleForResource(m_context, CmsRole.VFS_MANAGER, res); 387 // check for role 388 CmsRole role = CmsRole.valueOfRoleName(principalName); 389 // role based permissions can only be set in the system folder 390 if (role == null) { 391 throw e; 392 } 393 acEntry = new CmsAccessControlEntry(res.getResourceId(), role.getId(), permissionString); 394 acEntry.setFlags(CmsAccessControlEntry.ACCESS_FLAGS_ROLE); 395 } else { 396 throw e; 397 } 398 } 399 400 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 401 } 402 403 /** 404 * Changes the lock of a resource to the current user, 405 * that is "steals" the lock from another user.<p> 406 * 407 * This is the "steal lock" operation.<p> 408 * 409 * @param resource the resource to change the lock 410 * 411 * @throws CmsException if something goes wrong 412 */ 413 public void changeLock(CmsResource resource) throws CmsException { 414 415 getResourceType(resource).changeLock(this, m_securityManager, resource); 416 } 417 418 /** 419 * Changes the lock of a resource to the current user, 420 * that is "steals" the lock from another user.<p> 421 * 422 * This is the "steal lock" operation.<p> 423 * 424 * @param resourcename the name of the resource to change the lock with complete path 425 * 426 * @throws CmsException if something goes wrong 427 */ 428 public void changeLock(String resourcename) throws CmsException { 429 430 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 431 changeLock(resource); 432 } 433 434 /** 435 * Returns a list with all sub resources of a given folder that have set the given property, 436 * matching the current property's value with the given old value and replacing it by a given new value.<p> 437 * 438 * @param resourcename the name of the resource to change the property value 439 * @param property the name of the property to change the value 440 * @param oldValue the old value of the property, can be a regular expression 441 * @param newValue the new value of the property 442 * @param recursive if true, change recursively all property values on sub-resources (only for folders) 443 * 444 * @return a list with the <code>{@link CmsResource}</code>'s where the property value has been changed 445 * 446 * @throws CmsException if operation was not successful 447 */ 448 public List<CmsResource> changeResourcesInFolderWithProperty( 449 String resourcename, 450 String property, 451 String oldValue, 452 String newValue, 453 boolean recursive) 454 throws CmsException { 455 456 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 457 return m_securityManager.changeResourcesInFolderWithProperty( 458 m_context, 459 resource, 460 property, 461 oldValue, 462 newValue, 463 recursive); 464 } 465 466 /** 467 * Changes the resource flags of a resource.<p> 468 * 469 * The resource flags are used to indicate various "special" conditions 470 * for a resource. Most notably, the "internal only" setting which signals 471 * that a resource can not be directly requested with it's URL.<p> 472 * 473 * @param resourcename the name of the resource to change the flags for (full current site relative path) 474 * @param flags the new flags for this resource 475 * 476 * @throws CmsException if something goes wrong 477 */ 478 public void chflags(String resourcename, int flags) throws CmsException { 479 480 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 481 getResourceType(resource).chflags(this, m_securityManager, resource, flags); 482 } 483 484 /** 485 * Changes the resource type of a resource.<p> 486 * 487 * OpenCms handles resources according to the resource type, 488 * not the file suffix. This is e.g. why a JSP in OpenCms can have the 489 * suffix ".html" instead of ".jsp" only. Changing the resource type 490 * makes sense e.g. if you want to make a plain text file a JSP resource, 491 * or a binary file an image, etc.<p> 492 * 493 * @param resource the resource whose type should be changed 494 * @param type the new resource type for this resource 495 * 496 * @throws CmsException if something goes wrong 497 */ 498 public void chtype(CmsResource resource, I_CmsResourceType type) throws CmsException { 499 500 getResourceType(resource).chtype(this, m_securityManager, resource, type); 501 } 502 503 /** 504 * Changes the resource type of a resource.<p> 505 * 506 * OpenCms handles resources according to the resource type, 507 * not the file suffix. This is e.g. why a JSP in OpenCms can have the 508 * suffix ".html" instead of ".jsp" only. Changing the resource type 509 * makes sense e.g. if you want to make a plain text file a JSP resource, 510 * or a binary file an image, etc.<p> 511 * 512 * @param resourcename the name of the resource to change the type for (full current site relative path) 513 * @param type the new resource type for this resource 514 * 515 * @throws CmsException if something goes wrong 516 */ 517 public void chtype(String resourcename, I_CmsResourceType type) throws CmsException { 518 519 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 520 getResourceType(resource).chtype(this, m_securityManager, resource, type); 521 } 522 523 /** 524 * Changes the resource type of a resource.<p> 525 * 526 * OpenCms handles resources according to the resource type, 527 * not the file suffix. This is e.g. why a JSP in OpenCms can have the 528 * suffix ".html" instead of ".jsp" only. Changing the resource type 529 * makes sense e.g. if you want to make a plain text file a JSP resource, 530 * or a binary file an image, etc.<p> 531 * 532 * @param resourcename the name of the resource to change the type for (full current site relative path) 533 * @param type the new resource type for this resource 534 * 535 * @throws CmsException if something goes wrong 536 * 537 * @deprecated 538 * Use {@link #chtype(String, I_CmsResourceType)} instead. 539 * Resource types should always be referenced either by its type class (preferred) or by type name. 540 * Use of int based resource type references will be discontinued in a future OpenCms release. 541 */ 542 @Deprecated 543 public void chtype(String resourcename, int type) throws CmsException { 544 545 chtype(resourcename, getResourceType(type)); 546 } 547 548 /** 549 * Copies a resource.<p> 550 * 551 * The copied resource will always be locked to the current user 552 * after the copy operation.<p> 553 * 554 * Siblings will be treated according to the 555 * <code>{@link org.opencms.file.CmsResource#COPY_PRESERVE_SIBLING}</code> mode.<p> 556 * 557 * @param source the name of the resource to copy (full current site relative path) 558 * @param destination the name of the copy destination (full current site relative path) 559 * 560 * @throws CmsException if something goes wrong 561 * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0 562 * 563 * @see #copyResource(String, String, CmsResource.CmsResourceCopyMode) 564 */ 565 public void copyResource(String source, String destination) throws CmsException, CmsIllegalArgumentException { 566 567 copyResource(source, destination, CmsResource.COPY_PRESERVE_SIBLING); 568 } 569 570 /** 571 * Copies a resource.<p> 572 * 573 * The copied resource will always be locked to the current user 574 * after the copy operation.<p> 575 * 576 * The <code>siblingMode</code> parameter controls how to handle siblings 577 * during the copy operation.<br> 578 * Possible values for this parameter are: <br> 579 * <ul> 580 * <li><code>{@link CmsResource#COPY_AS_NEW}</code></li> 581 * <li><code>{@link CmsResource#COPY_AS_SIBLING}</code></li> 582 * <li><code>{@link CmsResource#COPY_PRESERVE_SIBLING}</code></li> 583 * </ul><p> 584 * 585 * @param source the name of the resource to copy (full current site relative path) 586 * @param destination the name of the copy destination (full current site relative path) 587 * @param siblingMode indicates how to handle siblings during copy 588 * 589 * @throws CmsException if something goes wrong 590 * @throws CmsIllegalArgumentException if the <code>destination</code> argument is null or of length 0 591 */ 592 public void copyResource(String source, String destination, CmsResource.CmsResourceCopyMode siblingMode) 593 throws CmsException, CmsIllegalArgumentException { 594 595 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 596 getResourceType(resource).copyResource(this, m_securityManager, resource, destination, siblingMode); 597 } 598 599 /** 600 * Copies a resource to the current project of the user.<p> 601 * 602 * This is used to extend the current users project with the 603 * specified resource, in case that the resource is not yet part of the project. 604 * The resource is not really copied like in a regular copy operation, 605 * it is in fact only "enabled" in the current users project.<p> 606 * 607 * @param resource the resource to copy to the current project 608 * 609 * @throws CmsException if something goes wrong 610 */ 611 public void copyResourceToProject(CmsResource resource) throws CmsException { 612 613 getResourceType(resource).copyResourceToProject(this, m_securityManager, resource); 614 } 615 616 /** 617 * Copies a resource to the current project of the user.<p> 618 * 619 * This is used to extend the current users project with the 620 * specified resource, in case that the resource is not yet part of the project. 621 * The resource is not really copied like in a regular copy operation, 622 * it is in fact only "enabled" in the current users project.<p> 623 * 624 * @param resourcename the name of the resource to copy to the current project (full current site relative path) 625 * 626 * @throws CmsException if something goes wrong 627 */ 628 public void copyResourceToProject(String resourcename) throws CmsException { 629 630 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 631 copyResourceToProject(resource); 632 } 633 634 /** 635 * Counts the locked resources in a project.<p> 636 * 637 * @param id the id of the project 638 * 639 * @return the number of locked resources in this project 640 * 641 * @throws CmsException if operation was not successful 642 */ 643 public int countLockedResources(CmsUUID id) throws CmsException { 644 645 return m_securityManager.countLockedResources(m_context, id); 646 } 647 648 /** 649 * Copies access control entries of a given resource to another resource.<p> 650 * 651 * Already existing access control entries of the destination resource are removed.<p> 652 * 653 * @param sourceName the name of the resource of which the access control entries are copied 654 * @param destName the name of the resource to which the access control entries are applied 655 * 656 * @throws CmsException if something goes wrong 657 */ 658 public void cpacc(String sourceName, String destName) throws CmsException { 659 660 CmsResource source = readResource(sourceName); 661 CmsResource dest = readResource(destName); 662 m_securityManager.copyAccessControlEntries(m_context, source, dest); 663 } 664 665 /** 666 * Creates a new user group.<p> 667 * 668 * @param groupFqn the name of the new group 669 * @param description the description of the new group 670 * @param flags the flags for the new group 671 * @param parent the parent group (or <code>null</code>) 672 * 673 * @return a <code>{@link CmsGroup}</code> object representing the newly created group 674 * 675 * @throws CmsException if operation was not successful 676 */ 677 public CmsGroup createGroup(String groupFqn, String description, int flags, String parent) throws CmsException { 678 679 return m_securityManager.createGroup(m_context, groupFqn, description, flags, parent); 680 } 681 682 /** 683 * Creates a new project.<p> 684 * 685 * @param name the name of the project to create 686 * @param description the description for the new project 687 * @param groupname the name of the project user group 688 * @param managergroupname the name of the project manager group 689 * 690 * @return the created project 691 * 692 * @throws CmsException if something goes wrong 693 */ 694 public CmsProject createProject(String name, String description, String groupname, String managergroupname) 695 throws CmsException { 696 697 return m_securityManager.createProject( 698 m_context, 699 name, 700 description, 701 groupname, 702 managergroupname, 703 CmsProject.PROJECT_TYPE_NORMAL); 704 } 705 706 /** 707 * Creates a new project.<p> 708 * 709 * @param name the name of the project to create 710 * @param description the description for the new project 711 * @param groupname the name of the project user group 712 * @param managergroupname the name of the project manager group 713 * @param projecttype the type of the project (normal or temporary) 714 * 715 * @return the created project 716 * 717 * @throws CmsException if operation was not successful 718 */ 719 public CmsProject createProject( 720 String name, 721 String description, 722 String groupname, 723 String managergroupname, 724 CmsProject.CmsProjectType projecttype) 725 throws CmsException { 726 727 return m_securityManager.createProject(m_context, name, description, groupname, managergroupname, projecttype); 728 } 729 730 /** 731 * Creates a property definition.<p> 732 * 733 * Property definitions are valid for all resource types.<p> 734 * 735 * @param name the name of the property definition to create 736 * 737 * @return the created property definition 738 * 739 * @throws CmsException if something goes wrong 740 */ 741 public CmsPropertyDefinition createPropertyDefinition(String name) throws CmsException { 742 743 return (m_securityManager.createPropertyDefinition(m_context, name)); 744 } 745 746 /** 747 * Creates a resource with the given properties and content. 748 * Will throw an exception, if a resource with the given name already exists.<p> 749 * 750 * @param sitePath the site path for the resource 751 * @param resource the resource object to be imported 752 * @param content the content of the resource 753 * @param properties the properties of the resource 754 * 755 * @return the imported resource 756 * 757 * @throws CmsException if something goes wrong 758 */ 759 public CmsResource createResource( 760 String sitePath, 761 CmsResource resource, 762 byte[] content, 763 List<CmsProperty> properties) 764 throws CmsException { 765 766 resource.setUserLastModified(getRequestContext().getCurrentUser().getId()); 767 resource.setDateLastModified(System.currentTimeMillis()); 768 // ensure resource record is updated 769 resource.setState(CmsResource.STATE_NEW); 770 return m_securityManager.createResource( 771 m_context, 772 m_context.addSiteRoot(sitePath), 773 resource, 774 content, 775 properties); 776 } 777 778 /** 779 * Creates a new resource of the given resource type with 780 * empty content and no properties.<p> 781 * 782 * @param resourcename the name of the resource to create (full current site relative path) 783 * @param type the type of the resource to create 784 * 785 * @return the created resource 786 * 787 * @throws CmsException if something goes wrong 788 * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0 789 * 790 * @see #createResource(String, int, byte[], List) 791 */ 792 public CmsResource createResource(String resourcename, I_CmsResourceType type) 793 throws CmsException, CmsIllegalArgumentException { 794 795 return createResource(resourcename, type, new byte[0], new ArrayList<CmsProperty>(0)); 796 } 797 798 /** 799 * Creates a new resource of the given resource type 800 * with the provided content and properties.<p> 801 * 802 * @param resourcename the name of the resource to create (full current site relative path) 803 * @param type the type of the resource to create 804 * @param content the contents for the new resource 805 * @param properties the properties for the new resource 806 * 807 * @return the created resource 808 * 809 * @throws CmsException if something goes wrong 810 * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0 811 */ 812 public CmsResource createResource( 813 String resourcename, 814 I_CmsResourceType type, 815 byte[] content, 816 List<CmsProperty> properties) 817 throws CmsException, CmsIllegalArgumentException { 818 819 return type.createResource(this, m_securityManager, resourcename, content, properties); 820 } 821 822 /** 823 * Creates a new resource of the given resource type with 824 * empty content and no properties.<p> 825 * 826 * @param resourcename the name of the resource to create (full current site relative path) 827 * @param type the type of the resource to create 828 * 829 * @return the created resource 830 * 831 * @throws CmsException if something goes wrong 832 * @throws CmsIllegalArgumentException if the given <code>resourcename</code> is null or of length 0 833 * 834 * @see #createResource(String, int, byte[], List) 835 * 836 * @deprecated 837 * Use {@link #createResource(String, I_CmsResourceType)} instead. 838 * Resource types should always be referenced either by its type class (preferred) or by type name. 839 * Use of int based resource type references will be discontinued in a future OpenCms release. 840 */ 841 @Deprecated 842 public CmsResource createResource(String resourcename, int type) throws CmsException, CmsIllegalArgumentException { 843 844 return createResource(resourcename, getResourceType(type), new byte[0], new ArrayList<CmsProperty>(0)); 845 } 846 847 /** 848 * Creates a new resource of the given resource type 849 * with the provided content and properties.<p> 850 * 851 * @param resourcename the name of the resource to create (full current site relative path) 852 * @param type the type of the resource to create 853 * @param content the contents for the new resource 854 * @param properties the properties for the new resource 855 * 856 * @return the created resource 857 * 858 * @throws CmsException if something goes wrong 859 * @throws CmsIllegalArgumentException if the <code>resourcename</code> argument is null or of length 0 860 * 861 * @deprecated 862 * Use {@link #createResource(String, I_CmsResourceType, byte[], List)} instead. 863 * Resource types should always be referenced either by its type class (preferred) or by type name. 864 * Use of int based resource type references will be discontinued in a future OpenCms release. 865 */ 866 @Deprecated 867 public CmsResource createResource(String resourcename, int type, byte[] content, List<CmsProperty> properties) 868 throws CmsException, CmsIllegalArgumentException { 869 870 return createResource(resourcename, getResourceType(type), content, properties); 871 } 872 873 /** 874 * Creates a new sibling of the source resource.<p> 875 * 876 * @param source the name of the resource to create a sibling for with complete path 877 * @param destination the name of the sibling to create with complete path 878 * @param properties the individual properties for the new sibling 879 * 880 * @return the new created sibling 881 * 882 * @throws CmsException if something goes wrong 883 */ 884 public CmsResource createSibling(String source, String destination, List<CmsProperty> properties) 885 throws CmsException { 886 887 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 888 return getResourceType(resource).createSibling(this, m_securityManager, resource, destination, properties); 889 } 890 891 /** 892 * Creates the project for the temporary workplace files.<p> 893 * 894 * @return the created project for the temporary workplace files 895 * 896 * @throws CmsException if something goes wrong 897 */ 898 public CmsProject createTempfileProject() throws CmsException { 899 900 return m_securityManager.createTempfileProject(m_context); 901 } 902 903 /** 904 * Creates a new user.<p> 905 * 906 * @param userFqn the name for the new user 907 * @param password the password for the new user 908 * @param description the description for the new user 909 * @param additionalInfos the additional infos for the user 910 * 911 * @return the created user 912 * 913 * @throws CmsException if something goes wrong 914 */ 915 public CmsUser createUser(String userFqn, String password, String description, Map<String, Object> additionalInfos) 916 throws CmsException { 917 918 return m_securityManager.createUser(m_context, userFqn, password, description, additionalInfos); 919 } 920 921 /** 922 * Deletes all published resource entries.<p> 923 * 924 * @param linkType the type of resource deleted (0= non-parameter, 1=parameter) 925 * 926 * @throws CmsException if something goes wrong 927 */ 928 public void deleteAllStaticExportPublishedResources(int linkType) throws CmsException { 929 930 m_securityManager.deleteAllStaticExportPublishedResources(m_context, linkType); 931 } 932 933 /** 934 * Deletes a group, where all permissions, users and children of the group 935 * are transfered to a replacement group.<p> 936 * 937 * @param groupId the id of the group to be deleted 938 * @param replacementId the id of the group to be transfered, can be <code>null</code> 939 * 940 * @throws CmsException if operation was not successful 941 */ 942 public void deleteGroup(CmsUUID groupId, CmsUUID replacementId) throws CmsException { 943 944 m_securityManager.deleteGroup(m_context, groupId, replacementId); 945 } 946 947 /** 948 * Deletes a user group.<p> 949 * 950 * Only groups that contain no subgroups can be deleted.<p> 951 * 952 * @param group the name of the group 953 * 954 * @throws CmsException if operation was not successful 955 */ 956 public void deleteGroup(String group) throws CmsException { 957 958 m_securityManager.deleteGroup(m_context, group); 959 } 960 961 /** 962 * Deletes the versions from the history tables, keeping the given number of versions per resource.<p> 963 * 964 * @param versionsToKeep number of versions to keep, is ignored if negative 965 * @param versionsDeleted number of versions to keep for deleted resources, is ignored if negative 966 * @param timeDeleted deleted resources older than this will also be deleted, is ignored if negative 967 * @param report the report for output logging 968 * 969 * @throws CmsException if operation was not successful 970 */ 971 public void deleteHistoricalVersions(int versionsToKeep, int versionsDeleted, long timeDeleted, I_CmsReport report) 972 throws CmsException { 973 974 m_securityManager.deleteHistoricalVersions(m_context, versionsToKeep, versionsDeleted, timeDeleted, report); 975 } 976 977 /** 978 * Deletes the log entries matching the given filter.<p> 979 * 980 * @param filter the filter to use for deleting the log entries 981 * 982 * @throws CmsException if something goes wrong 983 * 984 * @see CmsSecurityManager#deleteLogEntries(CmsRequestContext, CmsLogFilter) 985 * @see #getLogEntries(CmsLogFilter) 986 */ 987 public void deleteLogEntries(CmsLogFilter filter) throws CmsException { 988 989 m_securityManager.deleteLogEntries(m_context, filter); 990 } 991 992 /** 993 * Deletes a project.<p> 994 * 995 * All resources inside the project have to be be reset to their online state.<p> 996 * 997 * @param id the id of the project to delete 998 * 999 * @throws CmsException if operation was not successful 1000 */ 1001 public void deleteProject(CmsUUID id) throws CmsException { 1002 1003 m_securityManager.deleteProject(m_context, id); 1004 } 1005 1006 /** 1007 * Deletes a property definition.<p> 1008 * 1009 * @param name the name of the property definition to delete 1010 * 1011 * @throws CmsException if something goes wrong 1012 */ 1013 public void deletePropertyDefinition(String name) throws CmsException { 1014 1015 m_securityManager.deletePropertyDefinition(m_context, name); 1016 } 1017 1018 /** 1019 * Deletes the relations to a given resource.<p> 1020 * 1021 * @param resource the resource to delete the relations from 1022 * @param filter the filter to use for deleting the relations 1023 * 1024 * @throws CmsException if something goes wrong 1025 */ 1026 public void deleteRelationsFromResource(CmsResource resource, CmsRelationFilter filter) throws CmsException { 1027 1028 m_securityManager.deleteRelationsForResource(m_context, resource, filter); 1029 } 1030 1031 /** 1032 * Deletes the relations to a given resource.<p> 1033 * 1034 * @param resourceName the resource to delete the relations from 1035 * @param filter the filter to use for deleting the relations 1036 * 1037 * @throws CmsException if something goes wrong 1038 */ 1039 public void deleteRelationsFromResource(String resourceName, CmsRelationFilter filter) throws CmsException { 1040 1041 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1042 m_securityManager.deleteRelationsForResource(m_context, resource, filter); 1043 } 1044 1045 /** 1046 * Deletes a resource.<p> 1047 * 1048 * The <code>siblingMode</code> parameter controls how to handle siblings 1049 * during the delete operation.<br> 1050 * Possible values for this parameter are: <br> 1051 * <ul> 1052 * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li> 1053 * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li> 1054 * </ul><p> 1055 * 1056 * @param res the resource to delete 1057 * @param deletePreserveSiblings indicates how to handle siblings of the deleted resource 1058 * 1059 * @throws CmsException if something goes wrong 1060 */ 1061 public void deleteResource(CmsResource res, CmsResourceDeleteMode deletePreserveSiblings) throws CmsException { 1062 1063 getResourceType(res).deleteResource(this, m_securityManager, res, deletePreserveSiblings); 1064 } 1065 1066 /** 1067 * Deletes a resource given its name.<p> 1068 * 1069 * The <code>siblingMode</code> parameter controls how to handle siblings 1070 * during the delete operation.<br> 1071 * Possible values for this parameter are: <br> 1072 * <ul> 1073 * <li><code>{@link CmsResource#DELETE_REMOVE_SIBLINGS}</code></li> 1074 * <li><code>{@link CmsResource#DELETE_PRESERVE_SIBLINGS}</code></li> 1075 * </ul><p> 1076 * 1077 * @param resourcename the name of the resource to delete (full current site relative path) 1078 * @param siblingMode indicates how to handle siblings of the deleted resource 1079 * 1080 * @throws CmsException if something goes wrong 1081 */ 1082 public void deleteResource(String resourcename, CmsResource.CmsResourceDeleteMode siblingMode) throws CmsException { 1083 1084 // throw the exception if resource name is an empty string 1085 if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) { 1086 throw new CmsVfsResourceNotFoundException( 1087 Messages.get().container(Messages.ERR_DELETE_RESOURCE_1, resourcename)); 1088 } 1089 1090 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 1091 getResourceType(resource).deleteResource(this, m_securityManager, resource, siblingMode); 1092 } 1093 1094 /** 1095 * Deletes a published resource entry.<p> 1096 * 1097 * @param resourceName The name of the resource to be deleted in the static export 1098 * @param linkType the type of resource deleted (0= non-parameter, 1=parameter) 1099 * @param linkParameter the parameters of the resource 1100 * 1101 * @throws CmsException if something goes wrong 1102 */ 1103 public void deleteStaticExportPublishedResource(String resourceName, int linkType, String linkParameter) 1104 throws CmsException { 1105 1106 m_securityManager.deleteStaticExportPublishedResource(m_context, resourceName, linkType, linkParameter); 1107 } 1108 1109 /** 1110 * Deletes a user.<p> 1111 * 1112 * @param userId the id of the user to be deleted 1113 * 1114 * @throws CmsException if operation was not successful 1115 */ 1116 public void deleteUser(CmsUUID userId) throws CmsException { 1117 1118 m_securityManager.deleteUser(m_context, userId); 1119 } 1120 1121 /** 1122 * Deletes a user, where all permissions and resources attributes of the user 1123 * were transfered to a replacement user.<p> 1124 * 1125 * @param userId the id of the user to be deleted 1126 * @param replacementId the id of the user to be transfered, can be <code>null</code> 1127 * 1128 * @throws CmsException if operation was not successful 1129 */ 1130 public void deleteUser(CmsUUID userId, CmsUUID replacementId) throws CmsException { 1131 1132 m_securityManager.deleteUser(m_context, userId, replacementId); 1133 } 1134 1135 /** 1136 * Deletes a user.<p> 1137 * 1138 * @param username the name of the user to be deleted 1139 * 1140 * @throws CmsException if operation was not successful 1141 */ 1142 public void deleteUser(String username) throws CmsException { 1143 1144 m_securityManager.deleteUser(m_context, username); 1145 } 1146 1147 /** 1148 * Checks the availability of a resource in the VFS, 1149 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1150 * 1151 * A resource may be of type <code>{@link CmsFile}</code> or 1152 * <code>{@link CmsFolder}</code>.<p> 1153 * 1154 * This method also takes into account the user permissions, so if 1155 * the given resource exists, but the current user has not the required 1156 * permissions, then this method will return <code>false</code>.<p> 1157 * 1158 * @param structureId the structure id of the resource to check 1159 * 1160 * @return <code>true</code> if the resource is available 1161 * 1162 * @see #readResource(CmsUUID) 1163 * @see #existsResource(CmsUUID, CmsResourceFilter) 1164 */ 1165 public boolean existsResource(CmsUUID structureId) { 1166 1167 return existsResource(structureId, CmsResourceFilter.DEFAULT); 1168 } 1169 1170 /** 1171 * Checks the availability of a resource in the VFS, 1172 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1173 * 1174 * A resource may be of type <code>{@link CmsFile}</code> or 1175 * <code>{@link CmsFolder}</code>.<p> 1176 * 1177 * The specified filter controls what kind of resources should be "found" 1178 * during the read operation. This will depend on the application. For example, 1179 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 1180 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 1181 * will ignore the date release / date expired information of the resource.<p> 1182 * 1183 * This method also takes into account the user permissions, so if 1184 * the given resource exists, but the current user has not the required 1185 * permissions, then this method will return <code>false</code>.<p> 1186 * 1187 * @param structureId the structure id of the resource to check 1188 * @param filter the resource filter to use while checking 1189 * 1190 * @return <code>true</code> if the resource is available 1191 * 1192 * @see #readResource(CmsUUID) 1193 * @see #readResource(CmsUUID, CmsResourceFilter) 1194 */ 1195 public boolean existsResource(CmsUUID structureId, CmsResourceFilter filter) { 1196 1197 return m_securityManager.existsResource(m_context, structureId, filter); 1198 } 1199 1200 /** 1201 * Checks the availability of a resource in the VFS, 1202 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1203 * 1204 * A resource may be of type <code>{@link CmsFile}</code> or 1205 * <code>{@link CmsFolder}</code>.<p> 1206 * 1207 * This method also takes into account the user permissions, so if 1208 * the given resource exists, but the current user has not the required 1209 * permissions, then this method will return <code>false</code>.<p> 1210 * 1211 * @param resourcename the name of the resource to check (full current site relative path) 1212 * 1213 * @return <code>true</code> if the resource is available 1214 * 1215 * @see #readResource(String) 1216 * @see #existsResource(String, CmsResourceFilter) 1217 */ 1218 public boolean existsResource(String resourcename) { 1219 1220 return existsResource(resourcename, CmsResourceFilter.DEFAULT); 1221 } 1222 1223 /** 1224 * Checks the availability of a resource in the VFS, 1225 * using the provided filter.<p> 1226 * 1227 * A resource may be of type <code>{@link CmsFile}</code> or 1228 * <code>{@link CmsFolder}</code>.<p> 1229 * 1230 * The specified filter controls what kind of resources should be "found" 1231 * during the read operation. This will depend on the application. For example, 1232 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 1233 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 1234 * will ignore the date release / date expired information of the resource.<p> 1235 * 1236 * This method also takes into account the user permissions, so if 1237 * the given resource exists, but the current user has not the required 1238 * permissions, then this method will return <code>false</code>.<p> 1239 * 1240 * @param resourcename the name of the resource to check (full current site relative path) 1241 * @param filter the resource filter to use while checking 1242 * 1243 * @return <code>true</code> if the resource is available 1244 * 1245 * @see #readResource(String) 1246 * @see #readResource(String, CmsResourceFilter) 1247 */ 1248 public boolean existsResource(String resourcename, CmsResourceFilter filter) { 1249 1250 return m_securityManager.existsResource(m_context, addSiteRoot(resourcename), filter); 1251 } 1252 1253 /** 1254 * Returns the list of access control entries of a resource given its name.<p> 1255 * 1256 * @param resourceName the name of the resource 1257 * 1258 * @return a list of <code>{@link CmsAccessControlEntry}</code> objects 1259 * 1260 * @throws CmsException if something goes wrong 1261 */ 1262 public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName) throws CmsException { 1263 1264 return getAccessControlEntries(resourceName, true); 1265 } 1266 1267 /** 1268 * Returns the list of access control entries of a resource given its name.<p> 1269 * 1270 * @param resourceName the name of the resource 1271 * @param getInherited <code>true</code>, if inherited access control entries should be returned, too 1272 * 1273 * @return a list of <code>{@link CmsAccessControlEntry}</code> objects defining all permissions for the given resource 1274 * 1275 * @throws CmsException if something goes wrong 1276 */ 1277 public List<CmsAccessControlEntry> getAccessControlEntries(String resourceName, boolean getInherited) 1278 throws CmsException { 1279 1280 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 1281 return m_securityManager.getAccessControlEntries(m_context, res, getInherited); 1282 } 1283 1284 /** 1285 * Returns the access control list (summarized access control entries) of a given resource.<p> 1286 * 1287 * @param resourceName the name of the resource 1288 * 1289 * @return the access control list of the resource 1290 * 1291 * @throws CmsException if something goes wrong 1292 */ 1293 public CmsAccessControlList getAccessControlList(String resourceName) throws CmsException { 1294 1295 return getAccessControlList(resourceName, false); 1296 } 1297 1298 /** 1299 * Returns the access control list (summarized access control entries) of a given resource.<p> 1300 * 1301 * If <code>inheritedOnly</code> is set, only inherited access control entries are returned.<p> 1302 * 1303 * @param resourceName the name of the resource 1304 * @param inheritedOnly if set, the non-inherited entries are skipped 1305 * 1306 * @return the access control list of the resource 1307 * 1308 * @throws CmsException if something goes wrong 1309 */ 1310 public CmsAccessControlList getAccessControlList(String resourceName, boolean inheritedOnly) throws CmsException { 1311 1312 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 1313 return m_securityManager.getAccessControlList(m_context, res, inheritedOnly); 1314 } 1315 1316 /** 1317 * Gets all access control entries for the current project.<p> 1318 * 1319 * @return the list of all access control entries 1320 * 1321 * @throws CmsException if something goes wrong 1322 */ 1323 public List<CmsAccessControlEntry> getAllAccessControlEntries() throws CmsException { 1324 1325 return m_securityManager.getAllAccessControlEntries(m_context); 1326 } 1327 1328 /** 1329 * Returns a list with all projects from history.<p> 1330 * 1331 * @return list of <code>{@link CmsHistoryProject}</code> objects 1332 * with all projects from history 1333 * 1334 * @throws CmsException if operation was not successful 1335 */ 1336 public List<CmsHistoryProject> getAllHistoricalProjects() throws CmsException { 1337 1338 return m_securityManager.getAllHistoricalProjects(m_context); 1339 } 1340 1341 /** 1342 * Gets all URL names for a given structure id.<p> 1343 * 1344 * @param id the structure id 1345 * @return the list of all URL names for that structure id 1346 * 1347 * @throws CmsException if something goes wrong 1348 */ 1349 public List<String> getAllUrlNames(CmsUUID id) throws CmsException { 1350 1351 return m_securityManager.readAllUrlNameMappingEntries(m_context, id); 1352 } 1353 1354 /** 1355 * Returns a list of child resources to the given resource that can not be locked by the current user.<p> 1356 * 1357 * @param resource the resource 1358 * 1359 * @return a list of child resources to the given resource that can not be locked by the current user 1360 * 1361 * @throws CmsException if something goes wrong reading the resources 1362 */ 1363 public List<CmsResource> getBlockingLockedResources(CmsResource resource) throws CmsException { 1364 1365 if (resource.isFolder()) { 1366 CmsLockFilter blockingFilter = CmsLockFilter.FILTER_ALL; 1367 blockingFilter = blockingFilter.filterNotLockableByUser(getRequestContext().getCurrentUser()); 1368 return getLockedResources(resource, blockingFilter); 1369 } 1370 return Collections.<CmsResource> emptyList(); 1371 } 1372 1373 /** 1374 * Returns a list of child resources to the given resource that can not be locked by the current user.<p> 1375 * 1376 * @param resourceName the resource site path 1377 * 1378 * @return a list of child resources to the given resource that can not be locked by the current user 1379 * 1380 * @throws CmsException if something goes wrong reading the resources 1381 */ 1382 public List<CmsResource> getBlockingLockedResources(String resourceName) throws CmsException { 1383 1384 CmsResource resource = readResource(resourceName); 1385 return getBlockingLockedResources(resource); 1386 } 1387 1388 /** 1389 * Returns all child groups of a group.<p> 1390 * 1391 * @param groupname the name of the group 1392 * @param includeSubChildren if set also returns all sub-child groups of the given group 1393 * 1394 * @return a list of all child <code>{@link CmsGroup}</code> objects or <code>null</code> 1395 * 1396 * @throws CmsException if operation was not successful 1397 */ 1398 public List<CmsGroup> getChildren(String groupname, boolean includeSubChildren) throws CmsException { 1399 1400 return m_securityManager.getChildren(m_context, groupname, includeSubChildren); 1401 } 1402 1403 /** 1404 * Returns the detail name of a resource.<p> 1405 * 1406 * The detail view URI of a content element consists of its detail page URI and the detail name returned by this 1407 * method.<p> 1408 * 1409 * @param res the resource for which the detail name should be retrieved 1410 * @param locale the locale for the detail name 1411 * @param defaultLocales the default locales for the detail name 1412 * 1413 * @return the detail name 1414 * @throws CmsException if something goes wrong 1415 */ 1416 public String getDetailName(CmsResource res, Locale locale, List<Locale> defaultLocales) throws CmsException { 1417 1418 String urlName = readBestUrlName(res.getStructureId(), locale, defaultLocales); 1419 if (urlName == null) { 1420 urlName = res.getStructureId().toString(); 1421 } 1422 return urlName; 1423 } 1424 1425 /** 1426 * Returns all file resources contained in a folder.<p> 1427 * 1428 * The result is filtered according to the rules of 1429 * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1430 * 1431 * @param resourcename the full current site relative path of the resource to return the child resources for 1432 * 1433 * @return a list of all child files as <code>{@link CmsResource}</code> objects 1434 * 1435 * @throws CmsException if something goes wrong 1436 * 1437 * @see #getFilesInFolder(String, CmsResourceFilter) 1438 */ 1439 public List<CmsResource> getFilesInFolder(String resourcename) throws CmsException { 1440 1441 return getFilesInFolder(resourcename, CmsResourceFilter.DEFAULT); 1442 } 1443 1444 /** 1445 * Returns all file resources contained in a folder.<p> 1446 * 1447 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1448 * you can control if you want to include deleted, invisible or 1449 * time-invalid resources in the result.<p> 1450 * 1451 * @param resourcename the full path of the resource to return the child resources for 1452 * @param filter the resource filter to use 1453 * 1454 * @return a list of all child file as <code>{@link CmsResource}</code> objects 1455 * 1456 * @throws CmsException if something goes wrong 1457 */ 1458 public List<CmsResource> getFilesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1459 1460 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1461 return m_securityManager.readChildResources(m_context, resource, filter, false, true); 1462 } 1463 1464 /** 1465 * Returns all the groups the given user belongs to.<p> 1466 * 1467 * @param username the name of the user 1468 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1469 * 1470 * @return a list of <code>{@link CmsGroup}</code> objects 1471 * 1472 * @throws CmsException if operation was not successful 1473 */ 1474 public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly) throws CmsException { 1475 1476 return getGroupsOfUser(username, directGroupsOnly, true); 1477 } 1478 1479 /** 1480 * Returns all the groups the given user belongs to.<p> 1481 * 1482 * @param username the name of the user 1483 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1484 * @param includeOtherOus if to include groups of other organizational units 1485 * 1486 * @return a list of <code>{@link CmsGroup}</code> objects 1487 * 1488 * @throws CmsException if operation was not successful 1489 */ 1490 public List<CmsGroup> getGroupsOfUser(String username, boolean directGroupsOnly, boolean includeOtherOus) 1491 throws CmsException { 1492 1493 return getGroupsOfUser(username, directGroupsOnly, includeOtherOus, m_context.getRemoteAddress()); 1494 } 1495 1496 /** 1497 * Returns the groups of a user filtered by the specified IP address.<p> 1498 * 1499 * @param username the name of the user 1500 * @param directGroupsOnly if set only the direct assigned groups will be returned, if not also indirect roles 1501 * @param remoteAddress the IP address to filter the groups in the result list 1502 * @param includeOtherOus if to include groups of other organizational units 1503 * 1504 * @return a list of <code>{@link CmsGroup}</code> objects filtered by the specified IP address 1505 * 1506 * @throws CmsException if operation was not successful 1507 */ 1508 public List<CmsGroup> getGroupsOfUser( 1509 String username, 1510 boolean directGroupsOnly, 1511 boolean includeOtherOus, 1512 String remoteAddress) 1513 throws CmsException { 1514 1515 return m_securityManager.getGroupsOfUser( 1516 m_context, 1517 username, 1518 (includeOtherOus ? "" : CmsOrganizationalUnit.getParentFqn(username)), 1519 includeOtherOus, 1520 false, 1521 directGroupsOnly, 1522 remoteAddress); 1523 } 1524 1525 /** 1526 * Creates a new locale group service.<p> 1527 * 1528 * @return a locale group service instance 1529 */ 1530 public CmsLocaleGroupService getLocaleGroupService() { 1531 1532 return new CmsLocaleGroupService(this); 1533 } 1534 1535 /** 1536 * Returns the edition lock state for a specified resource.<p> 1537 * 1538 * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p> 1539 * 1540 * @param resource the resource to return the edition lock state for 1541 * 1542 * @return the edition lock state for the specified resource 1543 * 1544 * @throws CmsException if something goes wrong 1545 */ 1546 public CmsLock getLock(CmsResource resource) throws CmsException { 1547 1548 return m_securityManager.getLock(m_context, resource); 1549 } 1550 1551 /** 1552 * Returns the lock state for a specified resource name.<p> 1553 * 1554 * If the resource is waiting to be publish you might get a lock of type {@link CmsLockType#PUBLISH}.<p> 1555 * 1556 * @param resourcename the name if the resource to get the lock state for (full current site relative path) 1557 * 1558 * @return the lock state for the specified resource 1559 * 1560 * @throws CmsException if something goes wrong 1561 */ 1562 public CmsLock getLock(String resourcename) throws CmsException { 1563 1564 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1565 return getLock(resource); 1566 } 1567 1568 /** 1569 * Returns all locked resources within a folder or matches the lock of the given resource.<p> 1570 * 1571 * @param resource the resource to check 1572 * @param filter the lock filter 1573 * 1574 * @return a list of locked resources 1575 * 1576 * @throws CmsException if operation was not successful 1577 */ 1578 public List<CmsResource> getLockedResources(CmsResource resource, CmsLockFilter filter) throws CmsException { 1579 1580 return m_securityManager.getLockedResourcesObjects(m_context, resource, filter); 1581 } 1582 1583 /** 1584 * Returns all locked resources within a folder or matches the lock of the given resource.<p> 1585 * 1586 * @param resourceName the name of the resource to check 1587 * @param filter the lock filter 1588 * 1589 * @return a list of locked resource paths (relative to current site) 1590 * 1591 * @throws CmsException if operation was not successful 1592 */ 1593 public List<String> getLockedResources(String resourceName, CmsLockFilter filter) throws CmsException { 1594 1595 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1596 return m_securityManager.getLockedResources(m_context, resource, filter); 1597 } 1598 1599 /** 1600 * Returns all locked resources within a folder or matches the lock of the given resource, but uses a cache for resource lookup.<p> 1601 * 1602 * @param resource the resource to check 1603 * @param filter the lock filter 1604 * @param cache the cache to use for resource lookups 1605 * 1606 * @return a list of locked resources 1607 * 1608 * @throws CmsException if operation was not successful 1609 */ 1610 public List<CmsResource> getLockedResourcesWithCache( 1611 CmsResource resource, 1612 CmsLockFilter filter, 1613 Map<String, CmsResource> cache) 1614 throws CmsException { 1615 1616 return m_securityManager.getLockedResourcesObjectsWithCache(m_context, resource, filter, cache); 1617 } 1618 1619 /** 1620 * Returns all log entries matching the given filter.<p> 1621 * 1622 * @param filter the filter to match the relation 1623 * 1624 * @return a list containing all log entries matching the given filter 1625 * 1626 * @throws CmsException if something goes wrong 1627 * 1628 * @see CmsSecurityManager#getLogEntries(CmsRequestContext, CmsLogFilter) 1629 * @see #deleteLogEntries(CmsLogFilter) 1630 */ 1631 public List<CmsLogEntry> getLogEntries(CmsLogFilter filter) throws CmsException { 1632 1633 return m_securityManager.getLogEntries(m_context, filter); 1634 } 1635 1636 /** 1637 * Returns the name a resource would have if it were moved to the 1638 * "lost and found" folder. <p> 1639 * 1640 * In general, it is the same name as the given resource has, the only exception is 1641 * if a resource in the "lost and found" folder with the same name already exists. 1642 * In such case, a counter is added to the resource name.<p> 1643 * 1644 * @param resourcename the name of the resource to get the "lost and found" name for (full current site relative path) 1645 * 1646 * @return the tentative name of the resource inside the "lost and found" folder 1647 * 1648 * @throws CmsException if something goes wrong 1649 * 1650 * @see #moveToLostAndFound(String) 1651 */ 1652 public String getLostAndFoundName(String resourcename) throws CmsException { 1653 1654 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1655 return m_securityManager.moveToLostAndFound(m_context, resource, true); 1656 } 1657 1658 /** 1659 * Returns the parent group of a group.<p> 1660 * 1661 * @param groupname the name of the group 1662 * 1663 * @return group the parent group or <code>null</code> 1664 * 1665 * @throws CmsException if operation was not successful 1666 */ 1667 public CmsGroup getParent(String groupname) throws CmsException { 1668 1669 return m_securityManager.getParent(m_context, groupname); 1670 } 1671 1672 /** 1673 * Returns the set of permissions of the current user for a given resource.<p> 1674 * 1675 * @param resourceName the name of the resource 1676 * 1677 * @return the bit set of the permissions of the current user 1678 * 1679 * @throws CmsException if something goes wrong 1680 */ 1681 public CmsPermissionSet getPermissions(String resourceName) throws CmsException { 1682 1683 return getPermissions(resourceName, m_context.getCurrentUser().getName()); 1684 } 1685 1686 /** 1687 * Returns the set of permissions of a given user for a given resource.<p> 1688 * 1689 * @param resourceName the name of the resource 1690 * @param userName the name of the user 1691 * 1692 * @return the current permissions on this resource 1693 * 1694 * @throws CmsException if something goes wrong 1695 */ 1696 public CmsPermissionSet getPermissions(String resourceName, String userName) throws CmsException { 1697 1698 // reading permissions is allowed even if the resource is marked as deleted 1699 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1700 CmsUser user = readUser(userName); 1701 return m_securityManager.getPermissions(m_context, resource, user); 1702 } 1703 1704 /** 1705 * Returns all relations for the given resource matching the given filter.<p> 1706 * 1707 * You should have view/read permissions on the given resource.<p> 1708 * 1709 * You may become source and/or target paths to resource you do not have view/read permissions on.<p> 1710 * 1711 * @param resource the resource to retrieve the relations for 1712 * @param filter the filter to match the relation 1713 * 1714 * @return a List containing all {@link org.opencms.relations.CmsRelation} 1715 * objects for the given resource matching the given filter 1716 * 1717 * @throws CmsException if something goes wrong 1718 * 1719 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 1720 */ 1721 public List<CmsRelation> getRelationsForResource(CmsResource resource, CmsRelationFilter filter) 1722 throws CmsException { 1723 1724 return m_securityManager.getRelationsForResource(m_context, resource, filter); 1725 } 1726 1727 /** 1728 * Returns all relations for the given resource matching the given filter.<p> 1729 * 1730 * You should have view/read permissions on the given resource.<p> 1731 * 1732 * You may become source and/or target paths to resource you do not have view/read permissions on.<p> 1733 * 1734 * @param resourceName the name of the resource to retrieve the relations for 1735 * @param filter the filter to match the relation 1736 * 1737 * @return a List containing all {@link org.opencms.relations.CmsRelation} 1738 * objects for the given resource matching the given filter 1739 * 1740 * @throws CmsException if something goes wrong 1741 * 1742 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 1743 */ 1744 public List<CmsRelation> getRelationsForResource(String resourceName, CmsRelationFilter filter) 1745 throws CmsException { 1746 1747 return getRelationsForResource(readResource(resourceName, CmsResourceFilter.ALL), filter); 1748 } 1749 1750 /** 1751 * Returns the current users request context.<p> 1752 * 1753 * This request context is used to authenticate the user for all 1754 * OpenCms operations. It also contains the request runtime settings, e.g. 1755 * about the current site this request was made on.<p> 1756 * 1757 * @return the current users request context 1758 */ 1759 public CmsRequestContext getRequestContext() { 1760 1761 return m_context; 1762 } 1763 1764 /** 1765 * Returns all resources associated to a given principal via an ACE with the given permissions.<p> 1766 * 1767 * If the <code>includeAttr</code> flag is set it returns also all resources associated to 1768 * a given principal through some of following attributes.<p> 1769 * 1770 * <ul> 1771 * <li>User Created</li> 1772 * <li>User Last Modified</li> 1773 * </ul><p> 1774 * 1775 * @param principalId the id of the principal 1776 * @param permissions a set of permissions to match, can be <code>null</code> for all ACEs 1777 * @param includeAttr a flag to include resources associated by attributes 1778 * 1779 * @return a set of <code>{@link CmsResource}</code> objects 1780 * 1781 * @throws CmsException if something goes wrong 1782 */ 1783 public Set<CmsResource> getResourcesForPrincipal( 1784 CmsUUID principalId, 1785 CmsPermissionSet permissions, 1786 boolean includeAttr) 1787 throws CmsException { 1788 1789 return m_securityManager.getResourcesForPrincipal(getRequestContext(), principalId, permissions, includeAttr); 1790 } 1791 1792 /** 1793 * Returns all child resources of a resource, that is the resources 1794 * contained in a folder.<p> 1795 * 1796 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1797 * you can control if you want to include deleted, invisible or 1798 * time-invalid resources in the result.<p> 1799 * 1800 * This method is mainly used by the workplace explorer.<p> 1801 * 1802 * @param resourcename the full current site relative path of the resource to return the child resources for 1803 * @param filter the resource filter to use 1804 * 1805 * @return a list of all child <code>{@link CmsResource}</code>s 1806 * 1807 * @throws CmsException if something goes wrong 1808 */ 1809 public List<CmsResource> getResourcesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1810 1811 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1812 return m_securityManager.readChildResources(m_context, resource, filter, true, true); 1813 } 1814 1815 /** 1816 * Adjusts the absolute resource root path for the current site.<p> 1817 * 1818 * The full root path of a resource is always available using 1819 * <code>{@link CmsResource#getRootPath()}</code>. From this name this method cuts 1820 * of the current site root using 1821 * <code>{@link CmsRequestContext#removeSiteRoot(String)}</code>.<p> 1822 * 1823 * If the resource root path does not start with the current site root, 1824 * it is left untouched.<p> 1825 * 1826 * @param resource the resource to get the adjusted site root path for 1827 * 1828 * @return the absolute resource path adjusted for the current site 1829 * 1830 * @see CmsRequestContext#removeSiteRoot(String) 1831 * @see CmsRequestContext#getSitePath(CmsResource) 1832 * @see CmsResource#getRootPath() 1833 */ 1834 public String getSitePath(CmsResource resource) { 1835 1836 return m_context.getSitePath(resource); 1837 } 1838 1839 /** 1840 * Returns all folder resources contained in a folder.<p> 1841 * 1842 * The result is filtered according to the rules of 1843 * the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 1844 * 1845 * @param resourcename the full current site relative path of the resource to return the child resources for. 1846 * 1847 * @return a list of all child file as <code>{@link CmsResource}</code> objects 1848 * 1849 * @throws CmsException if something goes wrong 1850 * 1851 * @see #getSubFolders(String, CmsResourceFilter) 1852 */ 1853 public List<CmsResource> getSubFolders(String resourcename) throws CmsException { 1854 1855 return getSubFolders(resourcename, CmsResourceFilter.DEFAULT); 1856 } 1857 1858 /** 1859 * Returns all folder resources contained in a folder.<p> 1860 * 1861 * With the <code>{@link CmsResourceFilter}</code> provided as parameter 1862 * you can control if you want to include deleted, invisible or 1863 * time-invalid resources in the result.<p> 1864 * 1865 * @param resourcename the full current site relative path of the resource to return the child resources for. 1866 * 1867 * @return a list of all child folder <code>{@link CmsResource}</code>s 1868 * @param filter the resource filter to use 1869 * 1870 * @throws CmsException if something goes wrong 1871 */ 1872 public List<CmsResource> getSubFolders(String resourcename, CmsResourceFilter filter) throws CmsException { 1873 1874 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1875 return m_securityManager.readChildResources(m_context, resource, filter, true, false); 1876 } 1877 1878 /** 1879 * Returns the newest URL names for the given structure id for each locale.<p> 1880 * 1881 * @param id the structure id 1882 * @return the list of URL names for each locale 1883 * 1884 * @throws CmsException if something goes wrong 1885 */ 1886 public List<String> getUrlNamesForAllLocales(CmsUUID id) throws CmsException { 1887 1888 return m_securityManager.readUrlNamesForAllLocales(m_context, id); 1889 } 1890 1891 /** 1892 * Returns all direct users of a given group.<p> 1893 * 1894 * Users that are "indirectly" in the group are not returned in the result.<p> 1895 * 1896 * @param groupname the name of the group to get all users for 1897 * 1898 * @return all <code>{@link CmsUser}</code> objects in the group 1899 * 1900 * @throws CmsException if operation was not successful 1901 */ 1902 public List<CmsUser> getUsersOfGroup(String groupname) throws CmsException { 1903 1904 return getUsersOfGroup(groupname, true); 1905 } 1906 1907 /** 1908 * Returns all direct users of a given group.<p> 1909 * 1910 * Users that are "indirectly" in the group are not returned in the result.<p> 1911 * 1912 * @param groupname the name of the group to get all users for 1913 * @param includeOtherOus if the result should include users of other ous 1914 * 1915 * @return all <code>{@link CmsUser}</code> objects in the group 1916 * 1917 * @throws CmsException if operation was not successful 1918 */ 1919 public List<CmsUser> getUsersOfGroup(String groupname, boolean includeOtherOus) throws CmsException { 1920 1921 return m_securityManager.getUsersOfGroup(m_context, groupname, includeOtherOus, true, false); 1922 } 1923 1924 /** 1925 * Checks if the current user has required permissions to access a given resource.<p> 1926 * 1927 * @param resource the resource to check the permissions for 1928 * @param requiredPermissions the set of permissions to check for 1929 * 1930 * @return <code>true</code> if the required permissions are satisfied 1931 * 1932 * @throws CmsException if something goes wrong 1933 */ 1934 public boolean hasPermissions(CmsResource resource, CmsPermissionSet requiredPermissions) throws CmsException { 1935 1936 return m_securityManager.hasPermissions( 1937 m_context, 1938 resource, 1939 requiredPermissions, 1940 true, 1941 CmsResourceFilter.ALL).isAllowed(); 1942 } 1943 1944 /** 1945 * Checks if the current user has required permissions to access a given resource.<p> 1946 * 1947 * @param resource the resource to check the permissions for 1948 * @param requiredPermissions the set of permissions to check for 1949 * @param checkLock if <code>true</code> the lock status of the resource is checked for write operations 1950 * and the resource needs be locked by the current user so that the test is passed, 1951 * if <code>false</code> the lock is not checked at all 1952 * @param filter the resource filter to use 1953 * 1954 * @return <code>true</code> if the required permissions are satisfied 1955 * 1956 * @throws CmsException if something goes wrong 1957 */ 1958 public boolean hasPermissions( 1959 CmsResource resource, 1960 CmsPermissionSet requiredPermissions, 1961 boolean checkLock, 1962 CmsResourceFilter filter) 1963 throws CmsException { 1964 1965 return I_CmsPermissionHandler.PERM_ALLOWED == m_securityManager.hasPermissions( 1966 m_context, 1967 resource, 1968 requiredPermissions, 1969 checkLock, 1970 filter); 1971 } 1972 1973 /** 1974 * Writes a list of access control entries as new access control entries of a given resource.<p> 1975 * 1976 * Already existing access control entries of this resource are removed before.<p> 1977 * 1978 * @param resource the resource to attach the control entries to 1979 * @param acEntries a list of <code>{@link CmsAccessControlEntry}</code> objects 1980 * 1981 * @throws CmsException if something goes wrong 1982 */ 1983 public void importAccessControlEntries(CmsResource resource, List<CmsAccessControlEntry> acEntries) 1984 throws CmsException { 1985 1986 m_securityManager.importAccessControlEntries(m_context, resource, acEntries); 1987 } 1988 1989 /** 1990 * Imports a new relation to the given resource.<p> 1991 * 1992 * @param resourceName the name of the source resource 1993 * @param targetPath the path of the target resource 1994 * @param relationType the type of the relation 1995 * 1996 * @throws CmsException if something goes wrong 1997 */ 1998 public void importRelation(String resourceName, String targetPath, String relationType) throws CmsException { 1999 2000 createRelation(resourceName, targetPath, relationType, true); 2001 } 2002 2003 /** 2004 * Imports a resource to the OpenCms VFS.<p> 2005 * 2006 * If a resource already exists in the VFS (i.e. has the same name and 2007 * same id) it is replaced by the imported resource.<p> 2008 * 2009 * If a resource with the same name but a different id exists, 2010 * the imported resource is (usually) moved to the "lost and found" folder.<p> 2011 * 2012 * @param resourcename the name for the resource after import (full current site relative path) 2013 * @param resource the resource object to be imported 2014 * @param content the content of the resource 2015 * @param properties the properties of the resource 2016 * 2017 * @return the imported resource 2018 * 2019 * @throws CmsException if something goes wrong 2020 * 2021 * @see CmsObject#moveToLostAndFound(String) 2022 */ 2023 public CmsResource importResource( 2024 String resourcename, 2025 CmsResource resource, 2026 byte[] content, 2027 List<CmsProperty> properties) 2028 throws CmsException { 2029 2030 return getResourceType( 2031 resource).importResource(this, m_securityManager, resourcename, resource, content, properties); 2032 } 2033 2034 /** 2035 * Creates a new user by import.<p> 2036 * 2037 * @param id the id of the user 2038 * @param name the new name for the user 2039 * @param password the new password for the user 2040 * @param firstname the first name of the user 2041 * @param lastname the last name of the user 2042 * @param email the email of the user 2043 * @param flags the flags for a user (for example <code>{@link I_CmsPrincipal#FLAG_ENABLED}</code>) 2044 * @param dateCreated the creation date 2045 * @param additionalInfos the additional user infos 2046 * 2047 * @return the imported user 2048 * 2049 * @throws CmsException if something goes wrong 2050 */ 2051 public CmsUser importUser( 2052 String id, 2053 String name, 2054 String password, 2055 String firstname, 2056 String lastname, 2057 String email, 2058 int flags, 2059 long dateCreated, 2060 Map<String, Object> additionalInfos) 2061 throws CmsException { 2062 2063 return m_securityManager.importUser( 2064 m_context, 2065 id, 2066 name, 2067 password, 2068 firstname, 2069 lastname, 2070 email, 2071 flags, 2072 dateCreated, 2073 additionalInfos); 2074 } 2075 2076 /** 2077 * Increments a counter and returns its old value.<p> 2078 * 2079 * @param name the name of the counter 2080 * 2081 * @return the value of the counter before incrementing 2082 * 2083 * @throws CmsException if something goes wrong 2084 */ 2085 public int incrementCounter(String name) throws CmsException { 2086 2087 return m_securityManager.incrementCounter(m_context, name); 2088 } 2089 2090 /** 2091 * Checks if the specified resource is inside the current project.<p> 2092 * 2093 * The project "view" is determined by a set of path prefixes. 2094 * If the resource starts with any one of this prefixes, it is considered to 2095 * be "inside" the project.<p> 2096 * 2097 * @param resourcename the specified resource name (full current site relative path) 2098 * 2099 * @return <code>true</code>, if the specified resource is inside the current project 2100 */ 2101 public boolean isInsideCurrentProject(String resourcename) { 2102 2103 return m_securityManager.isInsideCurrentProject(m_context, addSiteRoot(resourcename)); 2104 } 2105 2106 /** 2107 * Checks if the current user has management access to the current project.<p> 2108 * 2109 * @return <code>true</code>, if the user has management access to the current project 2110 */ 2111 2112 public boolean isManagerOfProject() { 2113 2114 return m_securityManager.isManagerOfProject(m_context); 2115 } 2116 2117 /** 2118 * Locks a resource.<p> 2119 * 2120 * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p> 2121 * 2122 * @param resource the resource to lock 2123 * 2124 * @throws CmsException if something goes wrong 2125 */ 2126 public void lockResource(CmsResource resource) throws CmsException { 2127 2128 getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.EXCLUSIVE); 2129 } 2130 2131 /** 2132 * Locks a resource.<p> 2133 * 2134 * This will be an exclusive, persistent lock that is removed only if the user unlocks it.<p> 2135 * 2136 * @param resourcename the name of the resource to lock (full current site relative path) 2137 * 2138 * @throws CmsException if something goes wrong 2139 */ 2140 public void lockResource(String resourcename) throws CmsException { 2141 2142 lockResource(resourcename, CmsLockType.EXCLUSIVE); 2143 } 2144 2145 /** 2146 * Locks a resource temporary.<p> 2147 * 2148 * This will be an exclusive, temporary lock valid only for the current users session. 2149 * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p> 2150 * 2151 * @param resource the resource to lock 2152 * 2153 * @throws CmsException if something goes wrong 2154 * 2155 * @see CmsObject#lockResource(String) 2156 */ 2157 public void lockResourceTemporary(CmsResource resource) throws CmsException { 2158 2159 getResourceType(resource).lockResource(this, m_securityManager, resource, CmsLockType.TEMPORARY); 2160 } 2161 2162 /** 2163 * Locks a resource temporary.<p> 2164 * 2165 * This will be an exclusive, temporary lock valid only for the current users session. 2166 * Usually this should not be used directly, this method is intended for the OpenCms workplace only.<p> 2167 * 2168 * @param resourcename the name of the resource to lock (full current site relative path) 2169 * 2170 * @throws CmsException if something goes wrong 2171 * 2172 * @see CmsObject#lockResource(String) 2173 */ 2174 public void lockResourceTemporary(String resourcename) throws CmsException { 2175 2176 lockResource(resourcename, CmsLockType.TEMPORARY); 2177 } 2178 2179 /** 2180 * Logs a user into the Cms, if the password is correct.<p> 2181 * 2182 * @param username the name of the user 2183 * @param password the password of the user 2184 * 2185 * @return the name of the logged in user 2186 * 2187 * @throws CmsException if the login was not successful 2188 */ 2189 public String loginUser(String username, String password) throws CmsException { 2190 2191 return loginUser(username, password, m_context.getRemoteAddress()); 2192 } 2193 2194 /** 2195 * Logs a user with a given ip address into the Cms, if the password is correct.<p> 2196 * 2197 * @param username the name of the user 2198 * @param password the password of the user 2199 * @param remoteAddress the ip address 2200 * 2201 * @return the name of the logged in user 2202 * 2203 * @throws CmsException if the login was not successful 2204 */ 2205 public String loginUser(String username, String password, String remoteAddress) throws CmsException { 2206 2207 // login the user 2208 CmsUser newUser = m_securityManager.loginUser(m_context, username, password, remoteAddress); 2209 // set the project back to the "Online" project 2210 CmsProject newProject = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID); 2211 // switch the cms context to the new user and project 2212 m_context.switchUser(newUser, newProject, newUser.getOuFqn()); 2213 // init this CmsObject with the new user 2214 init(m_securityManager, m_context); 2215 // fire a login event 2216 fireEvent(I_CmsEventListener.EVENT_LOGIN_USER, newUser); 2217 // return the users login name 2218 return newUser.getName(); 2219 } 2220 2221 /** 2222 * Lookups and reads the user or group with the given UUID.<p> 2223 * 2224 * @param principalId the uuid of a user or group 2225 * 2226 * @return the user or group with the given UUID 2227 */ 2228 public I_CmsPrincipal lookupPrincipal(CmsUUID principalId) { 2229 2230 return m_securityManager.lookupPrincipal(m_context, principalId); 2231 } 2232 2233 /** 2234 * Lookups and reads the user or group with the given name.<p> 2235 * 2236 * @param principalName the name of the user or group 2237 * 2238 * @return the user or group with the given name 2239 */ 2240 public I_CmsPrincipal lookupPrincipal(String principalName) { 2241 2242 return m_securityManager.lookupPrincipal(m_context, principalName); 2243 } 2244 2245 /** 2246 * Moves a resource to the given destination.<p> 2247 * 2248 * A move operation in OpenCms is always a copy (as sibling) followed by a delete, 2249 * this is a result of the online/offline structure of the 2250 * OpenCms VFS. This way you can see the deleted files/folders in the offline 2251 * project, and you will be unable to undelete them.<p> 2252 * 2253 * @param source the name of the resource to move (full current site relative path) 2254 * @param destination the destination resource name (full current site relative path) 2255 * 2256 * @throws CmsException if something goes wrong 2257 * 2258 * @see #renameResource(String, String) 2259 */ 2260 public void moveResource(String source, String destination) throws CmsException { 2261 2262 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 2263 getResourceType(resource).moveResource(this, m_securityManager, resource, destination); 2264 } 2265 2266 /** 2267 * Moves a resource to the "lost and found" folder.<p> 2268 * 2269 * The "lost and found" folder is a special system folder. 2270 * 2271 * This operation is used e.g. during import of resources 2272 * when a resource with the same name but a different resource ID 2273 * already exists in the VFS. In this case, the imported resource is 2274 * moved to the "lost and found" folder.<p> 2275 * 2276 * @param resourcename the name of the resource to move to "lost and found" (full current site relative path) 2277 * 2278 * @return the name of the resource inside the "lost and found" folder 2279 * 2280 * @throws CmsException if something goes wrong 2281 * 2282 * @see #getLostAndFoundName(String) 2283 */ 2284 public String moveToLostAndFound(String resourcename) throws CmsException { 2285 2286 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2287 return m_securityManager.moveToLostAndFound(m_context, resource, false); 2288 } 2289 2290 /** 2291 * Reads all available versions for a given resource.<p> 2292 * 2293 * @param resource the resource for which to read the versions 2294 * @return the list of historical versions of the resource 2295 * 2296 * @throws CmsException if something goes wrong 2297 */ 2298 public List<I_CmsHistoryResource> readAllAvailableVersions(CmsResource resource) throws CmsException { 2299 2300 return m_securityManager.readAllAvailableVersions(m_context, resource); 2301 } 2302 2303 /** 2304 * Reads all historical versions of a resource.<br> 2305 * 2306 * The reading excludes the file content, if the resource is a file.<p> 2307 * 2308 * @param resourceName the name of the resource to be read 2309 * 2310 * @return a list of historical resources, as <code>{@link I_CmsHistoryResource}</code> objects 2311 * 2312 * @throws CmsException if operation was not successful 2313 */ 2314 public List<I_CmsHistoryResource> readAllAvailableVersions(String resourceName) throws CmsException { 2315 2316 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 2317 return m_securityManager.readAllAvailableVersions(m_context, resource); 2318 } 2319 2320 /** 2321 * Reads all property definitions.<p> 2322 * 2323 * @return a list with the <code>{@link CmsPropertyDefinition}</code> objects (may be empty) 2324 * 2325 * @throws CmsException if something goes wrong 2326 */ 2327 public List<CmsPropertyDefinition> readAllPropertyDefinitions() throws CmsException { 2328 2329 return m_securityManager.readAllPropertyDefinitions(m_context); 2330 } 2331 2332 /** 2333 * Returns the first ancestor folder matching the filter criteria.<p> 2334 * 2335 * If no folder matching the filter criteria is found, null is returned.<p> 2336 * 2337 * @param resourcename the name of the resource to start (full current site relative path) 2338 * @param filter the resource filter to match while reading the ancestors 2339 * 2340 * @return the first ancestor folder matching the filter criteria or null if no folder was found 2341 * 2342 * @throws CmsException if something goes wrong 2343 */ 2344 public CmsFolder readAncestor(String resourcename, CmsResourceFilter filter) throws CmsException { 2345 2346 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2347 return m_securityManager.readAncestor(m_context, resource, filter); 2348 } 2349 2350 /** 2351 * Returns the first ancestor folder matching the resource type.<p> 2352 * 2353 * If no folder with the requested resource type is found, null is returned.<p> 2354 * 2355 * @param resourcename the name of the resource to start (full current site relative path) 2356 * @param type the resource type of the folder to match 2357 * 2358 * @return the first ancestor folder matching the filter criteria or null if no folder was found 2359 * 2360 * @throws CmsException if something goes wrong 2361 */ 2362 @SuppressWarnings("deprecation") 2363 public CmsFolder readAncestor(String resourcename, int type) throws CmsException { 2364 2365 return readAncestor(resourcename, CmsResourceFilter.requireType(type)); 2366 } 2367 2368 /** 2369 * Reads the newest URL name which is mapped to the given structure id.<p> 2370 * 2371 * If the structure id is not mapped to any name, null will be returned.<p> 2372 * 2373 * @param id the structure id for which the newest mapped name should be returned 2374 * @param locale the locale for which the URL name should be selected if possible 2375 * @param defaultLocales the default locales which should be used if the locale is not available 2376 * @return an URL name or null 2377 * @throws CmsException if something goes wrong 2378 */ 2379 public String readBestUrlName(CmsUUID id, Locale locale, List<Locale> defaultLocales) throws CmsException { 2380 2381 return m_securityManager.readBestUrlName(m_context, id, locale, defaultLocales); 2382 } 2383 2384 /** 2385 * Returns the default resource for the given folder.<p> 2386 * <ol> 2387 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2388 * <li>if still no file could be found, the configured default files in the 2389 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2390 * found, and 2391 * <li>if still no file could be found, <code>null</code> is returned 2392 * </ol> 2393 * 2394 * @param folderResource the folder 2395 * @param resourceFilter the resource filter 2396 * 2397 * @return the default file for the given folder 2398 * 2399 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2400 */ 2401 public CmsResource readDefaultFile(CmsResource folderResource, CmsResourceFilter resourceFilter) 2402 throws CmsSecurityException { 2403 2404 return m_securityManager.readDefaultFile(m_context, folderResource, resourceFilter); 2405 } 2406 2407 /** 2408 * Returns the default resource for the given folder.<p> 2409 * 2410 * If the given resource name or id identifies a file, then this file is returned.<p> 2411 * 2412 * Otherwise, in case of a folder:<br> 2413 * <ol> 2414 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2415 * <li>if still no file could be found, the configured default files in the 2416 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2417 * found, and 2418 * <li>if still no file could be found, <code>null</code> is returned 2419 * </ol> 2420 * 2421 * @param resourceNameOrID the name or id of the folder to read the default file for 2422 * 2423 * @return the default file for the given folder 2424 * 2425 * @throws CmsException if something goes wrong 2426 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2427 */ 2428 public CmsResource readDefaultFile(String resourceNameOrID) throws CmsException, CmsSecurityException { 2429 2430 return readDefaultFile(resourceNameOrID, CmsResourceFilter.DEFAULT); 2431 } 2432 2433 /** 2434 * Returns the default resource for the given folder.<p> 2435 * 2436 * If the given resource name or id identifies a file, then this file is returned.<p> 2437 * 2438 * Otherwise, in case of a folder:<br> 2439 * <ol> 2440 * <li>the {@link CmsPropertyDefinition#PROPERTY_DEFAULT_FILE} is checked, and 2441 * <li>if still no file could be found, the configured default files in the 2442 * <code>opencms-vfs.xml</code> configuration are iterated until a match is 2443 * found, and 2444 * <li>if still no file could be found, <code>null</code> is returned 2445 * </ol> 2446 * 2447 * @param resourceNameOrID the name or id of the folder to read the default file for# 2448 * @param filter the resource filter to use for reading the resources 2449 * 2450 * @return the default file for the given folder 2451 * 2452 * @throws CmsException if something goes wrong 2453 * @throws CmsSecurityException if the user has no permissions to read the resulting file 2454 */ 2455 public CmsResource readDefaultFile(String resourceNameOrID, CmsResourceFilter filter) 2456 throws CmsException, CmsSecurityException { 2457 2458 CmsResource resource; 2459 if (CmsUUID.isValidUUID(resourceNameOrID)) { 2460 resource = readResource(new CmsUUID(resourceNameOrID), filter); 2461 } else { 2462 resource = readResource(resourceNameOrID, filter); 2463 } 2464 return m_securityManager.readDefaultFile(m_context, resource, filter); 2465 } 2466 2467 /** 2468 * Reads all deleted (historical) resources below the given path, 2469 * including the full tree below the path, if required.<p> 2470 * 2471 * The result list may include resources with the same name of 2472 * resources (with different id's).<p> 2473 * 2474 * Use in conjunction with the {@link #restoreDeletedResource(CmsUUID)} 2475 * method.<p> 2476 * 2477 * @param resourcename the parent path to read the resources from 2478 * @param readTree <code>true</code> to read all sub resources 2479 * 2480 * @return a list of <code>{@link I_CmsHistoryResource}</code> objects 2481 * 2482 * @throws CmsException if something goes wrong 2483 * 2484 * @see #readResource(CmsUUID, int) 2485 * @see #readResources(String, CmsResourceFilter, boolean) 2486 */ 2487 public List<I_CmsHistoryResource> readDeletedResources(String resourcename, boolean readTree) throws CmsException { 2488 2489 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2490 return m_securityManager.readDeletedResources(m_context, resource, readTree); 2491 } 2492 2493 /** 2494 * Reads a file resource (including it's binary content) from the VFS, 2495 * for the given resource (this may also be an historical version of the resource).<p> 2496 * 2497 * In case the input {@link CmsResource} object already is a {@link CmsFile} with contents 2498 * available, it is casted to a file and returned unchanged. Otherwise the file is read 2499 * from the VFS.<p> 2500 * 2501 * In case you do not need the file content, 2502 * use <code>{@link #readResource(String)}</code> or 2503 * <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p> 2504 * 2505 * No resource filter is applied when reading the resource, since we already have 2506 * a full resource instance and assume we just want the content for that instance. 2507 * In case you need to apply a filter, use {@link #readFile(String, CmsResourceFilter)} instead.<p> 2508 * 2509 * @param resource the resource to read 2510 * 2511 * @return the file resource that was read 2512 * 2513 * @throws CmsException if the file resource could not be read for any reason 2514 * 2515 * @see #readFile(String) 2516 * @see #readFile(String, CmsResourceFilter) 2517 */ 2518 public CmsFile readFile(CmsResource resource) throws CmsException { 2519 2520 // test if we already have a file 2521 if (resource instanceof CmsFile) { 2522 // resource is already a file 2523 CmsFile file = (CmsFile)resource; 2524 if ((file.getContents() != null) && (file.getContents().length > 0)) { 2525 // file has the contents already available 2526 return file; 2527 } 2528 } 2529 2530 return m_securityManager.readFile(m_context, resource); 2531 } 2532 2533 /** 2534 * Reads a file resource (including it's binary content) from the VFS, 2535 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 2536 * 2537 * In case you do not need the file content, 2538 * use <code>{@link #readResource(String)}</code> instead.<p> 2539 * 2540 * @param resourcename the name of the resource to read (full current site relative path) 2541 * 2542 * @return the file resource that was read 2543 * 2544 * @throws CmsException if the file resource could not be read for any reason 2545 * 2546 * @see #readFile(String, CmsResourceFilter) 2547 * @see #readFile(CmsResource) 2548 * @see #readResource(String) 2549 */ 2550 public CmsFile readFile(String resourcename) throws CmsException { 2551 2552 return readFile(resourcename, CmsResourceFilter.DEFAULT); 2553 } 2554 2555 /** 2556 * Reads a file resource (including it's binary content) from the VFS, 2557 * using the specified resource filter.<p> 2558 * 2559 * In case you do not need the file content, 2560 * use <code>{@link #readResource(String, CmsResourceFilter)}</code> instead.<p> 2561 * 2562 * The specified filter controls what kind of resources should be "found" 2563 * during the read operation. This will depend on the application. For example, 2564 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 2565 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 2566 * will ignore the date release / date expired information of the resource.<p> 2567 * 2568 * @param resourcename the name of the resource to read (full current site relative path) 2569 * @param filter the resource filter to use while reading 2570 * 2571 * @return the file resource that was read 2572 * 2573 * @throws CmsException if the file resource could not be read for any reason 2574 * 2575 * @see #readFile(String) 2576 * @see #readFile(CmsResource) 2577 * @see #readResource(String, CmsResourceFilter) 2578 */ 2579 public CmsFile readFile(String resourcename, CmsResourceFilter filter) throws CmsException { 2580 2581 CmsResource resource = readResource(resourcename, filter); 2582 return readFile(resource); 2583 } 2584 2585 /** 2586 * Reads a folder resource from the VFS, 2587 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 2588 * 2589 * @param resourcename the name of the folder resource to read (full current site relative path) 2590 * 2591 * @return the folder resource that was read 2592 * 2593 * @throws CmsException if the resource could not be read for any reason 2594 * 2595 * @see #readResource(String, CmsResourceFilter) 2596 * @see #readFolder(String, CmsResourceFilter) 2597 */ 2598 public CmsFolder readFolder(String resourcename) throws CmsException { 2599 2600 return readFolder(resourcename, CmsResourceFilter.DEFAULT); 2601 } 2602 2603 /** 2604 * Reads a folder resource from the VFS, 2605 * using the specified resource filter.<p> 2606 * 2607 * The specified filter controls what kind of resources should be "found" 2608 * during the read operation. This will depend on the application. For example, 2609 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 2610 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 2611 * will ignore the date release / date expired information of the resource.<p> 2612 * 2613 * @param resourcename the name of the folder resource to read (full current site relative path) 2614 * @param filter the resource filter to use while reading 2615 * 2616 * @return the folder resource that was read 2617 * 2618 * @throws CmsException if the resource could not be read for any reason 2619 * 2620 * @see #readResource(String, CmsResourceFilter) 2621 */ 2622 public CmsFolder readFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 2623 2624 return m_securityManager.readFolder(m_context, addSiteRoot(resourcename), filter); 2625 } 2626 2627 /** 2628 * Reads the group of a project.<p> 2629 * 2630 * @param project the project to read the group from 2631 * 2632 * @return the group of the given project 2633 */ 2634 public CmsGroup readGroup(CmsProject project) { 2635 2636 return m_securityManager.readGroup(m_context, project); 2637 } 2638 2639 /** 2640 * Reads a group based on its id.<p> 2641 * 2642 * @param groupId the id of the group to be read 2643 * 2644 * @return the group that has the provided id 2645 * 2646 * @throws CmsException if something goes wrong 2647 * 2648 * @see #readHistoryPrincipal(CmsUUID) for retrieving deleted groups 2649 */ 2650 public CmsGroup readGroup(CmsUUID groupId) throws CmsException { 2651 2652 return m_securityManager.readGroup(m_context, groupId); 2653 } 2654 2655 /** 2656 * Reads a group based on its name.<p> 2657 * 2658 * @param groupName the name of the group to be read 2659 * 2660 * @return the group that has the provided name 2661 * 2662 * @throws CmsException if something goes wrong 2663 */ 2664 public CmsGroup readGroup(String groupName) throws CmsException { 2665 2666 return m_securityManager.readGroup(m_context, groupName); 2667 } 2668 2669 /** 2670 * Reads a principal (an user or group) from the historical archive based on its ID.<p> 2671 * 2672 * @param principalId the id of the principal to read 2673 * 2674 * @return the historical principal entry with the given id 2675 * 2676 * @throws CmsException if something goes wrong, ie. {@link org.opencms.db.CmsDbEntryNotFoundException} 2677 * 2678 * @see #readUser(CmsUUID) 2679 * @see #readGroup(CmsUUID) 2680 */ 2681 public CmsHistoryPrincipal readHistoryPrincipal(CmsUUID principalId) throws CmsException { 2682 2683 return m_securityManager.readHistoricalPrincipal(m_context, principalId); 2684 } 2685 2686 /** 2687 * Returns the latest historical project entry with the given id.<p> 2688 * 2689 * @param projectId the project id 2690 * 2691 * @return the requested historical project entry 2692 * 2693 * @throws CmsException if operation was not successful 2694 */ 2695 public CmsHistoryProject readHistoryProject(CmsUUID projectId) throws CmsException { 2696 2697 return (m_securityManager.readHistoryProject(m_context, projectId)); 2698 } 2699 2700 /** 2701 * Returns a historical project entry.<p> 2702 * 2703 * @param publishTag publish tag of the project 2704 * 2705 * @return the requested historical project entry 2706 * 2707 * @throws CmsException if operation was not successful 2708 */ 2709 public CmsHistoryProject readHistoryProject(int publishTag) throws CmsException { 2710 2711 return (m_securityManager.readHistoryProject(m_context, publishTag)); 2712 } 2713 2714 /** 2715 * Reads the list of all <code>{@link CmsProperty}</code> objects that belong to the given historical resource version.<p> 2716 * 2717 * @param resource the historical resource version to read the properties for 2718 * 2719 * @return the list of <code>{@link CmsProperty}</code> objects 2720 * 2721 * @throws CmsException if something goes wrong 2722 */ 2723 public List<CmsProperty> readHistoryPropertyObjects(I_CmsHistoryResource resource) throws CmsException { 2724 2725 return m_securityManager.readHistoryPropertyObjects(m_context, resource); 2726 } 2727 2728 /** 2729 * This method retrieves the structure id which is mapped to a given URL name.<p> 2730 * 2731 * If there is no structure id mapped to the given name, null will be returned.<p> 2732 * 2733 * However if the parameter is a string which represents a valid uuid, it will be directly returned as a {@link CmsUUID} instance.<p> 2734 * 2735 * @param name the url name 2736 * @return the id which is mapped to the URL name 2737 * 2738 * @throws CmsException if something goes wrong 2739 */ 2740 public CmsUUID readIdForUrlName(String name) throws CmsException { 2741 2742 if (CmsUUID.isValidUUID(name)) { 2743 return new CmsUUID(name); 2744 } 2745 return m_securityManager.readIdForUrlName(m_context, name); 2746 } 2747 2748 /** 2749 * Returns the project manager group of a project.<p> 2750 * 2751 * @param project the project 2752 * 2753 * @return the manager group of the project 2754 */ 2755 public CmsGroup readManagerGroup(CmsProject project) { 2756 2757 return m_securityManager.readManagerGroup(m_context, project); 2758 } 2759 2760 /** 2761 * Reads the owner of a project.<p> 2762 * 2763 * @param project the project to read the owner from 2764 * 2765 * @return the owner of the project 2766 * 2767 * @throws CmsException if something goes wrong 2768 */ 2769 public CmsUser readOwner(CmsProject project) throws CmsException { 2770 2771 return m_securityManager.readOwner(m_context, project); 2772 } 2773 2774 /** 2775 * Returns the parent folder to the given structure id.<p> 2776 * 2777 * @param structureId the child structure id 2778 * 2779 * @return the parent folder <code>{@link CmsResource}</code> 2780 * 2781 * @throws CmsException if something goes wrong 2782 */ 2783 public CmsResource readParentFolder(CmsUUID structureId) throws CmsException { 2784 2785 return m_securityManager.readParentFolder(m_context, structureId); 2786 } 2787 2788 /** 2789 * Builds a list of resources for a given path.<p> 2790 * 2791 * @param resource the resource to read the path for 2792 * @param filter a filter object (only "includeDeleted" information is used!) 2793 * 2794 * @return list of <code>{@link CmsResource}</code>s 2795 * 2796 * @throws CmsException if something goes wrong 2797 */ 2798 public List<CmsResource> readPath(CmsResource resource, CmsResourceFilter filter) throws CmsException { 2799 2800 return m_securityManager.readPath(m_context, resource.getRootPath(), filter); 2801 } 2802 2803 /** 2804 * Builds a list of resources for a given path.<p> 2805 * 2806 * @param path the requested path 2807 * @param filter a filter object (only "includeDeleted" information is used!) 2808 * 2809 * @return list of <code>{@link CmsResource}</code>s 2810 * 2811 * @throws CmsException if something goes wrong 2812 */ 2813 public List<CmsResource> readPath(String path, CmsResourceFilter filter) throws CmsException { 2814 2815 return m_securityManager.readPath(m_context, addSiteRoot(path), filter); 2816 } 2817 2818 /** 2819 * Reads the project with the given id.<p> 2820 * 2821 * @param id the id of the project 2822 * 2823 * @return the project with the given id 2824 * 2825 * @throws CmsException if operation was not successful 2826 */ 2827 public CmsProject readProject(CmsUUID id) throws CmsException { 2828 2829 return m_securityManager.readProject(id); 2830 } 2831 2832 /** 2833 * Reads the project with the given name.<p> 2834 * 2835 * @param name the name of the project 2836 * 2837 * @return the project with the given name 2838 * 2839 * @throws CmsException if operation was not successful 2840 */ 2841 public CmsProject readProject(String name) throws CmsException { 2842 2843 return m_securityManager.readProject(name); 2844 } 2845 2846 /** 2847 * Returns the list of all resource names that define the "view" of the given project.<p> 2848 * 2849 * @param project the project to get the project resources for 2850 * 2851 * @return the list of all resource names (root paths), as <code>{@link String}</code> 2852 * objects that define the "view" of the given project 2853 * 2854 * @throws CmsException if something goes wrong 2855 */ 2856 public List<String> readProjectResources(CmsProject project) throws CmsException { 2857 2858 return m_securityManager.readProjectResources(m_context, project); 2859 } 2860 2861 /** 2862 * Reads all resources of a project that match a given state from the VFS.<p> 2863 * 2864 * Possible values for the <code>state</code> parameter are:<br> 2865 * <ul> 2866 * <li><code>{@link CmsResource#STATE_CHANGED}</code>: Read all "changed" resources in the project</li> 2867 * <li><code>{@link CmsResource#STATE_NEW}</code>: Read all "new" resources in the project</li> 2868 * <li><code>{@link CmsResource#STATE_DELETED}</code>: Read all "deleted" resources in the project</li> 2869 * <li><code>{@link CmsResource#STATE_KEEP}</code>: Read all resources either "changed", "new" or "deleted" in the project</li> 2870 * </ul><p> 2871 * 2872 * @param projectId the id of the project to read the file resources for 2873 * @param state the resource state to match 2874 * 2875 * @return all <code>{@link CmsResource}</code>s of a project that match a given criteria from the VFS 2876 * 2877 * @throws CmsException if something goes wrong 2878 */ 2879 public List<CmsResource> readProjectView(CmsUUID projectId, CmsResourceState state) throws CmsException { 2880 2881 return m_securityManager.readProjectView(m_context, projectId, state); 2882 } 2883 2884 /** 2885 * Reads a property definition.<p> 2886 * 2887 * If no property definition with the given name is found, 2888 * <code>null</code> is returned.<p> 2889 * 2890 * @param name the name of the property definition to read 2891 * 2892 * @return the property definition that was read 2893 * 2894 * @throws CmsException a CmsDbEntryNotFoundException is thrown if the property definition does not exist 2895 */ 2896 public CmsPropertyDefinition readPropertyDefinition(String name) throws CmsException { 2897 2898 return (m_securityManager.readPropertyDefinition(m_context, name)); 2899 } 2900 2901 /** 2902 * Reads a property object from a resource specified by a property name.<p> 2903 * 2904 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2905 * 2906 * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code> 2907 * if you already have an instance of the resource to look up the property from.<p> 2908 * 2909 * @param resource the resource where the property is attached to 2910 * @param property the property name 2911 * @param search if true, the property is searched on all parent folders of the resource, 2912 * if it's not found attached directly to the resource 2913 * 2914 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2915 * 2916 * @throws CmsException if something goes wrong 2917 */ 2918 public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException { 2919 2920 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2921 } 2922 2923 /** 2924 * Reads the locale specific version of a property object from a resource specified by a property name.<p> 2925 * 2926 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2927 * 2928 * This method is more efficient then using <code>{@link CmsObject#readPropertyObject(String, String, boolean)}</code> 2929 * if you already have an instance of the resource to look up the property from.<p> 2930 * 2931 * @param resource the resource where the property is attached to 2932 * @param property the property name 2933 * @param search if true, the property is searched on all parent folders of the resource, 2934 * if it's not found attached directly to the resource 2935 * @param locale the locale for which the property should be read. 2936 * 2937 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2938 * 2939 * @throws CmsException if something goes wrong 2940 */ 2941 public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search, Locale locale) 2942 throws CmsException { 2943 2944 return m_securityManager.readPropertyObject(m_context, resource, property, search, locale); 2945 } 2946 2947 /** 2948 * Reads a property object from a resource specified by a property name.<p> 2949 * 2950 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2951 * 2952 * @param resourcePath the name of resource where the property is attached to 2953 * @param property the property name 2954 * @param search if true, the property is searched on all parent folders of the resource, 2955 * if it's not found attached directly to the resource 2956 * 2957 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2958 * 2959 * @throws CmsException if something goes wrong 2960 */ 2961 public CmsProperty readPropertyObject(String resourcePath, String property, boolean search) throws CmsException { 2962 2963 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2964 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2965 } 2966 2967 /** 2968 * Reads the locale specific version of a property object from a resource specified by a property name.<p> 2969 * 2970 * Returns <code>{@link CmsProperty#getNullProperty()}</code> if the property is not found.<p> 2971 * 2972 * @param resourcePath the name of resource where the property is attached to 2973 * @param property the property name 2974 * @param search if true, the property is searched on all parent folders of the resource, 2975 * if it's not found attached directly to the resource 2976 * @param locale the locale for which the property should be read. 2977 * 2978 * @return the required property, or <code>{@link CmsProperty#getNullProperty()}</code> if the property was not found 2979 * 2980 * @throws CmsException if something goes wrong 2981 */ 2982 public CmsProperty readPropertyObject(String resourcePath, String property, boolean search, Locale locale) 2983 throws CmsException { 2984 2985 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2986 return m_securityManager.readPropertyObject(m_context, resource, property, search, locale); 2987 } 2988 2989 /** 2990 * Reads all property objects from a resource.<p> 2991 * 2992 * Returns an empty list if no properties are found.<p> 2993 * 2994 * This method is more efficient then using <code>{@link CmsObject#readPropertyObjects(String, boolean)}</code> 2995 * if you already have an instance of the resource to look up the property from.<p> 2996 * 2997 * If the <code>search</code> parameter is <code>true</code>, the properties of all 2998 * parent folders of the resource are also read. The results are merged with the 2999 * properties directly attached to the resource. While merging, a property 3000 * on a parent folder that has already been found will be ignored. 3001 * So e.g. if a resource has a property "Title" attached, and it's parent folder 3002 * has the same property attached but with a different value, the result list will 3003 * contain only the property with the value from the resource, not form the parent folder(s).<p> 3004 * 3005 * @param resource the resource where the property is mapped to 3006 * @param search if <code>true</code>, the properties of all parent folders of the resource 3007 * are merged with the resource properties. 3008 * 3009 * @return a list of <code>{@link CmsProperty}</code> objects 3010 * 3011 * @throws CmsException if something goes wrong 3012 */ 3013 public List<CmsProperty> readPropertyObjects(CmsResource resource, boolean search) throws CmsException { 3014 3015 return m_securityManager.readPropertyObjects(m_context, resource, search); 3016 } 3017 3018 /** 3019 * Reads all property objects from a resource.<p> 3020 * 3021 * Returns an empty list if no properties are found.<p> 3022 * 3023 * All properties in the result List will be in frozen (read only) state, so you can't change the values.<p> 3024 * 3025 * If the <code>search</code> parameter is <code>true</code>, the properties of all 3026 * parent folders of the resource are also read. The results are merged with the 3027 * properties directly attached to the resource. While merging, a property 3028 * on a parent folder that has already been found will be ignored. 3029 * So e.g. if a resource has a property "Title" attached, and it's parent folder 3030 * has the same property attached but with a different value, the result list will 3031 * contain only the property with the value from the resource, not form the parent folder(s).<p> 3032 * 3033 * @param resourcePath the name of resource where the property is mapped to 3034 * @param search if <code>true</code>, the properties of all parent folders of the resource 3035 * are merged with the resource properties. 3036 * 3037 * @return a list of <code>{@link CmsProperty}</code> objects 3038 * 3039 * @throws CmsException if something goes wrong 3040 */ 3041 public List<CmsProperty> readPropertyObjects(String resourcePath, boolean search) throws CmsException { 3042 3043 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 3044 return m_securityManager.readPropertyObjects(m_context, resource, search); 3045 } 3046 3047 /** 3048 * Reads the resources that were published in a publish task for a given publish history ID.<p> 3049 * 3050 * @param publishHistoryId unique ID to identify each publish task in the publish history 3051 * 3052 * @return a list of <code>{@link org.opencms.db.CmsPublishedResource}</code> objects 3053 * 3054 * @throws CmsException if something goes wrong 3055 */ 3056 public List<CmsPublishedResource> readPublishedResources(CmsUUID publishHistoryId) throws CmsException { 3057 3058 return m_securityManager.readPublishedResources(m_context, publishHistoryId); 3059 } 3060 3061 /** 3062 * Returns all relations matching the given filter.<p> 3063 * 3064 * @param filter the filter to match the relation 3065 * 3066 * @return all relations matching the given filter 3067 * 3068 * @throws CmsException if something goes wrong 3069 * 3070 * @see CmsSecurityManager#getRelationsForResource(CmsRequestContext, CmsResource, CmsRelationFilter) 3071 * @see #getRelationsForResource(CmsResource, CmsRelationFilter) 3072 */ 3073 public List<CmsRelation> readRelations(CmsRelationFilter filter) throws CmsException { 3074 3075 return m_securityManager.getRelationsForResource(m_context, null, filter); 3076 } 3077 3078 /** 3079 * Reads a resource from the VFS, 3080 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 3081 * 3082 * A resource may be of type <code>{@link CmsFile}</code> or 3083 * <code>{@link CmsFolder}</code>. In case of 3084 * a file, the resource will not contain the binary file content. Since reading 3085 * the binary content is a cost-expensive database operation, it's recommended 3086 * to work with resources if possible, and only read the file content when absolutely 3087 * required. To "upgrade" a resource to a file, 3088 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3089 * 3090 * @param structureID the structure ID of the resource to read 3091 * 3092 * @return the resource that was read 3093 * 3094 * @throws CmsException if the resource could not be read for any reason 3095 * 3096 * @see #readFile(String) 3097 * @see #readResource(CmsUUID, CmsResourceFilter) 3098 */ 3099 public CmsResource readResource(CmsUUID structureID) throws CmsException { 3100 3101 return readResource(structureID, CmsResourceFilter.DEFAULT); 3102 } 3103 3104 /** 3105 * Reads a resource from the VFS, 3106 * using the specified resource filter.<p> 3107 * 3108 * A resource may be of type <code>{@link CmsFile}</code> or 3109 * <code>{@link CmsFolder}</code>. In case of 3110 * a file, the resource will not contain the binary file content. Since reading 3111 * the binary content is a cost-expensive database operation, it's recommended 3112 * to work with resources if possible, and only read the file content when absolutely 3113 * required. To "upgrade" a resource to a file, 3114 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3115 * 3116 * The specified filter controls what kind of resources should be "found" 3117 * during the read operation. This will depend on the application. For example, 3118 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 3119 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 3120 * will ignore the date release / date expired information of the resource.<p> 3121 * 3122 * @param structureID the structure ID of the resource to read 3123 * @param filter the resource filter to use while reading 3124 * 3125 * @return the resource that was read 3126 * 3127 * @throws CmsException if the resource could not be read for any reason 3128 * 3129 * @see #readFile(String, CmsResourceFilter) 3130 * @see #readFolder(String, CmsResourceFilter) 3131 */ 3132 public CmsResource readResource(CmsUUID structureID, CmsResourceFilter filter) throws CmsException { 3133 3134 return m_securityManager.readResource(m_context, structureID, filter); 3135 } 3136 3137 /** 3138 * Reads the historical resource with the given version for the resource given 3139 * the given structure id.<p> 3140 * 3141 * A resource may be of type <code>{@link CmsFile}</code> or 3142 * <code>{@link CmsFolder}</code>. In case of a file, the resource will not 3143 * contain the binary file content. Since reading the binary content is a 3144 * cost-expensive database operation, it's recommended to work with resources 3145 * if possible, and only read the file content when absolutely required. To 3146 * "upgrade" a resource to a file, use 3147 * <code>{@link #readFile(CmsResource)}</code>.<p> 3148 * 3149 * Please note that historical versions are just generated during publishing, 3150 * so the first version with version number 1 is generated during publishing 3151 * of a new resource (exception is a new sibling, that may also contain some 3152 * relevant versions of already published siblings) and the last version 3153 * available is the version of the current online resource.<p> 3154 * 3155 * @param structureID the structure ID of the resource to read 3156 * @param version the version number you want to retrieve 3157 * 3158 * @return the resource that was read 3159 * 3160 * @throws CmsException if the resource could not be read for any reason 3161 * @throws CmsVfsResourceNotFoundException if the version does not exists 3162 * 3163 * @see #restoreResourceVersion(CmsUUID, int) 3164 */ 3165 public I_CmsHistoryResource readResource(CmsUUID structureID, int version) 3166 throws CmsException, CmsVfsResourceNotFoundException { 3167 3168 CmsResource resource = readResource(structureID, CmsResourceFilter.ALL); 3169 return m_securityManager.readResource(m_context, resource, version); 3170 } 3171 3172 /** 3173 * Reads a resource from the VFS, 3174 * using the <code>{@link CmsResourceFilter#DEFAULT}</code> filter.<p> 3175 * 3176 * A resource may be of type <code>{@link CmsFile}</code> or 3177 * <code>{@link CmsFolder}</code>. In case of 3178 * a file, the resource will not contain the binary file content. Since reading 3179 * the binary content is a cost-expensive database operation, it's recommended 3180 * to work with resources if possible, and only read the file content when absolutely 3181 * required. To "upgrade" a resource to a file, 3182 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3183 * 3184 * @param resourcename the name of the resource to read (full current site relative path) 3185 * 3186 * @return the resource that was read 3187 * 3188 * @throws CmsException if the resource could not be read for any reason 3189 * 3190 * @see #readFile(String) 3191 * @see #readResource(String, CmsResourceFilter) 3192 */ 3193 public CmsResource readResource(String resourcename) throws CmsException { 3194 3195 return readResource(resourcename, CmsResourceFilter.DEFAULT); 3196 } 3197 3198 /** 3199 * Reads a resource from the VFS, 3200 * using the specified resource filter.<p> 3201 * 3202 * A resource may be of type <code>{@link CmsFile}</code> or 3203 * <code>{@link CmsFolder}</code>. In case of 3204 * a file, the resource will not contain the binary file content. Since reading 3205 * the binary content is a cost-expensive database operation, it's recommended 3206 * to work with resources if possible, and only read the file content when absolutely 3207 * required. To "upgrade" a resource to a file, 3208 * use <code>{@link #readFile(CmsResource)}</code>.<p> 3209 * 3210 * The specified filter controls what kind of resources should be "found" 3211 * during the read operation. This will depend on the application. For example, 3212 * using <code>{@link CmsResourceFilter#DEFAULT}</code> will only return currently 3213 * "valid" resources, while using <code>{@link CmsResourceFilter#IGNORE_EXPIRATION}</code> 3214 * will ignore the date release / date expired information of the resource.<p> 3215 * 3216 * @param resourcename the name of the resource to read (full current site relative path) 3217 * @param filter the resource filter to use while reading 3218 * 3219 * @return the resource that was read 3220 * 3221 * @throws CmsException if the resource could not be read for any reason 3222 * 3223 * @see #readFile(String, CmsResourceFilter) 3224 * @see #readFolder(String, CmsResourceFilter) 3225 */ 3226 public CmsResource readResource(String resourcename, CmsResourceFilter filter) throws CmsException { 3227 3228 return m_securityManager.readResource(m_context, addSiteRoot(resourcename), filter); 3229 } 3230 3231 /** 3232 * Reads all resources below the given resource matching the filter criteria, 3233 * including the full tree below the path only in case the <code>readTree</code> 3234 * parameter is <code>true</code>.<p> 3235 * 3236 * @param resource the parent resource 3237 * @param filter the filter 3238 * @param readTree <code>true</code> to read all sub resources 3239 * 3240 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3241 * 3242 * @throws CmsException if something goes wrong 3243 */ 3244 public List<CmsResource> readResources(CmsResource resource, CmsResourceFilter filter, boolean readTree) 3245 throws CmsException { 3246 3247 if (readTree) { 3248 return m_securityManager.readResources(m_context, resource, filter, readTree); 3249 } else { 3250 return m_securityManager.readChildResources(m_context, resource, filter, true, true); 3251 } 3252 } 3253 3254 /** 3255 * Reads all resources below the given path matching the filter criteria, 3256 * including the full tree below the path.<p> 3257 * 3258 * @param resourcename the parent path to read the resources from 3259 * @param filter the filter 3260 * 3261 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3262 * 3263 * @throws CmsException if something goes wrong 3264 * 3265 * @see #readResources(String, CmsResourceFilter, boolean) 3266 */ 3267 public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter) throws CmsException { 3268 3269 return readResources(resourcename, filter, true); 3270 } 3271 3272 /** 3273 * Reads all resources below the given path matching the filter criteria, 3274 * including the full tree below the path only in case the <code>readTree</code> 3275 * parameter is <code>true</code>.<p> 3276 * 3277 * @param resourcename the parent path to read the resources from 3278 * @param filter the filter 3279 * @param readTree <code>true</code> to read all sub resources 3280 * 3281 * @return a list of <code>{@link CmsResource}</code> objects matching the filter criteria 3282 * 3283 * @throws CmsException if something goes wrong 3284 */ 3285 public List<CmsResource> readResources(String resourcename, CmsResourceFilter filter, boolean readTree) 3286 throws CmsException { 3287 3288 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3289 return m_securityManager.readResources(m_context, resource, filter, readTree); 3290 } 3291 3292 /** 3293 * Reads all resources that have a value set for the specified property.<p> 3294 * 3295 * Both individual and shared properties of a resource are checked.<p> 3296 * 3297 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3298 * 3299 * @param propertyDefinition the name of the property to check for 3300 * 3301 * @return a list of all <code>{@link CmsResource}</code> objects 3302 * that have a value set for the specified property. 3303 * 3304 * @throws CmsException if something goes wrong 3305 */ 3306 public List<CmsResource> readResourcesWithProperty(String propertyDefinition) throws CmsException { 3307 3308 return readResourcesWithProperty("/", propertyDefinition); 3309 } 3310 3311 /** 3312 * Reads all resources that have a value set for the specified property in the given path.<p> 3313 * 3314 * Both individual and shared properties of a resource are checked.<p> 3315 * 3316 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3317 * 3318 * @param path the folder to get the resources with the property from 3319 * @param propertyDefinition the name of the property to check for 3320 * 3321 * @return all <code>{@link CmsResource}</code> objects 3322 * that have a value set for the specified property in the given path. 3323 * 3324 * @throws CmsException if something goes wrong 3325 */ 3326 public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition) throws CmsException { 3327 3328 return readResourcesWithProperty(path, propertyDefinition, null); 3329 } 3330 3331 /** 3332 * Reads all resources that have a value (containing the specified value) set 3333 * for the specified property in the given path.<p> 3334 * 3335 * Both individual and shared properties of a resource are checked.<p> 3336 * 3337 * If the <code>value</code> parameter is <code>null</code>, all resources having the 3338 * given property set are returned.<p> 3339 * 3340 * Will use the {@link CmsResourceFilter#ALL} resource filter.<p> 3341 * 3342 * @param path the folder to get the resources with the property from 3343 * @param propertyDefinition the name of the property to check for 3344 * @param value the string to search in the value of the property 3345 * 3346 * @return all <code>{@link CmsResource}</code> objects 3347 * that have a value set for the specified property in the given path. 3348 * 3349 * @throws CmsException if something goes wrong 3350 */ 3351 public List<CmsResource> readResourcesWithProperty(String path, String propertyDefinition, String value) 3352 throws CmsException { 3353 3354 CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION); 3355 return m_securityManager.readResourcesWithProperty( 3356 m_context, 3357 resource, 3358 propertyDefinition, 3359 value, 3360 CmsResourceFilter.ALL); 3361 } 3362 3363 /** 3364 * Reads all resources that have a value (containing the specified value) set 3365 * for the specified property in the given path.<p> 3366 * 3367 * Both individual and shared properties of a resource are checked.<p> 3368 * 3369 * If the <code>value</code> parameter is <code>null</code>, all resources having the 3370 * given property set are returned.<p> 3371 * 3372 * Will use the given resource filter.<p> 3373 * 3374 * @param path the folder to get the resources with the property from 3375 * @param propertyDefinition the name of the property to check for 3376 * @param value the string to search in the value of the property 3377 * @param filter the resource filter to apply to the result set 3378 * 3379 * @return all <code>{@link CmsResource}</code> objects 3380 * that have a value set for the specified property in the given path. 3381 * 3382 * @throws CmsException if something goes wrong 3383 */ 3384 public List<CmsResource> readResourcesWithProperty( 3385 String path, 3386 String propertyDefinition, 3387 String value, 3388 CmsResourceFilter filter) 3389 throws CmsException { 3390 3391 CmsResource resource = readResource(path, CmsResourceFilter.IGNORE_EXPIRATION); 3392 return m_securityManager.readResourcesWithProperty(m_context, resource, propertyDefinition, value, filter); 3393 } 3394 3395 /** 3396 * Returns a set of principals that are responsible for a specific resource.<p> 3397 * 3398 * @param resource the resource to get the responsible principals from 3399 * 3400 * @return the set of principals that are responsible for a specific resource 3401 * 3402 * @throws CmsException if something goes wrong 3403 */ 3404 public Set<I_CmsPrincipal> readResponsiblePrincipals(CmsResource resource) throws CmsException { 3405 3406 return m_securityManager.readResponsiblePrincipals(m_context, resource); 3407 } 3408 3409 /** 3410 * Returns a set of users that are responsible for a specific resource.<p> 3411 * 3412 * @param resource the resource to get the responsible users from 3413 * 3414 * @return the set of users that are responsible for a specific resource 3415 * 3416 * @throws CmsException if something goes wrong 3417 */ 3418 public Set<CmsUser> readResponsibleUsers(CmsResource resource) throws CmsException { 3419 3420 return m_securityManager.readResponsibleUsers(m_context, resource); 3421 } 3422 3423 /** 3424 * Returns a list of all siblings of the specified resource, 3425 * the specified resource being always part of the result set.<p> 3426 * 3427 * @param resource the resource 3428 * @param filter a resource filter 3429 * 3430 * @return a list of <code>{@link CmsResource}</code>s that 3431 * are siblings to the specified resource, 3432 * including the specified resource itself. 3433 * 3434 * @throws CmsException if something goes wrong 3435 */ 3436 public List<CmsResource> readSiblings(CmsResource resource, CmsResourceFilter filter) throws CmsException { 3437 3438 return m_securityManager.readSiblings(m_context, resource, filter); 3439 } 3440 3441 /** 3442 * Returns a list of all siblings of the specified resource, 3443 * the specified resource being always part of the result set.<p> 3444 * 3445 * @param resourcename the name of the specified resource 3446 * @param filter a resource filter 3447 * 3448 * @return a list of <code>{@link CmsResource}</code>s that 3449 * are siblings to the specified resource, 3450 * including the specified resource itself. 3451 * 3452 * @throws CmsException if something goes wrong 3453 */ 3454 public List<CmsResource> readSiblings(String resourcename, CmsResourceFilter filter) throws CmsException { 3455 3456 CmsResource resource = readResource(resourcename, filter); 3457 return readSiblings(resource, filter); 3458 } 3459 3460 /** 3461 * Reads all resources with the given resource id.<p> 3462 * 3463 * @param resourceId the resource id for which we want the siblings 3464 * @param filter the resource filter used to read the resources 3465 * @return the siblings which share the given resource id 3466 * 3467 * @throws CmsException if something goes wrong 3468 */ 3469 public List<CmsResource> readSiblingsForResourceId(CmsUUID resourceId, CmsResourceFilter filter) 3470 throws CmsException { 3471 3472 CmsResource pseudoResource = new CmsResource( 3473 null, 3474 resourceId, 3475 null, 3476 0, 3477 false, 3478 0, 3479 null, 3480 null, 3481 0, 3482 null, 3483 0, 3484 null, 3485 0, 3486 0, 3487 0, 3488 0, 3489 0, 3490 0); 3491 return readSiblings(pseudoResource, filter); 3492 } 3493 3494 /** 3495 * Returns the parameters of a resource in the list of all published template resources.<p> 3496 * 3497 * @param rfsName the rfs name of the resource 3498 * 3499 * @return the parameter string of the requested resource 3500 * 3501 * @throws CmsException if something goes wrong 3502 */ 3503 public String readStaticExportPublishedResourceParameters(String rfsName) throws CmsException { 3504 3505 return m_securityManager.readStaticExportPublishedResourceParameters(m_context, rfsName); 3506 } 3507 3508 /** 3509 * Returns a list of all template resources which must be processed during a static export.<p> 3510 * 3511 * @param parameterResources flag for reading resources with parameters (1) or without (0) 3512 * 3513 * @param timestamp a time stamp for reading the data from the db 3514 * 3515 * @return a list of template resources as <code>{@link String}</code> objects 3516 * 3517 * @throws CmsException if something goes wrong 3518 */ 3519 public List<String> readStaticExportResources(int parameterResources, long timestamp) throws CmsException { 3520 3521 return m_securityManager.readStaticExportResources(m_context, parameterResources, timestamp); 3522 } 3523 3524 /** 3525 * Reads the URL name mappings matching a given filter.<p> 3526 * 3527 * @param filter the filter to match 3528 * @return the URL name mappings matching the filter 3529 * 3530 * @throws CmsException if something goes wrong 3531 */ 3532 public List<CmsUrlNameMappingEntry> readUrlNameMappings(CmsUrlNameMappingFilter filter) throws CmsException { 3533 3534 return m_securityManager.readUrlNameMappings(m_context, filter); 3535 } 3536 3537 /** 3538 * Reads the URL names for all locales.<p> 3539 * 3540 * @param structureId the id of resource for which the URL names should be read 3541 * @return returns the URL names for the resource 3542 * 3543 * @throws CmsException if something goes wrong 3544 */ 3545 public List<String> readUrlNamesForAllLocales(CmsUUID structureId) throws CmsException { 3546 3547 List<String> detailNames = m_securityManager.readUrlNamesForAllLocales(m_context, structureId); 3548 if (detailNames.isEmpty()) { 3549 List<String> result = new ArrayList<String>(); 3550 result.add(structureId.toString()); 3551 return result; 3552 } 3553 return detailNames; 3554 } 3555 3556 /** 3557 * Reads a user based on its id.<p> 3558 * 3559 * @param userId the id of the user to be read 3560 * 3561 * @return the user with the given id 3562 * 3563 * @throws CmsException if something goes wrong 3564 * 3565 * @see #readHistoryPrincipal(CmsUUID) for retrieving data of deleted users 3566 */ 3567 public CmsUser readUser(CmsUUID userId) throws CmsException { 3568 3569 return m_securityManager.readUser(m_context, userId); 3570 } 3571 3572 /** 3573 * Reads a user based on its name.<p> 3574 * 3575 * @param username the name of the user to be read 3576 * 3577 * @return the user with the given name 3578 * 3579 * @throws CmsException if something goes wrong 3580 */ 3581 public CmsUser readUser(String username) throws CmsException { 3582 3583 return m_securityManager.readUser(m_context, username); 3584 } 3585 3586 /** 3587 * Returns a user, if the password is correct.<p> 3588 * 3589 * If the user/pwd pair is not valid a <code>{@link CmsException}</code> is thrown.<p> 3590 * 3591 * @param username the name of the user to be returned 3592 * @param password the password of the user to be returned 3593 * 3594 * @return the validated user 3595 * 3596 * @throws CmsException if operation was not successful 3597 */ 3598 public CmsUser readUser(String username, String password) throws CmsException { 3599 3600 return m_securityManager.readUser(m_context, username, password); 3601 } 3602 3603 /** 3604 * Removes a resource from the current project of the user.<p> 3605 * 3606 * This is used to reduce the current users project with the 3607 * specified resource, in case that the resource is already part of the project. 3608 * The resource is not really removed like in a regular copy operation, 3609 * it is in fact only "disabled" in the current users project.<p> 3610 * 3611 * @param resourcename the name of the resource to remove to the current project (full current site relative path) 3612 * 3613 * @throws CmsException if something goes wrong 3614 */ 3615 public void removeResourceFromProject(String resourcename) throws CmsException { 3616 3617 // TODO: this should be also possible if the resource has been deleted 3618 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3619 getResourceType(resource).removeResourceFromProject(this, m_securityManager, resource); 3620 } 3621 3622 /** 3623 * Removes a user from a group.<p> 3624 * 3625 * @param username the name of the user that is to be removed from the group 3626 * @param groupname the name of the group 3627 * 3628 * @throws CmsException if operation was not successful 3629 */ 3630 public void removeUserFromGroup(String username, String groupname) throws CmsException { 3631 3632 m_securityManager.removeUserFromGroup(m_context, username, groupname, false); 3633 } 3634 3635 /** 3636 * Renames a resource to the given destination name, 3637 * this is identical to a <code>move</code> operation.<p> 3638 * 3639 * @param source the name of the resource to rename (full current site relative path) 3640 * @param destination the new resource name (full path) 3641 * 3642 * @throws CmsException if something goes wrong 3643 * 3644 * @see #moveResource(String, String) 3645 */ 3646 public void renameResource(String source, String destination) throws CmsException { 3647 3648 moveResource(source, destination); 3649 } 3650 3651 /** 3652 * Replaces the content, type and properties of a resource.<p> 3653 * 3654 * @param resourcename the name of the resource to replace (full current site relative path) 3655 * @param type the new type of the resource 3656 * @param content the new content of the resource 3657 * @param properties the new properties of the resource 3658 * 3659 * @throws CmsException if something goes wrong 3660 */ 3661 public void replaceResource( 3662 String resourcename, 3663 I_CmsResourceType type, 3664 byte[] content, 3665 List<CmsProperty> properties) 3666 throws CmsException { 3667 3668 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3669 getResourceType(resource).replaceResource(this, m_securityManager, resource, type, content, properties); 3670 } 3671 3672 /** 3673 * Replaces the content, type and properties of a resource.<p> 3674 * 3675 * @param resourcename the name of the resource to replace (full current site relative path) 3676 * @param type the new type of the resource 3677 * @param content the new content of the resource 3678 * @param properties the new properties of the resource 3679 * 3680 * @throws CmsException if something goes wrong 3681 * 3682 * @deprecated 3683 * Use {@link #replaceResource(String, I_CmsResourceType, byte[], List)} instead. 3684 * Resource types should always be referenced either by its type class (preferred) or by type name. 3685 * Use of int based resource type references will be discontinued in a future OpenCms release. 3686 */ 3687 @Deprecated 3688 public void replaceResource(String resourcename, int type, byte[] content, List<CmsProperty> properties) 3689 throws CmsException { 3690 3691 replaceResource(resourcename, getResourceType(type), content, properties); 3692 } 3693 3694 /** 3695 * Restores a deleted resource identified by its structure id from the historical archive.<p> 3696 * 3697 * These ids can be obtained from the {@link #readDeletedResources(String, boolean)} method.<p> 3698 * 3699 * @param structureId the structure id of the resource to restore 3700 * 3701 * @throws CmsException if something goes wrong 3702 */ 3703 public void restoreDeletedResource(CmsUUID structureId) throws CmsException { 3704 3705 m_securityManager.restoreDeletedResource(m_context, structureId); 3706 } 3707 3708 /** 3709 * Restores a resource in the current project with a version from the historical archive.<p> 3710 * 3711 * @param structureId the structure id of the resource to restore from the archive 3712 * @param version the desired version of the resource to be restored 3713 * 3714 * @throws CmsException if something goes wrong 3715 * 3716 * @see #readResource(CmsUUID, int) 3717 */ 3718 public void restoreResourceVersion(CmsUUID structureId, int version) throws CmsException { 3719 3720 CmsResource resource = readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION); 3721 getResourceType(resource).restoreResource(this, m_securityManager, resource, version); 3722 } 3723 3724 /** 3725 * Removes an access control entry of a given principal from a given resource.<p> 3726 * 3727 * @param resourceName name of the resource 3728 * @param principalType the type of the principal (currently group or user) 3729 * @param principalName the name of the principal 3730 * 3731 * @throws CmsException if something goes wrong 3732 */ 3733 public void rmacc(String resourceName, String principalType, String principalName) throws CmsException { 3734 3735 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 3736 3737 if (CmsUUID.isValidUUID(principalName)) { 3738 // principal name is in fact a UUID, probably the user was already deleted 3739 m_securityManager.removeAccessControlEntry(m_context, res, new CmsUUID(principalName)); 3740 } else if (CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_NAME.equals(principalName)) { 3741 m_securityManager.removeAccessControlEntry(m_context, res, CmsAccessControlEntry.PRINCIPAL_ALL_OTHERS_ID); 3742 } else if (CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_NAME.equals(principalName)) { 3743 m_securityManager.removeAccessControlEntry( 3744 m_context, 3745 res, 3746 CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID); 3747 } else { 3748 try { 3749 // principal name not a UUID, assume this is a normal group or user name 3750 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 3751 m_securityManager.removeAccessControlEntry(m_context, res, principal.getId()); 3752 } catch (CmsDbEntryNotFoundException e) { 3753 // role case 3754 CmsRole role = CmsRole.valueOfRoleName(principalName); 3755 if (role == null) { 3756 throw e; 3757 } 3758 m_securityManager.removeAccessControlEntry(m_context, res, role.getId()); 3759 } 3760 } 3761 } 3762 3763 /** 3764 * Changes the "expire" date of a resource.<p> 3765 * 3766 * @param resource the resource to change 3767 * @param dateExpired the new expire date of the changed resource 3768 * @param recursive if this operation is to be applied recursively to all resources in a folder 3769 * 3770 * @throws CmsException if something goes wrong 3771 */ 3772 public void setDateExpired(CmsResource resource, long dateExpired, boolean recursive) throws CmsException { 3773 3774 getResourceType(resource).setDateExpired(this, m_securityManager, resource, dateExpired, recursive); 3775 } 3776 3777 /** 3778 * Changes the "expire" date of a resource.<p> 3779 * 3780 * @param resourcename the name of the resource to change (full current site relative path) 3781 * @param dateExpired the new expire date of the changed resource 3782 * @param recursive if this operation is to be applied recursively to all resources in a folder 3783 * 3784 * @throws CmsException if something goes wrong 3785 */ 3786 public void setDateExpired(String resourcename, long dateExpired, boolean recursive) throws CmsException { 3787 3788 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3789 setDateExpired(resource, dateExpired, recursive); 3790 } 3791 3792 /** 3793 * Changes the "last modified" time stamp of a resource.<p> 3794 * 3795 * @param resourcename the name of the resource to change (full current site relative path) 3796 * @param dateLastModified time stamp the new time stamp of the changed resource 3797 * @param recursive if this operation is to be applied recursively to all resources in a folder 3798 * 3799 * @throws CmsException if something goes wrong 3800 */ 3801 public void setDateLastModified(String resourcename, long dateLastModified, boolean recursive) throws CmsException { 3802 3803 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3804 getResourceType(resource).setDateLastModified(this, m_securityManager, resource, dateLastModified, recursive); 3805 } 3806 3807 /** 3808 * Changes the "release" date of a resource.<p> 3809 * 3810 * @param resource the resource to change 3811 * @param dateReleased the new release date of the changed resource 3812 * @param recursive if this operation is to be applied recursively to all resources in a folder 3813 * 3814 * @throws CmsException if something goes wrong 3815 */ 3816 public void setDateReleased(CmsResource resource, long dateReleased, boolean recursive) throws CmsException { 3817 3818 getResourceType(resource).setDateReleased(this, m_securityManager, resource, dateReleased, recursive); 3819 } 3820 3821 /** 3822 * Changes the "release" date of a resource.<p> 3823 * 3824 * @param resourcename the name of the resource to change (full current site relative path) 3825 * @param dateReleased the new release date of the changed resource 3826 * @param recursive if this operation is to be applied recursively to all resources in a folder 3827 * 3828 * @throws CmsException if something goes wrong 3829 */ 3830 public void setDateReleased(String resourcename, long dateReleased, boolean recursive) throws CmsException { 3831 3832 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3833 setDateReleased(resource, dateReleased, recursive); 3834 } 3835 3836 /** 3837 * Sets a new parent-group for an already existing group.<p> 3838 * 3839 * @param groupName the name of the group that should be updated 3840 * @param parentGroupName the name of the parent group to set, 3841 * or <code>null</code> if the parent 3842 * group should be deleted. 3843 * 3844 * @throws CmsException if operation was not successful 3845 */ 3846 public void setParentGroup(String groupName, String parentGroupName) throws CmsException { 3847 3848 m_securityManager.setParentGroup(m_context, groupName, parentGroupName); 3849 } 3850 3851 /** 3852 * Sets the password for a user.<p> 3853 * 3854 * @param username the name of the user 3855 * @param newPassword the new password 3856 * 3857 * @throws CmsException if operation was not successful 3858 */ 3859 public void setPassword(String username, String newPassword) throws CmsException { 3860 3861 m_securityManager.setPassword(m_context, username, newPassword); 3862 } 3863 3864 /** 3865 * Sets the password for a specified user.<p> 3866 * 3867 * @param username the name of the user 3868 * @param oldPassword the old password 3869 * @param newPassword the new password 3870 * 3871 * @throws CmsException if the user data could not be read from the database 3872 */ 3873 public void setPassword(String username, String oldPassword, String newPassword) throws CmsException { 3874 3875 m_securityManager.resetPassword(m_context, username, oldPassword, newPassword); 3876 } 3877 3878 /** 3879 * Helper method to temporarily change the site root in a try-with-resources statement. 3880 * 3881 * @param siteRoot the site root to switch to 3882 * @return an AutoCloseable that restores the original site root when closed 3883 */ 3884 public AutoCloseable tempChangeSiteRoot(String siteRoot) { 3885 3886 final String oldSiteRoot = m_context.getSiteRoot(); 3887 m_context.setSiteRoot(siteRoot); 3888 return () -> m_context.setSiteRoot(oldSiteRoot); 3889 } 3890 3891 /** 3892 * Undeletes a resource.<p> 3893 * 3894 * Only resources that have already been published once can be undeleted, 3895 * if a "new" resource is deleted it can not be undeleted.<p> 3896 * 3897 * @param resourcename the name of the resource to undelete 3898 * @param recursive if this operation is to be applied recursively to all resources in a folder 3899 * 3900 * @throws CmsException if something goes wrong 3901 * 3902 * @see CmsObject#undoChanges(String, CmsResource.CmsResourceUndoMode) 3903 */ 3904 public void undeleteResource(String resourcename, boolean recursive) throws CmsException { 3905 3906 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3907 getResourceType(resource).undelete(this, m_securityManager, resource, recursive); 3908 } 3909 3910 /** 3911 * Undoes all changes to a resource by restoring the version from the 3912 * online project to the current offline project.<p> 3913 * 3914 * @param resourcename the name of the resource to undo the changes for 3915 * @param mode the undo mode, one of the <code>{@link CmsResource.CmsResourceUndoMode}#UNDO_XXX</code> constants 3916 * 3917 * @throws CmsException if something goes wrong 3918 * 3919 * @see CmsResource#UNDO_CONTENT 3920 * @see CmsResource#UNDO_CONTENT_RECURSIVE 3921 * @see CmsResource#UNDO_MOVE_CONTENT 3922 * @see CmsResource#UNDO_MOVE_CONTENT_RECURSIVE 3923 */ 3924 public void undoChanges(String resourcename, CmsResource.CmsResourceUndoMode mode) throws CmsException { 3925 3926 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3927 getResourceType(resource).undoChanges(this, m_securityManager, resource, mode); 3928 } 3929 3930 /** 3931 * Unlocks all resources of a project. 3932 * 3933 * @param id the id of the project to be unlocked 3934 * 3935 * @throws CmsException if operation was not successful 3936 */ 3937 public void unlockProject(CmsUUID id) throws CmsException { 3938 3939 m_securityManager.unlockProject(m_context, id); 3940 } 3941 3942 /** 3943 * Unlocks a resource.<p> 3944 * 3945 * @param resource the resource to unlock 3946 * 3947 * @throws CmsException if something goes wrong 3948 */ 3949 public void unlockResource(CmsResource resource) throws CmsException { 3950 3951 getResourceType(resource).unlockResource(this, m_securityManager, resource); 3952 } 3953 3954 /** 3955 * Unlocks a resource.<p> 3956 * 3957 * @param resourcename the name of the resource to unlock (full current site relative path) 3958 * 3959 * @throws CmsException if something goes wrong 3960 */ 3961 public void unlockResource(String resourcename) throws CmsException { 3962 3963 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3964 getResourceType(resource).unlockResource(this, m_securityManager, resource); 3965 } 3966 3967 /** 3968 * Updates the last login date on the given user to the current time.<p> 3969 * 3970 * @param user the user to be updated 3971 * 3972 * @throws CmsRoleViolationException if the current user does not own the rule {@link CmsRole#ACCOUNT_MANAGER} for the current project 3973 * @throws CmsException if operation was not successful 3974 */ 3975 public void updateLastLoginDate(CmsUser user) throws CmsRoleViolationException, CmsException { 3976 3977 m_securityManager.updateLastLoginDate(m_context, user); 3978 } 3979 3980 /** 3981 * Tests if a user is member of the given group.<p> 3982 * 3983 * @param username the name of the user to test 3984 * @param groupname the name of the group to test 3985 * 3986 * @return <code>true</code>, if the user is in the group; or <code>false</code> otherwise 3987 * 3988 * @throws CmsException if operation was not successful 3989 */ 3990 public boolean userInGroup(String username, String groupname) throws CmsException { 3991 3992 return (m_securityManager.userInGroup(m_context, username, groupname)); 3993 } 3994 3995 /** 3996 * This method checks if a new password follows the rules for 3997 * new passwords, which are defined by a Class implementing the 3998 * <code>{@link org.opencms.security.I_CmsPasswordHandler}</code> 3999 * interface and configured in the opencms.properties file.<p> 4000 * 4001 * If this method throws no exception the password is valid.<p> 4002 * 4003 * @param password the new password that has to be checked 4004 * 4005 * @throws CmsSecurityException if the password is not valid 4006 */ 4007 public void validatePassword(String password) throws CmsSecurityException { 4008 4009 m_securityManager.validatePassword(password); 4010 } 4011 4012 /** 4013 * Writes a resource to the OpenCms VFS, including it's content.<p> 4014 * 4015 * Applies only to resources of type <code>{@link CmsFile}</code> 4016 * i.e. resources that have a binary content attached.<p> 4017 * 4018 * Certain resource types might apply content validation or transformation rules 4019 * before the resource is actually written to the VFS. The returned result 4020 * might therefore be a modified version from the provided original.<p> 4021 * 4022 * @param resource the resource to write 4023 * 4024 * @return the written resource (may have been modified) 4025 * 4026 * @throws CmsException if something goes wrong 4027 */ 4028 public CmsFile writeFile(CmsFile resource) throws CmsException { 4029 4030 return getResourceType(resource).writeFile(this, m_securityManager, resource); 4031 } 4032 4033 /** 4034 * Writes an already existing group.<p> 4035 * 4036 * The group has to be a valid OpenCms group.<br> 4037 * 4038 * The group will be completely overridden by the given data.<p> 4039 * 4040 * @param group the group that should be written 4041 * 4042 * @throws CmsException if operation was not successful 4043 */ 4044 public void writeGroup(CmsGroup group) throws CmsException { 4045 4046 m_securityManager.writeGroup(m_context, group); 4047 } 4048 4049 /** 4050 * Creates a historical entry of the current project.<p> 4051 * 4052 * @param publishTag the correlative publish tag 4053 * @param publishDate the date of publishing 4054 * 4055 * @throws CmsException if operation was not successful 4056 */ 4057 public void writeHistoryProject(int publishTag, long publishDate) throws CmsException { 4058 4059 m_securityManager.writeHistoryProject(m_context, publishTag, publishDate); 4060 } 4061 4062 /** 4063 * Writes an already existing project.<p> 4064 * 4065 * The project id has to be a valid OpenCms project id.<br> 4066 * 4067 * The project with the given id will be completely overridden 4068 * by the given data.<p> 4069 * 4070 * @param project the project that should be written 4071 * 4072 * @throws CmsException if operation was not successful 4073 */ 4074 public void writeProject(CmsProject project) throws CmsException { 4075 4076 m_securityManager.writeProject(m_context, project); 4077 } 4078 4079 /** 4080 * Writes the 'projectlastmodified' field of a resource record.<p> 4081 * 4082 * @param resource the resource which should be modified 4083 * @param project the project whose id should be written into the resource record 4084 * 4085 * @throws CmsException if something goes wrong 4086 */ 4087 public void writeProjectLastModified(CmsResource resource, CmsProject project) throws CmsException { 4088 4089 m_securityManager.writeResourceProjectLastModified(getRequestContext(), resource, project); 4090 } 4091 4092 /** 4093 * Writes a property for a specified resource.<p> 4094 * 4095 * @param resourcename the name of resource with complete path 4096 * @param property the property to write 4097 * 4098 * @throws CmsException if something goes wrong 4099 */ 4100 public void writePropertyObject(String resourcename, CmsProperty property) throws CmsException { 4101 4102 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 4103 getResourceType(resource).writePropertyObject(this, m_securityManager, resource, property); 4104 } 4105 4106 /** 4107 * Writes a list of properties for a specified resource.<p> 4108 * 4109 * Code calling this method has to ensure that the no properties 4110 * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>, 4111 * otherwise an exception is thrown.<p> 4112 * 4113 * @param res the resource 4114 * @param properties the list of properties to write 4115 * 4116 * @throws CmsException if something goes wrong 4117 */ 4118 public void writePropertyObjects(CmsResource res, List<CmsProperty> properties) throws CmsException { 4119 4120 getResourceType(res).writePropertyObjects(this, m_securityManager, res, properties); 4121 } 4122 4123 /** 4124 * Writes a list of properties for a specified resource.<p> 4125 * 4126 * Code calling this method has to ensure that the no properties 4127 * <code>a, b</code> are contained in the specified list so that <code>a.equals(b)</code>, 4128 * otherwise an exception is thrown.<p> 4129 * 4130 * @param resourcename the name of resource with complete path 4131 * @param properties the list of properties to write 4132 * 4133 * @throws CmsException if something goes wrong 4134 */ 4135 public void writePropertyObjects(String resourcename, List<CmsProperty> properties) throws CmsException { 4136 4137 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 4138 getResourceType(resource).writePropertyObjects(this, m_securityManager, resource, properties); 4139 } 4140 4141 /** 4142 * Writes a resource.<p> 4143 * 4144 * @param resource the file to write 4145 * 4146 * @throws CmsException if resource type is set to folder, or 4147 * if the user has not the rights to write the file header. 4148 */ 4149 public void writeResource(CmsResource resource) throws CmsException { 4150 4151 m_securityManager.writeResource(m_context, resource); 4152 } 4153 4154 /** 4155 * Writes a published resource entry.<p> 4156 * 4157 * This is done during static export.<p> 4158 * 4159 * @param resourceName The name of the resource to be added to the static export 4160 * @param linkType the type of resource exported (0= non-parameter, 1=parameter) 4161 * @param linkParameter the parameters added to the resource 4162 * @param timestamp a time stamp for writing the data into the db 4163 * 4164 * @throws CmsException if something goes wrong 4165 */ 4166 public void writeStaticExportPublishedResource( 4167 String resourceName, 4168 int linkType, 4169 String linkParameter, 4170 long timestamp) 4171 throws CmsException { 4172 4173 m_securityManager.writeStaticExportPublishedResource( 4174 m_context, 4175 resourceName, 4176 linkType, 4177 linkParameter, 4178 timestamp); 4179 } 4180 4181 /** 4182 * Writes a new URL name mapping for a given resource.<p> 4183 * 4184 * The first name from the given name sequence which is not already mapped to another resource will be used 4185 * for the URL name mapping.<p> 4186 * 4187 * @param nameSeq an iterator for generating names for the mapping 4188 * @param structureId the structure id to which the name should be mapped 4189 * @param locale the locale of the mapping 4190 * @param replaceOnPublish if the mapping should replace previous mappings when published 4191 * 4192 * @return the name which was actually mapped to the structure id 4193 * 4194 * @throws CmsException if something goes wrong 4195 */ 4196 public String writeUrlNameMapping( 4197 Iterator<String> nameSeq, 4198 CmsUUID structureId, 4199 String locale, 4200 boolean replaceOnPublish) 4201 throws CmsException { 4202 4203 return m_securityManager.writeUrlNameMapping(m_context, nameSeq, structureId, locale, replaceOnPublish); 4204 } 4205 4206 /** 4207 * Writes a new URL name mapping for a given resource.<p> 4208 * 4209 * This method uses {@link CmsNumberSuffixNameSequence} to generate a sequence of name candidates 4210 * from the given base name.<p> 4211 * 4212 * @param name the base name for the mapping 4213 * @param structureId the structure id to which the name should be mapped 4214 * @param locale the locale of the mapping 4215 * @param replaceOnPublish mappings for which this is set will replace older mappings on publish 4216 * 4217 * @return the URL name that was actually used for the mapping 4218 * 4219 * @throws CmsException if something goes wrong 4220 */ 4221 public String writeUrlNameMapping(String name, CmsUUID structureId, String locale, boolean replaceOnPublish) 4222 throws CmsException { 4223 4224 return writeUrlNameMapping(new CmsNumberSuffixNameSequence(name), structureId, locale, replaceOnPublish); 4225 } 4226 4227 /** 4228 * Updates the user information. <p> 4229 * 4230 * The user id has to be a valid OpenCms user id.<br> 4231 * 4232 * The user with the given id will be completely overriden 4233 * by the given data.<p> 4234 * 4235 * @param user the user to be written 4236 * 4237 * @throws CmsException if operation was not successful 4238 */ 4239 public void writeUser(CmsUser user) throws CmsException { 4240 4241 m_securityManager.writeUser(m_context, user); 4242 } 4243 4244 /** 4245 * Adds a new relation to the given resource.<p> 4246 * 4247 * @param resource the source resource 4248 * @param target the target resource 4249 * @param relationType the type of the relation 4250 * @param importCase if importing relations 4251 * 4252 * @throws CmsException if something goes wrong 4253 */ 4254 private void createRelation(CmsResource resource, CmsResource target, String relationType, boolean importCase) 4255 throws CmsException { 4256 4257 CmsRelationType type = CmsRelationType.valueOf(relationType); 4258 m_securityManager.addRelationToResource(m_context, resource, target, type, importCase); 4259 } 4260 4261 /** 4262 * Adds a new relation to the given resource.<p> 4263 * 4264 * @param resourceName the name of the source resource 4265 * @param targetPath the path of the target resource 4266 * @param relationType the type of the relation 4267 * @param importCase if importing relations 4268 * 4269 * @throws CmsException if something goes wrong 4270 */ 4271 private void createRelation(String resourceName, String targetPath, String relationType, boolean importCase) 4272 throws CmsException { 4273 4274 CmsResource resource = readResource(resourceName, CmsResourceFilter.IGNORE_EXPIRATION); 4275 CmsResource target = readResource(targetPath, CmsResourceFilter.IGNORE_EXPIRATION); 4276 createRelation(resource, target, relationType, importCase); 4277 } 4278 4279 /** 4280 * Notify all event listeners that a particular event has occurred.<p> 4281 * 4282 * The event will be given to all registered <code>{@link I_CmsEventListener}</code>s.<p> 4283 * 4284 * @param type the type of the event 4285 * @param data a data object that contains data used by the event listeners 4286 * 4287 * @see OpenCms#addCmsEventListener(I_CmsEventListener) 4288 * @see OpenCms#addCmsEventListener(I_CmsEventListener, int[]) 4289 */ 4290 private void fireEvent(int type, Object data) { 4291 4292 OpenCms.fireCmsEvent(type, Collections.singletonMap("data", data)); 4293 } 4294 4295 /** 4296 * Convenience method to get the initialized resource type instance for the given resource, 4297 * with a fall back to special "unknown" resource types in case the resource type is not configured.<p> 4298 * 4299 * @param resource the resource to get the type for 4300 * 4301 * @return the initialized resource type instance for the given resource 4302 * 4303 * @see org.opencms.loader.CmsResourceManager#getResourceType(int) 4304 */ 4305 private I_CmsResourceType getResourceType(CmsResource resource) { 4306 4307 return OpenCms.getResourceManager().getResourceType(resource); 4308 } 4309 4310 /** 4311 * Convenience method to return the initialized resource type 4312 * instance for the given id.<p> 4313 * 4314 * @param resourceType the id of the resource type to get 4315 * 4316 * @return the initialized resource type instance for the given id 4317 * 4318 * @throws CmsException if something goes wrong 4319 * 4320 * @see org.opencms.loader.CmsResourceManager#getResourceType(int) 4321 */ 4322 private I_CmsResourceType getResourceType(int resourceType) throws CmsException { 4323 4324 return OpenCms.getResourceManager().getResourceType(resourceType); 4325 } 4326 4327 /** 4328 * Initializes this <code>{@link CmsObject}</code> with the provided user context and database connection.<p> 4329 * 4330 * @param securityManager the security manager 4331 * @param context the request context that contains the user authentication 4332 */ 4333 private void init(CmsSecurityManager securityManager, CmsRequestContext context) { 4334 4335 m_securityManager = securityManager; 4336 m_context = context; 4337 } 4338 4339 /** 4340 * Locks a resource.<p> 4341 * 4342 * The <code>type</code> parameter controls what kind of lock is used.<br> 4343 * Possible values for this parameter are: <br> 4344 * <ul> 4345 * <li><code>{@link org.opencms.lock.CmsLockType#EXCLUSIVE}</code></li> 4346 * <li><code>{@link org.opencms.lock.CmsLockType#TEMPORARY}</code></li> 4347 * </ul><p> 4348 * 4349 * @param resourcename the name of the resource to lock (full current site relative path) 4350 * @param type type of the lock 4351 * 4352 * @throws CmsException if something goes wrong 4353 */ 4354 private void lockResource(String resourcename, CmsLockType type) throws CmsException { 4355 4356 // throw the exception if resource name is an empty string 4357 if (CmsStringUtil.isEmptyOrWhitespaceOnly(resourcename)) { 4358 throw new CmsVfsResourceNotFoundException( 4359 Messages.get().container(Messages.ERR_LOCK_RESOURCE_1, resourcename)); 4360 } 4361 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 4362 getResourceType(resource).lockResource(this, m_securityManager, resource, type); 4363 } 4364 4365}