1 31 32 package org.opencms.file; 33 34 import org.opencms.db.CmsPublishList; 35 import org.opencms.db.CmsSecurityManager; 36 import org.opencms.file.types.I_CmsResourceType; 37 import org.opencms.lock.CmsLock; 38 import org.opencms.main.CmsException; 39 import org.opencms.main.CmsIllegalArgumentException; 40 import org.opencms.main.I_CmsEventListener; 41 import org.opencms.main.OpenCms; 42 import org.opencms.report.CmsShellReport; 43 import org.opencms.report.I_CmsReport; 44 import org.opencms.security.CmsAccessControlEntry; 45 import org.opencms.security.CmsAccessControlList; 46 import org.opencms.security.CmsPermissionSet; 47 import org.opencms.security.CmsPrincipal; 48 import org.opencms.security.CmsRole; 49 import org.opencms.security.CmsRoleViolationException; 50 import org.opencms.security.CmsSecurityException; 51 import org.opencms.security.I_CmsPrincipal; 52 import org.opencms.util.CmsUUID; 53 import org.opencms.workflow.CmsTaskService; 54 55 import java.util.Collections ; 56 import java.util.List ; 57 import java.util.Map ; 58 import java.util.Set ; 59 60 90 public final class CmsObject { 91 92 95 protected CmsRequestContext m_context; 96 97 100 protected CmsSecurityManager m_securityManager; 101 102 112 public CmsObject(CmsSecurityManager securityManager, CmsRequestContext context) { 113 114 init(securityManager, context); 115 } 116 117 125 public void addUserToGroup(String username, String groupname) throws CmsException { 126 127 m_securityManager.addUserToGroup(m_context, username, groupname); 128 } 129 130 149 public CmsUser addWebUser(String name, String password, String group, String description, Map additionalInfos) 150 throws CmsException { 151 152 return m_securityManager.addWebUser(m_context, name, password, group, description, additionalInfos); 153 } 154 155 163 public void backupProject(int versionId, long publishDate) throws CmsException { 164 165 m_securityManager.backupProject(m_context, versionId, publishDate); 166 } 167 168 184 public void chacc( 185 String resourceName, 186 String principalType, 187 String principalName, 188 int allowedPermissions, 189 int deniedPermissions, 190 int flags) throws CmsException { 191 192 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 193 194 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 195 CmsAccessControlEntry acEntry = new CmsAccessControlEntry( 196 res.getResourceId(), 197 principal.getId(), 198 allowedPermissions, 199 deniedPermissions, 200 flags); 201 acEntry.setFlagsForPrincipal(principal); 202 203 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 204 } 205 206 220 public void chacc(String resourceName, String principalType, String principalName, String permissionString) 221 throws CmsException { 222 223 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 224 225 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 226 CmsAccessControlEntry acEntry = new CmsAccessControlEntry( 227 res.getResourceId(), 228 principal.getId(), 229 permissionString); 230 acEntry.setFlagsForPrincipal(principal); 231 232 m_securityManager.writeAccessControlEntry(m_context, res, acEntry); 233 } 234 235 248 public void changeLastModifiedProjectId(String resourcename) throws CmsException { 249 250 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 251 getResourceType(resource.getTypeId()).changeLastModifiedProjectId(this, m_securityManager, resource); 252 } 253 254 264 public void changeLock(String resourcename) throws CmsException { 265 266 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 267 getResourceType(resource.getTypeId()).changeLock(this, m_securityManager, resource); 268 } 269 270 284 public List changeResourcesInFolderWithProperty( 285 String resourcename, 286 String property, 287 String oldValue, 288 String newValue, 289 boolean recursive) throws CmsException { 290 291 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 292 return m_securityManager.changeResourcesInFolderWithProperty( 293 m_context, 294 resource, 295 property, 296 oldValue, 297 newValue, 298 recursive); 299 } 300 301 309 public void changeUserType(CmsUUID userId, int userType) throws CmsException { 310 311 m_securityManager.changeUserType(m_context, userId, userType); 312 } 313 314 322 public void changeUserType(String username, int userType) throws CmsException { 323 324 m_securityManager.changeUserType(m_context, username, userType); 325 } 326 327 334 public void checkPublishPermissions(CmsPublishList publishList) throws CmsException { 335 336 m_securityManager.checkPublishPermissions(m_context, publishList); 338 } 339 340 348 public void checkRole(CmsRole roles) throws CmsRoleViolationException { 349 350 m_securityManager.checkRole(m_context, roles); 351 } 352 353 365 public void chflags(String resourcename, int flags) throws CmsException { 366 367 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 368 getResourceType(resource.getTypeId()).chflags(this, m_securityManager, resource, flags); 369 } 370 371 385 public void chtype(String resourcename, int type) throws CmsException { 386 387 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 388 getResourceType(resource.getTypeId()).chtype(this, m_securityManager, resource, type); 389 } 390 391 408 public void copyResource(String source, String destination) throws CmsException, CmsIllegalArgumentException { 409 410 copyResource(source, destination, CmsResource.COPY_PRESERVE_SIBLING); 411 } 412 413 435 public void copyResource(String source, String destination, int siblingMode) 436 throws CmsException, CmsIllegalArgumentException { 437 438 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 439 getResourceType(resource.getTypeId()).copyResource(this, m_securityManager, resource, destination, siblingMode); 440 } 441 442 454 public void copyResourceToProject(String resourcename) throws CmsException { 455 456 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 457 getResourceType(resource.getTypeId()).copyResourceToProject(this, m_securityManager, resource); 458 } 459 460 469 public int countLockedResources(int id) throws CmsException { 470 471 return m_securityManager.countLockedResources(m_context, id); 472 } 473 474 483 public int countLockedResources(String foldername) throws CmsException { 484 485 return m_securityManager.countLockedResources(m_context, addSiteRoot(foldername)); 486 } 487 488 498 public void cpacc(String sourceName, String destName) throws CmsException { 499 500 CmsResource source = readResource(sourceName); 501 CmsResource dest = readResource(destName); 502 m_securityManager.copyAccessControlEntries(m_context, source, dest); 503 } 504 505 517 public CmsGroup createGroup(String name, String description, int flags, String parent) throws CmsException { 518 519 return m_securityManager.createGroup(m_context, name, description, flags, parent); 520 } 521 522 534 public CmsProject createProject(String name, String description, String groupname, String managergroupname) 535 throws CmsException { 536 537 return m_securityManager.createProject( 538 m_context, 539 name, 540 description, 541 groupname, 542 managergroupname, 543 CmsProject.PROJECT_TYPE_NORMAL); 544 } 545 546 559 public CmsProject createProject( 560 String name, 561 String description, 562 String groupname, 563 String managergroupname, 564 int projecttype) throws CmsException { 565 566 return m_securityManager.createProject(m_context, name, description, groupname, managergroupname, projecttype); 567 } 568 569 580 public CmsPropertyDefinition createPropertyDefinition(String name) throws CmsException { 581 582 return (m_securityManager.createPropertyDefinition(m_context, name)); 583 } 584 585 599 public CmsResource createResource(String resourcename, int type) throws CmsException, CmsIllegalArgumentException { 600 601 return createResource(resourcename, type, new byte[0], Collections.EMPTY_LIST); 602 } 603 604 618 public CmsResource createResource(String resourcename, int type, byte[] content, List properties) 619 throws CmsException, CmsIllegalArgumentException { 620 621 return getResourceType(type).createResource(this, m_securityManager, resourcename, content, properties); 622 } 623 624 633 public void createSibling(String source, String destination, List properties) throws CmsException { 634 635 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 636 getResourceType(resource.getTypeId()).createSibling(this, m_securityManager, resource, destination, properties); 637 } 638 639 646 public CmsProject createTempfileProject() throws CmsException { 647 648 return m_securityManager.createTempfileProject(m_context); 649 } 650 651 663 public CmsUser createUser(String name, String password, String description, Map additionalInfos) 664 throws CmsException { 665 666 return m_securityManager.createUser(m_context, name, password, description, additionalInfos); 667 } 668 669 676 public void deleteAllStaticExportPublishedResources(int linkType) throws CmsException { 677 678 m_securityManager.deleteAllStaticExportPublishedResources(m_context, linkType); 679 } 680 681 696 public void deleteBackups(long timestamp, int versions, I_CmsReport report) throws CmsException { 697 698 m_securityManager.deleteBackups(m_context, timestamp, versions, report); 699 } 700 701 710 public void deleteGroup(CmsUUID groupId, CmsUUID replacementId) throws CmsException { 711 712 m_securityManager.deleteGroup(m_context, groupId, replacementId); 713 } 714 715 724 public void deleteGroup(String delgroup) throws CmsException { 725 726 m_securityManager.deleteGroup(m_context, delgroup); 727 } 728 729 738 public void deleteProject(int id) throws CmsException { 739 740 m_securityManager.deleteProject(m_context, id); 741 } 742 743 753 public void deleteProperty(String resourcename, String key) throws CmsException { 754 755 CmsProperty property = new CmsProperty(); 756 property.setName(key); 757 property.setStructureValue(CmsProperty.DELETE_VALUE); 758 759 writePropertyObject(resourcename, property); 760 } 761 762 769 public void deletePropertyDefinition(String name) throws CmsException { 770 771 m_securityManager.deletePropertyDefinition(m_context, name); 772 } 773 774 790 public void deleteResource(String resourcename, int siblingMode) throws CmsException { 791 792 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 793 getResourceType(resource.getTypeId()).deleteResource(this, m_securityManager, resource, siblingMode); 794 } 795 796 805 public void deleteStaticExportPublishedResource(String resourceName, int linkType, String linkParameter) 806 throws CmsException { 807 808 m_securityManager.deleteStaticExportPublishedResource(m_context, resourceName, linkType, linkParameter); 809 } 810 811 818 public void deleteUser(CmsUUID userId) throws CmsException { 819 820 m_securityManager.deleteUser(m_context, userId); 821 } 822 823 832 public void deleteUser(CmsUUID userId, CmsUUID replacementId) throws CmsException { 833 834 m_securityManager.deleteUser(m_context, userId, replacementId); 835 } 836 837 844 public void deleteUser(String username) throws CmsException { 845 846 m_securityManager.deleteUser(m_context, username); 847 } 848 849 856 public void deleteWebUser(CmsUUID userId) throws CmsException { 857 858 m_securityManager.deleteWebUser(m_context, userId); 859 } 860 861 879 public boolean existsResource(String resourcename) { 880 881 return existsResource(resourcename, CmsResourceFilter.DEFAULT); 882 } 883 884 909 public boolean existsResource(String resourcename, CmsResourceFilter filter) { 910 911 return m_securityManager.existsResource(m_context, addSiteRoot(resourcename), filter); 912 } 913 914 923 public List getAccessControlEntries(String resourceName) throws CmsException { 924 925 return getAccessControlEntries(resourceName, true); 926 } 927 928 938 public List getAccessControlEntries(String resourceName, boolean getInherited) throws CmsException { 939 940 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 941 return m_securityManager.getAccessControlEntries(m_context, res, getInherited); 942 } 943 944 953 public CmsAccessControlList getAccessControlList(String resourceName) throws CmsException { 954 955 return getAccessControlList(resourceName, false); 956 } 957 958 970 public CmsAccessControlList getAccessControlList(String resourceName, boolean inheritedOnly) throws CmsException { 971 972 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 973 return m_securityManager.getAccessControlList(m_context, res, inheritedOnly); 974 } 975 976 984 public List getAllAccessibleProjects() throws CmsException { 985 986 return m_securityManager.getAllAccessibleProjects(m_context); 987 } 988 989 997 public List getAllBackupProjects() throws CmsException { 998 999 return m_securityManager.getAllBackupProjects(m_context); 1000 } 1001 1002 1010 public List getAllManageableProjects() throws CmsException { 1011 1012 return m_securityManager.getAllManageableProjects(m_context); 1013 } 1014 1015 1020 public int getBackupTagId() { 1021 1022 return m_securityManager.getBackupTagId(m_context); 1023 } 1024 1025 1034 public List getChild(String groupname) throws CmsException { 1035 1036 return (m_securityManager.getChild(m_context, groupname)); 1037 } 1038 1039 1050 public List getChilds(String groupname) throws CmsException { 1051 1052 return (m_securityManager.getChilds(m_context, groupname)); 1053 } 1054 1055 1060 public Map getConfigurations() { 1061 1062 return m_securityManager.getConfigurations(); 1063 } 1064 1065 1074 public List getDirectGroupsOfUser(String username) throws CmsException { 1075 1076 return (m_securityManager.getDirectGroupsOfUser(m_context, username)); 1077 } 1078 1079 1093 public List getFilesInFolder(String resourcename) throws CmsException { 1094 1095 return getFilesInFolder(resourcename, CmsResourceFilter.DEFAULT); 1096 } 1097 1098 1112 public List getFilesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1113 1114 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1115 return m_securityManager.readChildResources(m_context, resource, filter, false, true); 1116 } 1117 1118 1125 public List getGroups() throws CmsException { 1126 1127 return (m_securityManager.getGroups(m_context)); 1128 } 1129 1130 1139 public List getGroupsOfUser(String username) throws CmsException { 1140 1141 return m_securityManager.getGroupsOfUser(m_context, username); 1142 } 1143 1144 1154 public List getGroupsOfUser(String username, String remoteAddress) throws CmsException { 1155 1156 return m_securityManager.getGroupsOfUser(m_context, username, remoteAddress); 1157 } 1158 1159 1168 public CmsLock getLock(CmsResource resource) throws CmsException { 1169 1170 return m_securityManager.getLock(m_context, resource); 1171 } 1172 1173 1182 public CmsLock getLock(String resourcename) throws CmsException { 1183 1184 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1185 return getLock(resource); 1186 } 1187 1188 1204 public String getLostAndFoundName(String resourcename) throws CmsException { 1205 1206 return m_securityManager.moveToLostAndFound(m_context, resourcename, true); 1207 } 1208 1209 1218 public CmsGroup getParent(String groupname) throws CmsException { 1219 1220 return m_securityManager.getParent(m_context, groupname); 1221 } 1222 1223 1232 public CmsPermissionSet getPermissions(String resourceName) throws CmsException { 1233 1234 CmsResource resource = readResource(resourceName, CmsResourceFilter.ALL); 1236 CmsUser user = m_context.currentUser(); 1237 1238 return m_securityManager.getPermissions(m_context, resource, user); 1239 } 1240 1241 1251 public CmsPermissionSet getPermissions(String resourceName, String userName) throws CmsException { 1252 1253 CmsAccessControlList acList = getAccessControlList(resourceName); 1254 CmsUser user = readUser(userName); 1255 return acList.getPermissions(user, getGroupsOfUser(userName)); 1256 } 1257 1258 1266 public CmsPublishList getPublishList() throws CmsException { 1267 1268 return m_securityManager.fillPublishList(m_context, new CmsPublishList(m_context.currentProject())); 1269 } 1270 1271 1283 public CmsPublishList getPublishList(CmsResource directPublishResource, boolean directPublishSiblings) 1284 throws CmsException { 1285 1286 return m_securityManager.fillPublishList(m_context, new CmsPublishList( 1287 directPublishResource, 1288 directPublishSiblings)); 1289 } 1290 1291 1303 public CmsPublishList getPublishList(List directPublishResources, boolean directPublishSiblings) 1304 throws CmsException { 1305 1306 return getPublishList(directPublishResources, directPublishSiblings, true); 1307 } 1308 1309 1322 public CmsPublishList getPublishList( 1323 List directPublishResources, 1324 boolean directPublishSiblings, 1325 boolean publishSubResources) throws CmsException { 1326 1327 return m_securityManager.fillPublishList(m_context, new CmsPublishList( 1328 directPublishResources, 1329 directPublishSiblings, 1330 publishSubResources)); 1331 } 1332 1333 1342 public CmsRequestContext getRequestContext() { 1343 1344 return m_context; 1345 } 1346 1347 1366 public List getResourcesForPrincipal(CmsUUID principalId, CmsPermissionSet permissions, boolean includeAttr) 1367 throws CmsException { 1368 1369 return m_securityManager.getResourcesForPrincipal(getRequestContext(), principalId, permissions, includeAttr); 1370 } 1371 1372 1389 public List getResourcesInFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 1390 1391 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1392 return m_securityManager.readChildResources(m_context, resource, filter, true, true); 1393 } 1394 1395 1415 public List getResourcesInTimeRange(String folder, long starttime, long endtime) throws CmsException { 1416 1417 CmsResourceFilter filter = CmsResourceFilter.IGNORE_EXPIRATION; 1418 filter = filter.addRequireLastModifiedAfter(starttime); 1419 filter = filter.addRequireLastModifiedBefore(endtime); 1420 1421 return readResources(folder, filter); 1422 } 1423 1424 1443 public String getSitePath(CmsResource resource) { 1444 1445 return m_context.getSitePath(resource); 1446 } 1447 1448 1462 public List getSubFolders(String resourcename) throws CmsException { 1463 1464 return getSubFolders(resourcename, CmsResourceFilter.DEFAULT); 1465 } 1466 1467 1481 public List getSubFolders(String resourcename, CmsResourceFilter filter) throws CmsException { 1482 1483 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1484 return m_securityManager.readChildResources(m_context, resource, filter, true, false); 1485 } 1486 1487 1492 public CmsTaskService getTaskService() { 1493 1494 return new CmsTaskService(m_context, m_securityManager); 1495 } 1496 1497 1504 public List getUsers() throws CmsException { 1505 1506 return m_securityManager.getUsers(m_context); 1507 } 1508 1509 1518 public List getUsers(int type) throws CmsException { 1519 1520 return (m_securityManager.getUsers(m_context, type)); 1521 } 1522 1523 1534 public List getUsersOfGroup(String groupname) throws CmsException { 1535 1536 return (m_securityManager.getUsersOfGroup(m_context, groupname)); 1537 } 1538 1539 1549 public boolean hasPermissions(CmsResource resource, CmsPermissionSet requiredPermissions) throws CmsException { 1550 1551 return CmsSecurityManager.PERM_ALLOWED == m_securityManager.hasPermissions( 1552 m_context, 1553 resource, 1554 requiredPermissions, 1555 true, 1556 CmsResourceFilter.ALL); 1557 } 1558 1559 1573 public boolean hasPermissions( 1574 CmsResource resource, 1575 CmsPermissionSet requiredPermissions, 1576 boolean checkLock, 1577 CmsResourceFilter filter) throws CmsException { 1578 1579 return CmsSecurityManager.PERM_ALLOWED == m_securityManager.hasPermissions( 1580 m_context, 1581 resource, 1582 requiredPermissions, 1583 checkLock, 1584 filter); 1585 } 1586 1587 1598 public boolean hasPublishPermissions(String resourcename) { 1599 1600 CmsResource resource = null; 1601 if (resourcename != null) { 1602 try { 1604 resource = readResource(resourcename, CmsResourceFilter.ALL); 1605 checkPublishPermissions(new CmsPublishList(Collections.singletonList(resource), false)); 1606 } catch (CmsException e) { 1607 return false; 1609 } 1610 } 1611 return true; 1613 } 1614 1615 1624 public boolean hasRole(CmsRole roles) { 1625 1626 return m_securityManager.hasRole(m_context, roles); 1627 } 1628 1629 1639 public void importAccessControlEntries(CmsResource resource, List acEntries) throws CmsException { 1640 1641 m_securityManager.importAccessControlEntries(m_context, resource, acEntries); 1642 } 1643 1644 1664 public CmsResource importResource(String resourcename, CmsResource resource, byte[] content, List properties) 1665 throws CmsException { 1666 1667 return getResourceType(resource.getTypeId()).importResource( 1668 this, 1669 m_securityManager, 1670 resourcename, 1671 resource, 1672 content, 1673 properties); 1674 } 1675 1676 1695 public CmsUser importUser( 1696 String id, 1697 String name, 1698 String password, 1699 String description, 1700 String firstname, 1701 String lastname, 1702 String email, 1703 String address, 1704 int flags, 1705 int type, 1706 Map additionalInfos) throws CmsException { 1707 1708 return m_securityManager.importUser( 1709 m_context, 1710 id, 1711 name, 1712 password, 1713 description, 1714 firstname, 1715 lastname, 1716 email, 1717 address, 1718 flags, 1719 type, 1720 additionalInfos); 1721 } 1722 1723 1730 public boolean isAdmin() { 1731 1732 return hasRole(CmsRole.ADMINISTRATOR); 1733 } 1734 1735 1746 public boolean isInsideCurrentProject(String resourcename) { 1747 1748 return m_securityManager.isInsideCurrentProject(m_context, addSiteRoot(resourcename)); 1749 } 1750 1751 1756 1757 public boolean isManagerOfProject() { 1758 1759 return m_securityManager.isManagerOfProject(m_context); 1760 } 1761 1762 1773 public void lockResource(String resourcename) throws CmsException { 1774 1775 lockResource(resourcename, CmsLock.COMMON); 1776 } 1777 1778 1793 public void lockResource(String resourcename, int mode) throws CmsException { 1794 1795 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 1796 getResourceType(resource.getTypeId()).lockResource(this, m_securityManager, resource, mode); 1797 } 1798 1799 1809 public String loginUser(String username, String password) throws CmsException { 1810 1811 return loginUser(username, password, m_context.getRemoteAddress()); 1812 } 1813 1814 1825 public String loginUser(String username, String password, String remoteAddress) throws CmsException { 1826 1827 return loginUser(username, password, remoteAddress, CmsUser.USER_TYPE_SYSTEMUSER); 1828 } 1829 1830 1842 public String loginUser(String username, String password, String remoteAddress, int type) throws CmsException { 1843 1844 CmsUser newUser = m_securityManager.loginUser(m_context, username, password, remoteAddress, type); 1846 CmsProject newProject = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID); 1848 m_context.switchUser(newUser, newProject); 1850 init(m_securityManager, m_context); 1852 fireEvent(I_CmsEventListener.EVENT_LOGIN_USER, newUser); 1854 return newUser.getName(); 1856 } 1857 1858 1868 public String loginWebUser(String username, String password) throws CmsException { 1869 1870 return loginUser(username, password, m_context.getRemoteAddress(), CmsUser.USER_TYPE_WEBUSER); 1871 } 1872 1873 1880 public I_CmsPrincipal lookupPrincipal(CmsUUID principalId) { 1881 1882 return m_securityManager.lookupPrincipal(m_context, principalId); 1883 } 1884 1885 1892 public I_CmsPrincipal lookupPrincipal(String principalName) { 1893 1894 return m_securityManager.lookupPrincipal(m_context, principalName); 1895 } 1896 1897 1912 public void moveResource(String source, String destination) throws CmsException { 1913 1914 CmsResource resource = readResource(source, CmsResourceFilter.IGNORE_EXPIRATION); 1915 getResourceType(resource.getTypeId()).moveResource(this, m_securityManager, resource, destination); 1916 } 1917 1918 1935 public String moveToLostAndFound(String resourcename) throws CmsException { 1936 1937 return m_securityManager.moveToLostAndFound(m_context, resourcename, false); 1938 } 1939 1940 1949 public CmsUUID publishProject() throws Exception { 1950 1951 return publishProject(new CmsShellReport(m_context.getLocale())); 1952 } 1953 1954 1963 public CmsUUID publishProject(I_CmsReport report) throws CmsException { 1964 1965 return publishProject(report, getPublishList()); 1966 } 1967 1968 1982 public CmsUUID publishProject(I_CmsReport report, CmsPublishList publishList) throws CmsException { 1983 1984 return m_securityManager.publishProject(this, publishList, report); 1985 } 1986 1987 2004 public CmsUUID publishProject(I_CmsReport report, CmsResource directPublishResource, boolean directPublishSiblings) 2005 throws CmsException { 2006 2007 return publishProject(report, getPublishList(directPublishResource, directPublishSiblings)); 2008 } 2009 2010 2023 public CmsUUID publishResource(String resourcename) throws Exception { 2024 2025 return publishResource(resourcename, false, new CmsShellReport(m_context.getLocale())); 2026 } 2027 2028 2039 public CmsUUID publishResource(String resourcename, boolean publishSiblings, I_CmsReport report) throws Exception { 2040 2041 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2042 return publishProject(report, resource, publishSiblings); 2043 } 2044 2045 2059 public List readAllBackupFileHeaders(String filename) throws CmsException { 2060 2061 CmsResource resource = readResource(filename, CmsResourceFilter.ALL); 2062 return (m_securityManager.readAllBackupFileHeaders(m_context, resource)); 2063 } 2064 2065 2072 public List readAllPropertyDefinitions() throws CmsException { 2073 2074 return m_securityManager.readAllPropertyDefinitions(m_context); 2075 } 2076 2077 2089 public CmsFolder readAncestor(String resourcename, CmsResourceFilter filter) throws CmsException { 2090 2091 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2092 return m_securityManager.readAncestor(m_context, resource, filter); 2093 } 2094 2095 2107 public CmsFolder readAncestor(String resourcename, int type) throws CmsException { 2108 2109 return readAncestor(resourcename, CmsResourceFilter.requireType(type)); 2110 } 2111 2112 2125 public CmsBackupResource readBackupFile(String filename, int tagId) throws CmsException { 2126 2127 CmsResource resource = readResource(filename, CmsResourceFilter.ALL); 2128 return m_securityManager.readBackupFile(m_context, tagId, resource); 2129 } 2130 2131 2140 public CmsBackupProject readBackupProject(int tagId) throws CmsException { 2141 2142 return (m_securityManager.readBackupProject(m_context, tagId)); 2143 } 2144 2145 2153 public List readBackupPropertyObjects(CmsBackupResource resource) throws CmsException { 2154 2155 return m_securityManager.readBackupPropertyObjects(m_context, resource); 2156 } 2157 2158 2174 public CmsFile readFile(String resourcename) throws CmsException { 2175 2176 return readFile(resourcename, CmsResourceFilter.DEFAULT); 2177 } 2178 2179 2201 public CmsFile readFile(String resourcename, CmsResourceFilter filter) throws CmsException { 2202 2203 CmsResource resource = readResource(resourcename, filter); 2204 return m_securityManager.readFile(m_context, resource, filter); 2205 } 2206 2207 2219 public CmsResource readFileHeader(String resourcename) throws CmsException { 2220 2221 return readResource(resourcename, CmsResourceFilter.DEFAULT); 2222 } 2223 2224 2237 public CmsFolder readFolder(String resourcename) throws CmsException { 2238 2239 return readFolder(resourcename, CmsResourceFilter.DEFAULT); 2240 } 2241 2242 2261 public CmsFolder readFolder(String resourcename, CmsResourceFilter filter) throws CmsException { 2262 2263 return m_securityManager.readFolder(m_context, addSiteRoot(resourcename), filter); 2264 } 2265 2266 2273 public CmsGroup readGroup(CmsProject project) { 2274 2275 return m_securityManager.readGroup(m_context, project); 2276 } 2277 2278 2287 public CmsGroup readGroup(CmsUUID groupId) throws CmsException { 2288 2289 return m_securityManager.readGroup(m_context, groupId); 2290 } 2291 2292 2301 public CmsGroup readGroup(String groupName) throws CmsException { 2302 2303 return m_securityManager.readGroup(m_context, groupName); 2304 } 2305 2306 2313 public CmsGroup readManagerGroup(CmsProject project) { 2314 2315 return m_securityManager.readManagerGroup(m_context, project); 2316 } 2317 2318 2327 public CmsUser readOwner(CmsProject project) throws CmsException { 2328 2329 return m_securityManager.readOwner(m_context, project); 2330 } 2331 2332 2342 public List readPath(String path, CmsResourceFilter filter) throws CmsException { 2343 2344 return m_securityManager.readPath(m_context, m_context.currentProject().getId(), addSiteRoot(path), filter); 2345 } 2346 2347 2356 public CmsProject readProject(int id) throws CmsException { 2357 2358 return m_securityManager.readProject(id); 2359 } 2360 2361 2370 public CmsProject readProject(String name) throws CmsException { 2371 2372 return m_securityManager.readProject(name); 2373 } 2374 2375 2385 public List readProjectResources(CmsProject project) throws CmsException { 2386 2387 return m_securityManager.readProjectResources(m_context, project); 2388 } 2389 2390 2408 public List readProjectView(int projectId, int state) throws CmsException { 2409 2410 return m_securityManager.readProjectView(m_context, projectId, state); 2411 } 2412 2413 2424 public Map readProperties(String resourcePath) throws CmsException { 2425 2426 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2427 List properties = m_securityManager.readPropertyObjects(m_context, resource, false); 2428 return CmsProperty.toMap(properties); 2429 } 2430 2431 2444 public Map readProperties(String resourcePath, boolean search) throws CmsException { 2445 2446 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2447 List properties = m_securityManager.readPropertyObjects(m_context, resource, search); 2448 return CmsProperty.toMap(properties); 2449 } 2450 2451 2465 public String readProperty(String resourcePath, String property) throws CmsException { 2466 2467 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2468 CmsProperty value = m_securityManager.readPropertyObject(m_context, resource, property, false); 2469 return value.isNullProperty() ? null : value.getValue(); 2470 } 2471 2472 2488 public String readProperty(String resourcePath, String property, boolean search) throws CmsException { 2489 2490 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2491 CmsProperty value = m_securityManager.readPropertyObject(m_context, resource, property, search); 2492 return value.isNullProperty() ? null : value.getValue(); 2493 } 2494 2495 2513 public String readProperty(String resourcePath, String property, boolean search, String propertyDefault) 2514 throws CmsException { 2515 2516 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2517 CmsProperty value = m_securityManager.readPropertyObject(m_context, resource, property, search); 2518 return value.isNullProperty() ? propertyDefault : value.getValue(); 2519 } 2520 2521 2534 public CmsPropertyDefinition readPropertyDefinition(String name) throws CmsException { 2535 2536 return (m_securityManager.readPropertyDefinition(m_context, name)); 2537 } 2538 2539 2556 public CmsProperty readPropertyObject(CmsResource resource, String property, boolean search) throws CmsException { 2557 2558 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2559 } 2560 2561 2575 public CmsProperty readPropertyObject(String resourcePath, String property, boolean search) throws CmsException { 2576 2577 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2578 return m_securityManager.readPropertyObject(m_context, resource, property, search); 2579 } 2580 2581 2605 public List readPropertyObjects(CmsResource resource, boolean search) throws CmsException { 2606 2607 return m_securityManager.readPropertyObjects(m_context, resource, search); 2608 } 2609 2610 2633 public List readPropertyObjects(String resourcePath, boolean search) throws CmsException { 2634 2635 CmsResource resource = readResource(resourcePath, CmsResourceFilter.ALL); 2636 return m_securityManager.readPropertyObjects(m_context, resource, search); 2637 } 2638 2639 2648 public List readPublishedResources(CmsUUID publishHistoryId) throws CmsException { 2649 2650 return m_securityManager.readPublishedResources(m_context, publishHistoryId); 2651 } 2652 2653 2675 public CmsResource readResource(String resourcename) throws CmsException { 2676 2677 return readResource(resourcename, CmsResourceFilter.DEFAULT); 2678 } 2679 2680 2709 public CmsResource readResource(String resourcename, CmsResourceFilter filter) throws CmsException { 2710 2711 return m_securityManager.readResource(m_context, addSiteRoot(resourcename), filter); 2712 } 2713 2714 2727 public List readResources(String resourcename, CmsResourceFilter filter) throws CmsException { 2728 2729 return readResources(resourcename, filter, true); 2730 } 2731 2732 2745 public List readResources(String resourcename, CmsResourceFilter filter, boolean readTree) throws CmsException { 2746 2747 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2748 return m_securityManager.readResources(m_context, resource, filter, readTree); 2749 } 2750 2751 2763 public List readResourcesWithProperty(String propertyDefinition) throws CmsException { 2764 2765 return m_securityManager.readResourcesWithProperty(m_context, "/", propertyDefinition); 2766 } 2767 2768 2781 public List readResourcesWithProperty(String path, String propertyDefinition) throws CmsException { 2782 2783 return m_securityManager.readResourcesWithProperty(m_context, addSiteRoot(path), propertyDefinition); 2784 } 2785 2786 2801 public List readResourcesWithProperty(String path, String propertyDefinition, String value) throws CmsException { 2802 2803 return m_securityManager.readResourcesWithProperty(m_context, addSiteRoot(path), propertyDefinition, value); 2804 } 2805 2806 2815 public Set readResponsiblePrincipals(CmsResource resource) throws CmsException { 2816 2817 return m_securityManager.readResponsiblePrincipals(m_context, resource); 2818 } 2819 2820 2829 public Set readResponsibleUsers(CmsResource resource) throws CmsException { 2830 2831 return m_securityManager.readResponsibleUsers(m_context, resource); 2832 } 2833 2834 2847 public List readSiblings(String resourcename, CmsResourceFilter filter) throws CmsException { 2848 2849 CmsResource resource = readResource(resourcename, filter); 2850 return m_securityManager.readSiblings(m_context, resource, filter); 2851 } 2852 2853 2862 public String readStaticExportPublishedResourceParameters(String rfsName) throws CmsException { 2863 2864 return m_securityManager.readStaticExportPublishedResourceParameters(m_context, rfsName); 2865 } 2866 2867 2878 public List readStaticExportResources(int parameterResources, long timestamp) throws CmsException { 2879 2880 return m_securityManager.readStaticExportResources(m_context, parameterResources, timestamp); 2881 } 2882 2883 2892 public CmsUser readUser(CmsUUID userId) throws CmsException { 2893 2894 return m_securityManager.readUser(m_context, userId); 2895 } 2896 2897 2906 public CmsUser readUser(String username) throws CmsException { 2907 2908 return m_securityManager.readUser(username); 2909 } 2910 2911 2921 public CmsUser readUser(String username, int type) throws CmsException { 2922 2923 return m_securityManager.readUser(m_context, username, type); 2924 } 2925 2926 2938 public CmsUser readUser(String username, String password) throws CmsException { 2939 2940 return m_securityManager.readUser(m_context, username, password); 2941 } 2942 2943 2952 public CmsUser readWebUser(String username) throws CmsException { 2953 2954 return m_securityManager.readWebUser(m_context, username); 2955 } 2956 2957 2969 public CmsUser readWebUser(String username, String password) throws CmsException { 2970 2971 return m_securityManager.readWebUser(m_context, username, password); 2972 } 2973 2974 2986 public void removeResourceFromProject(String resourcename) throws CmsException { 2987 2988 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 2989 getResourceType(resource.getTypeId()).removeResourceFromProject(this, m_securityManager, resource); 2990 } 2991 2992 3000 public void removeUserFromGroup(String username, String groupname) throws CmsException { 3001 3002 m_securityManager.removeUserFromGroup(m_context, username, groupname); 3003 } 3004 3005 3016 public void renameResource(String source, String destination) throws CmsException { 3017 3018 moveResource(source, destination); 3019 } 3020 3021 3031 public void replaceResource(String resourcename, int type, byte[] content, List properties) throws CmsException { 3032 3033 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3034 getResourceType(resource.getTypeId()).replaceResource( 3035 this, 3036 m_securityManager, 3037 resource, 3038 type, 3039 content, 3040 properties); 3041 } 3042 3043 3051 public void restoreResourceBackup(String resourcename, int tagId) throws CmsException { 3052 3053 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3054 getResourceType(resource.getTypeId()).restoreResourceBackup(this, m_securityManager, resource, tagId); 3055 } 3056 3057 3066 public void rmacc(String resourceName, String principalType, String principalName) throws CmsException { 3067 3068 CmsResource res = readResource(resourceName, CmsResourceFilter.ALL); 3069 3070 if (CmsUUID.isValidUUID(principalName)) { 3071 m_securityManager.removeAccessControlEntry(m_context, res, new CmsUUID(principalName)); 3073 } else { 3074 I_CmsPrincipal principal = CmsPrincipal.readPrincipal(this, principalType, principalName); 3076 m_securityManager.removeAccessControlEntry(m_context, res, principal.getId()); 3077 } 3078 } 3079 3080 3089 public void setDateExpired(String resourcename, long dateExpired, boolean recursive) throws CmsException { 3090 3091 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3092 getResourceType(resource.getTypeId()).setDateExpired(this, m_securityManager, resource, dateExpired, recursive); 3093 } 3094 3095 3104 public void setDateLastModified(String resourcename, long dateLastModified, boolean recursive) throws CmsException { 3105 3106 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3107 getResourceType(resource.getTypeId()).setDateLastModified( 3108 this, 3109 m_securityManager, 3110 resource, 3111 dateLastModified, 3112 recursive); 3113 } 3114 3115 3124 public void setDateReleased(String resourcename, long dateReleased, boolean recursive) throws CmsException { 3125 3126 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3127 getResourceType(resource.getTypeId()).setDateReleased( 3128 this, 3129 m_securityManager, 3130 resource, 3131 dateReleased, 3132 recursive); 3133 } 3134 3135 3145 public void setParentGroup(String groupName, String parentGroupName) throws CmsException { 3146 3147 m_securityManager.setParentGroup(m_context, groupName, parentGroupName); 3148 } 3149 3150 3158 public void setPassword(String username, String newPassword) throws CmsException { 3159 3160 m_securityManager.setPassword(m_context, username, newPassword); 3161 } 3162 3163 3172 public void setPassword(String username, String oldPassword, String newPassword) throws CmsException { 3173 3174 m_securityManager.resetPassword(m_context, username, oldPassword, newPassword); 3175 } 3176 3177 3198 public void touch(String resourcename, long dateLastModified, long dateReleased, long dateExpired, boolean recursive) 3199 throws CmsException { 3200 3201 if (dateReleased != CmsResource.TOUCH_DATE_UNCHANGED) { 3202 setDateReleased(resourcename, dateReleased, recursive); 3203 } 3204 if (dateExpired != CmsResource.TOUCH_DATE_UNCHANGED) { 3205 setDateExpired(resourcename, dateExpired, recursive); 3206 } 3207 if (dateLastModified != CmsResource.TOUCH_DATE_UNCHANGED) { 3208 setDateLastModified(resourcename, dateLastModified, recursive); 3209 } 3210 } 3211 3212 3228 public void undeleteResource(String resourcename) throws CmsException { 3229 3230 undoChanges(resourcename, true); 3231 } 3232 3233 3242 public void undoChanges(String resourcename, boolean recursive) throws CmsException { 3243 3244 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3245 getResourceType(resource.getTypeId()).undoChanges(this, m_securityManager, resource, recursive); 3246 } 3247 3248 3255 public void unlockProject(int id) throws CmsException { 3256 3257 m_securityManager.unlockProject(m_context, id); 3258 } 3259 3260 3267 public void unlockResource(String resourcename) throws CmsException { 3268 3269 CmsResource resource = readResource(resourcename, CmsResourceFilter.ALL); 3270 getResourceType(resource.getTypeId()).unlockResource(this, m_securityManager, resource); 3271 } 3272 3273 3283 public boolean userInGroup(String username, String groupname) throws CmsException { 3284 3285 return (m_securityManager.userInGroup(m_context, username, groupname)); 3286 } 3287 3288 3302 public Map validateHtmlLinks(CmsPublishList publishList, I_CmsReport report) throws Exception { 3303 3304 return m_securityManager.validateHtmlLinks(this, publishList, report); 3305 } 3306 3307 3319 public void validatePassword(String password) throws CmsSecurityException { 3320 3321 m_securityManager.validatePassword(password); 3322 } 3323 3324 3340 public CmsFile writeFile(CmsFile resource) throws CmsException { 3341 3342 return getResourceType(resource.getTypeId()).writeFile(this, m_securityManager, resource); 3343 } 3344 3345 3353 public void writeFileHeader(CmsFile file) throws CmsException { 3354 3355 m_securityManager.writeResource(m_context, file); 3356 } 3357 3358 3370 public void writeGroup(CmsGroup group) throws CmsException { 3371 3372 m_securityManager.writeGroup(m_context, group); 3373 } 3374 3375 3387 public void writeProject(CmsProject project) throws CmsException { 3388 3389 m_securityManager.writeProject(m_context, project); 3390 } 3391 3392 3402 public void writeProperties(String resourceName, Map properties) throws CmsException { 3403 3404 writePropertyObjects(resourceName, CmsProperty.toList(properties)); 3405 } 3406 3407 3418 public void writeProperties(String name, Map properties, boolean addDefinition) throws CmsException { 3419 3420 writePropertyObjects(name, CmsProperty.setAutoCreatePropertyDefinitions( 3421 CmsProperty.toList(properties), 3422 addDefinition)); 3423 } 3424 3425 3436 public void writeProperty(String resourceName, String key, String value) throws CmsException { 3437 3438 CmsProperty property = new CmsProperty(); 3439 property.setName(key); 3440 property.setStructureValue(value); 3441 3442 writePropertyObject(resourceName, property); 3443 } 3444 3445 3457 public void writeProperty(String resourcename, String key, String value, boolean addDefinition) throws CmsException { 3458 3459 CmsProperty property = new CmsProperty(); 3460 property.setName(key); 3461 property.setStructureValue(value); 3462 property.setAutoCreatePropertyDefinition(addDefinition); 3463 3464 writePropertyObject(resourcename, property); 3465 } 3466 3467 3475 public void writePropertyObject(String resourcename, CmsProperty property) throws CmsException { 3476 3477 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3478 getResourceType(resource.getTypeId()).writePropertyObject(this, m_securityManager, resource, property); 3479 } 3480 3481 3493 public void writePropertyObjects(String resourcename, List properties) throws CmsException { 3494 3495 CmsResource resource = readResource(resourcename, CmsResourceFilter.IGNORE_EXPIRATION); 3496 getResourceType(resource.getTypeId()).writePropertyObjects(this, m_securityManager, resource, properties); 3497 } 3498 3499 3511 public void writeStaticExportPublishedResource( 3512 String resourceName, 3513 int linkType, 3514 String linkParameter, 3515 long timestamp) throws CmsException { 3516 3517 m_securityManager.writeStaticExportPublishedResource( 3518 m_context, 3519 resourceName, 3520 linkType, 3521 linkParameter, 3522 timestamp); 3523 } 3524 3525 3537 public void writeUser(CmsUser user) throws CmsException { 3538 3539 m_securityManager.writeUser(m_context, user); 3540 } 3541 3542 3556 public void writeWebUser(CmsUser user) throws CmsException { 3557 3558 m_securityManager.writeWebUser(m_context, user); 3559 } 3560 3561 3571 private String addSiteRoot(String resourcename) { 3572 3573 return m_context.addSiteRoot(resourcename); 3574 } 3575 3576 3587 private void fireEvent(int type, Object data) { 3588 3589 OpenCms.fireCmsEvent(type, Collections.singletonMap("data", data)); 3590 } 3591 3592 3604 private I_CmsResourceType getResourceType(int resourceType) throws CmsException { 3605 3606 return OpenCms.getResourceManager().getResourceType(resourceType); 3607 } 3608 3609 3615 private void init(CmsSecurityManager securityManager, CmsRequestContext context) { 3616 3617 m_securityManager = securityManager; 3618 m_context = context; 3619 } 3620} | Popular Tags |