1 31 32 package org.opencms.main; 33 34 import org.opencms.configuration.CmsConfigurationException; 35 import org.opencms.configuration.CmsConfigurationManager; 36 import org.opencms.configuration.CmsImportExportConfiguration; 37 import org.opencms.configuration.CmsModuleConfiguration; 38 import org.opencms.configuration.CmsSearchConfiguration; 39 import org.opencms.configuration.CmsSystemConfiguration; 40 import org.opencms.configuration.CmsVfsConfiguration; 41 import org.opencms.configuration.CmsWorkplaceConfiguration; 42 import org.opencms.db.CmsDbEntryNotFoundException; 43 import org.opencms.db.CmsDefaultUsers; 44 import org.opencms.db.CmsLoginManager; 45 import org.opencms.db.CmsSecurityManager; 46 import org.opencms.db.CmsSqlManager; 47 import org.opencms.file.CmsObject; 48 import org.opencms.file.CmsProject; 49 import org.opencms.file.CmsProperty; 50 import org.opencms.file.CmsPropertyDefinition; 51 import org.opencms.file.CmsRequestContext; 52 import org.opencms.file.CmsResource; 53 import org.opencms.file.CmsUser; 54 import org.opencms.file.CmsVfsResourceNotFoundException; 55 import org.opencms.flex.CmsFlexCache; 56 import org.opencms.flex.CmsFlexCacheConfiguration; 57 import org.opencms.flex.CmsFlexController; 58 import org.opencms.i18n.CmsEncoder; 59 import org.opencms.i18n.CmsI18nInfo; 60 import org.opencms.i18n.CmsLocaleManager; 61 import org.opencms.i18n.CmsMessageContainer; 62 import org.opencms.importexport.CmsImportExportManager; 63 import org.opencms.jsp.util.CmsErrorBean; 64 import org.opencms.loader.CmsResourceManager; 65 import org.opencms.loader.I_CmsFlexCacheEnabledLoader; 66 import org.opencms.lock.CmsLockManager; 67 import org.opencms.module.CmsModuleManager; 68 import org.opencms.monitor.CmsMemoryMonitor; 69 import org.opencms.monitor.CmsMemoryMonitorConfiguration; 70 import org.opencms.scheduler.CmsScheduleManager; 71 import org.opencms.search.CmsSearchManager; 72 import org.opencms.security.CmsRole; 73 import org.opencms.security.CmsRoleViolationException; 74 import org.opencms.security.CmsSecurityException; 75 import org.opencms.security.I_CmsPasswordHandler; 76 import org.opencms.security.I_CmsValidationHandler; 77 import org.opencms.site.CmsSite; 78 import org.opencms.site.CmsSiteManager; 79 import org.opencms.staticexport.CmsLinkManager; 80 import org.opencms.staticexport.CmsStaticExportManager; 81 import org.opencms.util.CmsFileUtil; 82 import org.opencms.util.CmsPropertyUtils; 83 import org.opencms.util.CmsRequestUtil; 84 import org.opencms.util.CmsStringUtil; 85 import org.opencms.util.CmsUUID; 86 import org.opencms.workplace.CmsWorkplace; 87 import org.opencms.workplace.CmsWorkplaceManager; 88 import org.opencms.xml.CmsXmlContentTypeManager; 89 90 import java.io.IOException ; 91 import java.util.ArrayList ; 92 import java.util.Collections ; 93 import java.util.Date ; 94 import java.util.HashMap ; 95 import java.util.HashSet ; 96 import java.util.Hashtable ; 97 import java.util.Iterator ; 98 import java.util.List ; 99 import java.util.Locale ; 100 import java.util.Map ; 101 import java.util.Set ; 102 103 import javax.servlet.ServletContext ; 104 import javax.servlet.ServletException ; 105 import javax.servlet.http.HttpServletRequest ; 106 import javax.servlet.http.HttpServletResponse ; 107 import javax.servlet.http.HttpSession ; 108 109 import org.apache.commons.codec.binary.Base64; 110 import org.apache.commons.collections.ExtendedProperties; 111 import org.apache.commons.logging.Log; 112 113 140 public final class OpenCmsCore { 141 142 143 private static final Object LOCK = new Object (); 144 145 146 private static final Log LOG = CmsLog.getLog(OpenCmsCore.class); 147 148 149 private static CmsMessageContainer m_errorCondition; 150 151 152 private static OpenCmsCore m_instance; 153 154 155 private CmsConfigurationManager m_configurationManager; 156 157 158 private List m_defaultFiles; 159 160 161 private CmsDefaultUsers m_defaultUsers; 162 163 164 private CmsEventManager m_eventManager; 165 166 167 private Set m_exportPoints; 168 169 170 private CmsImportExportManager m_importExportManager; 171 172 173 private CmsLinkManager m_linkManager; 174 175 176 private CmsLocaleManager m_localeManager; 177 178 179 private CmsLockManager m_lockManager; 180 181 182 private CmsLoginManager m_loginManager; 183 184 185 private CmsMemoryMonitor m_memoryMonitor; 186 187 188 private CmsModuleManager m_moduleManager; 189 190 191 private I_CmsPasswordHandler m_passwordHandler; 192 193 194 private Map m_requestHandlers; 195 196 197 private List m_resourceInitHandlers; 198 199 200 private CmsResourceManager m_resourceManager; 201 202 203 private int m_runLevel; 204 205 206 private Map m_runtimeProperties; 207 208 209 private CmsScheduleManager m_scheduleManager; 210 211 212 private CmsSearchManager m_searchManager; 213 214 215 private CmsSecurityManager m_securityManager; 216 217 218 private CmsSessionManager m_sessionManager; 219 220 221 private CmsSiteManager m_siteManager; 222 223 224 private CmsStaticExportManager m_staticExportManager; 225 226 227 private CmsSystemInfo m_systemInfo; 228 229 230 private CmsThreadStore m_threadStore; 231 232 233 private I_CmsValidationHandler m_validationHandler; 234 235 236 private CmsWorkplaceManager m_workplaceManager; 237 238 239 private CmsXmlContentTypeManager m_xmlContentTypeManager; 240 241 247 private OpenCmsCore() 248 throws CmsInitException { 249 250 synchronized (LOCK) { 251 if (m_instance != null && (m_instance.getRunLevel() > OpenCms.RUNLEVEL_0_OFFLINE)) { 252 throw new CmsInitException(Messages.get().container(Messages.ERR_ALREADY_INITIALIZED_0)); 253 } 254 initMembers(); 255 m_instance = this; 256 setRunLevel(OpenCms.RUNLEVEL_1_CORE_OBJECT); 257 } 258 } 259 260 265 protected static OpenCmsCore getInstance() { 266 267 if (m_errorCondition != null) { 268 throw new CmsInitException(m_errorCondition, false); 270 } 271 if (m_instance == null) { 272 try { 273 m_instance = new OpenCmsCore(); 275 } catch (CmsInitException e) { 276 } 278 } 279 return m_instance; 280 } 281 282 287 protected static void setErrorCondition(CmsMessageContainer errorCondition) { 288 289 if ((m_instance != null) && (m_instance.getRunLevel() < OpenCms.RUNLEVEL_3_SHELL_ACCESS)) { 291 if (!Messages.ERR_CRITICAL_INIT_WIZARD_0.equals(errorCondition.getKey())) { 292 m_errorCondition = errorCondition; 294 System.err.println(Messages.get().getBundle().key( 296 Messages.LOG_INIT_FAILURE_MESSAGE_1, 297 errorCondition.key())); 298 } 299 LOG.error(errorCondition.key()); 300 m_instance = null; 301 } else if (m_instance != null) { 302 LOG.warn(Messages.get().getBundle().key( 304 Messages.LOG_INIT_INVALID_ERROR_2, 305 new Integer (m_instance.getRunLevel()), 306 errorCondition.key())); 307 } 308 } 309 310 315 protected void addRequestHandler(I_CmsRequestHandler handler) { 316 317 if (handler == null) { 318 return; 319 } 320 String [] names = handler.getHandlerNames(); 321 for (int i = 0; i < names.length; i++) { 322 String name = names[i]; 323 if (m_requestHandlers.get(name) != null) { 324 CmsLog.INIT.error(Messages.get().getBundle().key(Messages.LOG_DUPLICATE_REQUEST_HANDLER_1, name)); 325 continue; 326 } 327 m_requestHandlers.put(name, handler); 328 if (CmsLog.INIT.isInfoEnabled()) { 329 CmsLog.INIT.info(Messages.get().getBundle().key( 330 Messages.INIT_ADDED_REQUEST_HANDLER_2, 331 name, 332 handler.getClass().getName())); 333 } 334 } 335 } 336 337 342 protected CmsConfigurationManager getConfigurationManager() { 343 344 return m_configurationManager; 345 } 346 347 354 protected List getDefaultFiles() { 355 356 return m_defaultFiles; 357 } 358 359 364 protected CmsDefaultUsers getDefaultUsers() { 365 366 return m_defaultUsers; 367 } 368 369 374 protected CmsEventManager getEventManager() { 375 376 return m_eventManager; 377 } 378 379 385 protected Set getExportPoints() { 386 387 return m_exportPoints; 388 } 389 390 396 protected CmsImportExportManager getImportExportManager() { 397 398 return m_importExportManager; 399 } 400 401 406 protected CmsLinkManager getLinkManager() { 407 408 return m_linkManager; 409 } 410 411 416 protected CmsLocaleManager getLocaleManager() { 417 418 return m_localeManager; 419 } 420 421 426 protected CmsLockManager getLockManager() { 427 428 return m_lockManager; 429 } 430 431 436 protected CmsLoginManager getLoginManager() { 437 438 return m_loginManager; 439 } 440 441 446 protected CmsMemoryMonitor getMemoryMonitor() { 447 448 return m_memoryMonitor; 449 } 450 451 456 protected CmsModuleManager getModuleManager() { 457 458 return m_moduleManager; 459 } 460 461 466 protected I_CmsPasswordHandler getPasswordHandler() { 467 468 return m_passwordHandler; 469 } 470 471 478 protected I_CmsRequestHandler getRequestHandler(String name) { 479 480 return (I_CmsRequestHandler)m_requestHandlers.get(name); 481 } 482 483 488 protected CmsResourceManager getResourceManager() { 489 490 return m_resourceManager; 491 } 492 493 503 protected int getRunLevel() { 504 505 return m_runLevel; 506 } 507 508 514 protected Object getRuntimeProperty(Object key) { 515 516 return m_runtimeProperties.get(key); 517 } 518 519 524 protected CmsScheduleManager getScheduleManager() { 525 526 return m_scheduleManager; 527 } 528 529 535 protected CmsSearchManager getSearchManager() { 536 537 return m_searchManager; 538 } 539 540 545 protected CmsSecurityManager getSecurityManager() { 546 547 return m_securityManager; 548 } 549 550 555 protected CmsSessionManager getSessionManager() { 556 557 return m_sessionManager; 558 } 559 560 566 protected CmsSiteManager getSiteManager() { 567 568 return m_siteManager; 569 } 570 571 576 protected CmsSqlManager getSqlManager() { 577 578 return m_securityManager.getSqlManager(); 579 } 580 581 586 protected CmsStaticExportManager getStaticExportManager() { 587 588 return m_staticExportManager; 589 } 590 591 596 protected CmsSystemInfo getSystemInfo() { 597 598 return m_systemInfo; 599 } 600 601 606 protected CmsThreadStore getThreadStore() { 607 608 return m_threadStore; 609 } 610 611 616 protected I_CmsValidationHandler getValidationHandler() { 617 618 return m_validationHandler; 619 } 620 621 627 protected CmsWorkplaceManager getWorkplaceManager() { 628 629 return m_workplaceManager; 630 } 631 632 637 protected CmsXmlContentTypeManager getXmlContentTypeManager() { 638 639 if (m_xmlContentTypeManager != null) { 640 return m_xmlContentTypeManager; 641 } 642 if (getRunLevel() == OpenCms.RUNLEVEL_1_CORE_OBJECT) { 643 m_xmlContentTypeManager = CmsXmlContentTypeManager.createTypeManagerForTestCases(); 645 } 646 return m_xmlContentTypeManager; 647 } 648 649 666 protected CmsObject initCmsObject(CmsObject cms) throws CmsException { 667 668 CmsContextInfo contextInfo = new CmsContextInfo(cms.getRequestContext()); 669 return initCmsObject(contextInfo); 670 } 671 672 694 protected CmsObject initCmsObject(CmsObject adminCms, CmsContextInfo contextInfo) 695 throws CmsRoleViolationException, CmsException { 696 697 String userName = contextInfo.getUserName(); 698 699 if (adminCms == null || !adminCms.hasRole(CmsRole.ADMINISTRATOR)) { 700 if (!userName.equals(getDefaultUsers().getUserGuest()) 701 && !userName.equals(getDefaultUsers().getUserExport())) { 702 703 CmsMessageContainer message = Messages.get().container( 705 Messages.ERR_INVALID_INIT_USER_2, 706 userName, 707 ((adminCms != null) ? (adminCms.getRequestContext().currentUser().getName()) : "")); 708 if (LOG.isWarnEnabled()) { 709 LOG.warn(message.key()); 710 } 711 throw new CmsRoleViolationException(message); 712 } 713 } 714 715 return initCmsObject(contextInfo); 716 } 717 718 738 protected CmsObject initCmsObject(String user) throws CmsException { 739 740 return initCmsObject(null, new CmsContextInfo(user)); 741 } 742 743 756 protected synchronized void initConfiguration(ExtendedProperties configuration) throws CmsInitException { 757 758 String systemEncoding = null; 759 try { 760 systemEncoding = System.getProperty("file.encoding"); 761 } catch (SecurityException se) { 762 } 764 if (CmsLog.INIT.isInfoEnabled()) { 765 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_FILE_ENCODING_1, systemEncoding)); 766 } 767 768 String ethernetAddress = configuration.getString("server.ethernet.address", CmsUUID.getDummyEthernetAddress()); 770 if (CmsLog.INIT.isInfoEnabled()) { 771 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_ETHERNET_ADDRESS_1, ethernetAddress)); 772 } 773 CmsUUID.init(ethernetAddress); 774 775 String serverName = configuration.getString("server.name", "OpenCmsServer"); 777 getSystemInfo().setServerName(serverName); 778 779 m_lockManager = CmsLockManager.getInstance(); 781 782 try { 784 if (CmsLog.INIT.isInfoEnabled()) { 785 String jdkinfo = System.getProperty("java.vm.name") + " "; 786 jdkinfo += System.getProperty("java.vm.version") + " "; 787 jdkinfo += System.getProperty("java.vm.info") + " "; 788 jdkinfo += System.getProperty("java.vm.vendor") + " "; 789 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_JAVA_VM_1, jdkinfo)); 790 String osinfo = System.getProperty("os.name") + " "; 791 osinfo += System.getProperty("os.version") + " "; 792 osinfo += System.getProperty("os.arch") + " "; 793 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_OPERATING_SYSTEM_1, osinfo)); 794 } 795 } catch (Exception e) { 796 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_PROP_0), e); 797 } 798 799 m_memoryMonitor = new CmsMemoryMonitor(); 801 802 m_configurationManager = new CmsConfigurationManager(getSystemInfo().getAbsoluteRfsPathRelativeToWebInf( 804 CmsSystemInfo.FOLDER_CONFIG)); 805 m_configurationManager.setConfiguration(configuration); 807 808 try { 810 m_configurationManager.loadXmlConfiguration(); 811 } catch (Exception e) { 812 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_XML_0), e); 813 } 814 815 CmsSystemConfiguration systemConfiguration = (CmsSystemConfiguration)m_configurationManager.getConfiguration(CmsSystemConfiguration.class); 817 818 CmsEventManager configuredEventManager = systemConfiguration.getEventManager(); 820 configuredEventManager.initialize(m_eventManager); 821 m_eventManager = configuredEventManager; 822 823 String setEncoding = systemConfiguration.getDefaultContentEncoding(); 825 String defaultEncoding = CmsEncoder.lookupEncoding(setEncoding, null); 826 if (defaultEncoding == null) { 827 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_ENCODING_1, setEncoding)); 829 } 830 if (CmsLog.INIT.isInfoEnabled()) { 831 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_OPENCMS_ENCODING_1, defaultEncoding)); 832 } 833 getSystemInfo().setDefaultEncoding(defaultEncoding); 834 835 CmsMemoryMonitorConfiguration memoryMonitorConfiguration = systemConfiguration.getCmsMemoryMonitorConfiguration(); 837 m_memoryMonitor.initialize(memoryMonitorConfiguration); 838 839 getSystemInfo().setVersionHistorySettings( 841 systemConfiguration.isVersionHistoryEnabled(), 842 systemConfiguration.getVersionHistoryMaxCount()); 843 getSystemInfo().setMailSettings(systemConfiguration.getMailSettings()); 845 getSystemInfo().setHttpAuthenticationSettings(systemConfiguration.getHttpAuthenticationSettings()); 847 848 getSystemInfo().setNotificationTime(systemConfiguration.getNotificationTime()); 850 getSystemInfo().setNotificationProject(systemConfiguration.getNotificationProject()); 851 m_scheduleManager = systemConfiguration.getScheduleManager(); 853 m_resourceInitHandlers = systemConfiguration.getResourceInitHandlers(); 855 Iterator it = systemConfiguration.getRequestHandlers().iterator(); 857 while (it.hasNext()) { 858 I_CmsRequestHandler handler = (I_CmsRequestHandler)it.next(); 859 addRequestHandler(handler); 860 if (CmsLog.INIT.isInfoEnabled()) { 861 CmsLog.INIT.warn(Messages.get().getBundle().key( 862 Messages.INIT_REQUEST_HANDLER_CLASS_1, 863 handler.getClass().getName())); 864 } 865 } 866 867 m_defaultUsers = systemConfiguration.getCmsDefaultUsers(); 869 870 try { 871 CmsRole.initialize(m_defaultUsers); 873 } catch (CmsSecurityException e) { 874 throw new CmsInitException( 876 Messages.get().container(Messages.ERR_CRITICAL_INIT_GENERIC_1, e.getMessage()), 877 e); 878 } 879 880 m_siteManager = systemConfiguration.getSiteManager(); 882 883 CmsVfsConfiguration vfsConfiguation = (CmsVfsConfiguration)m_configurationManager.getConfiguration(CmsVfsConfiguration.class); 885 m_resourceManager = vfsConfiguation.getResourceManager(); 886 m_xmlContentTypeManager = vfsConfiguation.getXmlContentTypeManager(); 887 m_defaultFiles = vfsConfiguation.getDefaultFiles(); 888 889 m_resourceManager.setTranslators(vfsConfiguation.getFolderTranslator(), vfsConfiguation.getFileTranslator()); 891 892 CmsFlexCache flexCache = null; 894 try { 895 if (CmsLog.INIT.isInfoEnabled()) { 896 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_FLEX_CACHE_STARTING_0)); 897 } 898 CmsFlexCacheConfiguration flexCacheConfiguration = systemConfiguration.getCmsFlexCacheConfiguration(); 900 flexCache = new CmsFlexCache(flexCacheConfiguration); 902 if (CmsLog.INIT.isInfoEnabled()) { 903 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_FLEX_CACHE_FINISHED_0)); 904 } 905 } catch (Exception e) { 906 if (CmsLog.INIT.isWarnEnabled()) { 907 CmsLog.INIT.warn(Messages.get().getBundle().key(Messages.INIT_FLEX_CACHE_ERROR_1, e.getMessage())); 908 } 909 } 910 911 if (flexCache != null) { 912 Iterator i = m_resourceManager.getLoaders().iterator(); 914 while (i.hasNext()) { 915 Object o = i.next(); 916 if (o instanceof I_CmsFlexCacheEnabledLoader) { 917 ((I_CmsFlexCacheEnabledLoader)o).setFlexCache(flexCache); 919 } 920 } 921 } 922 923 CmsImportExportConfiguration importExportConfiguration = (CmsImportExportConfiguration)m_configurationManager.getConfiguration(CmsImportExportConfiguration.class); 925 m_importExportManager = importExportConfiguration.getImportExportManager(); 926 m_staticExportManager = importExportConfiguration.getStaticExportManager(); 927 928 CmsSearchConfiguration searchConfiguration = (CmsSearchConfiguration)m_configurationManager.getConfiguration(CmsSearchConfiguration.class); 930 m_searchManager = searchConfiguration.getSearchManager(); 931 932 CmsWorkplaceConfiguration workplaceConfiguration = (CmsWorkplaceConfiguration)m_configurationManager.getConfiguration(CmsWorkplaceConfiguration.class); 934 m_workplaceManager = workplaceConfiguration.getWorkplaceManager(); 935 addExportPoints(m_workplaceManager.getExportPoints()); 937 938 CmsModuleConfiguration moduleConfiguration = (CmsModuleConfiguration)m_configurationManager.getConfiguration(CmsModuleConfiguration.class); 940 m_moduleManager = moduleConfiguration.getModuleManager(); 941 942 m_passwordHandler = systemConfiguration.getPasswordHandler(); 944 945 m_validationHandler = systemConfiguration.getValidationHandler(); 947 948 m_loginManager = systemConfiguration.getLoginManager(); 950 951 m_securityManager = CmsSecurityManager.newInstance( 953 m_configurationManager, 954 systemConfiguration.getRuntimeInfoFactory()); 955 956 m_threadStore = new CmsThreadStore(); 958 959 m_linkManager = new CmsLinkManager(); 961 962 m_runtimeProperties.putAll(systemConfiguration.getRuntimeProperties()); 964 965 CmsObject adminCms; 967 try { 968 adminCms = initCmsObject(null, null, getDefaultUsers().getUserAdmin(), null); 969 } catch (CmsException e) { 970 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_ADMINCMS_0), e); 971 } 972 973 try { 975 m_scheduleManager.initialize(initCmsObject(adminCms)); 977 978 m_localeManager = systemConfiguration.getLocaleManager(); 980 m_localeManager.initialize(initCmsObject(adminCms)); 981 982 m_siteManager.initialize(initCmsObject(adminCms)); 984 985 m_staticExportManager.initialize(initCmsObject(adminCms)); 987 988 m_xmlContentTypeManager.initialize(initCmsObject(adminCms)); 990 991 m_moduleManager.initialize(initCmsObject(adminCms), m_configurationManager); 993 994 m_resourceManager.initialize(initCmsObject(adminCms)); 996 997 m_searchManager.initialize(initCmsObject(adminCms)); 999 1000 m_workplaceManager.initialize(initCmsObject(adminCms)); 1002 } catch (CmsException e) { 1003 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_MANAGERS_0), e); 1004 } 1005 } 1006 1007 1018 protected synchronized void initContext(ServletContext context) throws CmsInitException { 1019 1020 String servletMapping = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_SERVLET); 1022 if (servletMapping == null) { 1023 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_SERVLET_0)); 1024 } 1025 1026 String webInfPath = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_OPEN_CMS_HOME); 1028 if (CmsStringUtil.isEmpty(webInfPath)) { 1029 webInfPath = CmsFileUtil.searchWebInfFolder(context.getRealPath("/")); 1030 if (CmsStringUtil.isEmpty(webInfPath)) { 1031 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_FOLDER_0)); 1032 } 1033 } 1034 1035 String defaultWebApplication = context.getInitParameter("DefaultWebApplication"); 1037 if (defaultWebApplication == null) { 1038 defaultWebApplication = "ROOT"; 1040 } 1041 1042 String webApplicationContext = context.getInitParameter(OpenCmsServlet.SERVLET_PARAM_WEB_APPLICATION_CONTEXT); 1045 1046 getSystemInfo().init(webInfPath, servletMapping, webApplicationContext, defaultWebApplication); 1048 1049 ExtendedProperties configuration = null; 1051 try { 1052 configuration = CmsPropertyUtils.loadProperties(getSystemInfo().getConfigurationFileRfsPath()); 1053 } catch (Exception e) { 1054 throw new CmsInitException(Messages.get().container( 1055 Messages.ERR_CRITICAL_INIT_PROPFILE_1, 1056 getSystemInfo().getConfigurationFileRfsPath()), e); 1057 } 1058 1059 if (configuration.getBoolean("wizard.enabled", true)) { 1061 throw new CmsInitException(Messages.get().container(Messages.ERR_CRITICAL_INIT_WIZARD_0)); 1062 } 1063 System.err.println(Messages.get().getBundle().key( 1065 Messages.LOG_STARTUP_CONSOLE_NOTE_2, 1066 OpenCms.getSystemInfo().getVersionName(), 1067 getSystemInfo().getWebApplicationName())); 1068 for (int i = 0; i < Messages.COPYRIGHT_BY_ALKACON.length; i++) { 1069 System.err.println(Messages.COPYRIGHT_BY_ALKACON[i]); 1070 } 1071 System.err.println(); 1072 1073 if (CmsLog.INIT.isInfoEnabled()) { 1075 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1076 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1077 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1078 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1079 for (int i = 0; i < Messages.COPYRIGHT_BY_ALKACON.length; i++) { 1080 CmsLog.INIT.info(". " + Messages.COPYRIGHT_BY_ALKACON[i]); 1081 } 1082 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LINE_0)); 1083 CmsLog.INIT.info(Messages.get().getBundle().key( 1084 Messages.INIT_STARTUP_TIME_1, 1085 new Date (System.currentTimeMillis()))); 1086 CmsLog.INIT.info(Messages.get().getBundle().key( 1087 Messages.INIT_OPENCMS_VERSION_1, 1088 OpenCms.getSystemInfo().getVersionName())); 1089 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_SERVLET_CONTAINER_1, context.getServerInfo())); 1090 CmsLog.INIT.info(Messages.get().getBundle().key( 1091 Messages.INIT_WEBAPP_NAME_1, 1092 getSystemInfo().getWebApplicationName())); 1093 CmsLog.INIT.info(Messages.get().getBundle().key( 1094 Messages.INIT_SERVLET_PATH_1, 1095 getSystemInfo().getServletPath())); 1096 CmsLog.INIT.info(Messages.get().getBundle().key( 1097 Messages.INIT_OPENCMS_CONTEXT_1, 1098 getSystemInfo().getOpenCmsContext())); 1099 CmsLog.INIT.info(Messages.get().getBundle().key( 1100 Messages.INIT_WEBINF_PATH_1, 1101 getSystemInfo().getWebInfRfsPath())); 1102 CmsLog.INIT.info(Messages.get().getBundle().key( 1103 Messages.INIT_PROPERTY_FILE_1, 1104 getSystemInfo().getConfigurationFileRfsPath())); 1105 CmsLog.INIT.info(Messages.get().getBundle().key( 1106 Messages.INIT_LOG_FILE_1, 1107 getSystemInfo().getLogFileRfsPath())); 1108 } 1109 1110 initConfiguration(configuration); 1112 } 1113 1114 1117 protected void initMembers() { 1118 1119 synchronized (LOCK) { 1120 m_resourceInitHandlers = new ArrayList (); 1121 m_requestHandlers = new HashMap (); 1122 m_systemInfo = new CmsSystemInfo(); 1123 m_exportPoints = Collections.EMPTY_SET; 1124 m_defaultUsers = new CmsDefaultUsers(); 1125 m_localeManager = new CmsLocaleManager(Locale.ENGLISH); 1126 m_sessionManager = new CmsSessionManager(); 1127 m_runtimeProperties = new Hashtable (); 1128 m_eventManager = new CmsEventManager(); 1130 } 1131 } 1132 1133 1159 protected CmsResource initResource( 1160 CmsObject cms, 1161 String resourceName, 1162 HttpServletRequest req, 1163 HttpServletResponse res) throws CmsException { 1164 1165 CmsResource resource = null; 1166 CmsException tmpException = null; 1167 1168 try { 1169 resource = cms.readResource(resourceName); 1171 if (resource.isFolder()) { 1173 try { 1175 String defaultFileName = cms.readPropertyObject( 1176 CmsResource.getFolderPath(cms.getSitePath(resource)), 1177 CmsPropertyDefinition.PROPERTY_DEFAULT_FILE, 1178 false).getValue(); 1179 if (defaultFileName != null) { 1180 String tmpResourceName = CmsResource.getFolderPath(cms.getSitePath(resource)) + defaultFileName; 1182 resource = cms.readResource(tmpResourceName); 1183 cms.getRequestContext().setUri(tmpResourceName); 1185 } 1186 } catch (CmsSecurityException se) { 1187 throw se; 1189 } catch (CmsException e) { 1190 } 1192 if (resource.isFolder()) { 1193 for (int i = 0; i < m_defaultFiles.size(); i++) { 1195 String tmpResourceName = CmsResource.getFolderPath(cms.getSitePath(resource)) 1196 + m_defaultFiles.get(i); 1197 try { 1198 resource = cms.readResource(tmpResourceName); 1199 cms.getRequestContext().setUri(tmpResourceName); 1201 break; 1203 } catch (CmsSecurityException se) { 1204 throw se; 1206 } catch (CmsException e) { 1207 } 1209 } 1210 } 1211 } 1212 if (resource.isFolder()) { 1213 resource = null; 1215 } 1216 } catch (CmsException e) { 1217 tmpException = e; 1219 resource = null; 1220 } 1221 1222 if (resource != null) { 1223 if ((resource.getFlags() & CmsResource.FLAG_INTERNAL) > 0) { 1225 throw new CmsException(Messages.get().container( 1226 Messages.ERR_READ_INTERNAL_RESOURCE_1, 1227 cms.getRequestContext().getUri())); 1228 } 1229 1230 if (cms.getRequestContext().currentProject().isOnlineProject()) { 1232 boolean secure = Boolean.valueOf( 1234 cms.readPropertyObject(cms.getSitePath(resource), CmsPropertyDefinition.PROPERTY_SECURE, true).getValue()).booleanValue(); 1235 if (secure) { 1236 CmsSite site = CmsSiteManager.getCurrentSite(cms); 1238 boolean usingSec = req.getRequestURL().toString().toUpperCase().startsWith( 1240 site.getSecureUrl().toUpperCase()); 1241 if (site.isExclusiveUrl() && !usingSec) { 1242 resource = null; 1243 if (site.isExclusiveError()) { 1245 throw new CmsVfsResourceNotFoundException(Messages.get().container( 1247 Messages.ERR_REQUEST_SECURE_RESOURCE_0)); 1248 } else { 1249 String uri = req.getRequestURL().toString(); 1251 String target = site.getSecureUrl() 1252 + uri.substring(uri.indexOf("/", uri.indexOf("//") + 2)); 1253 try { 1254 res.sendRedirect(target); 1255 } catch (Exception e) { 1256 } 1258 } 1259 } 1260 } 1261 } 1262 } 1263 1264 Iterator i = m_resourceInitHandlers.iterator(); 1266 while (i.hasNext()) { 1267 try { 1268 resource = ((I_CmsResourceInit)i.next()).initResource(resource, cms, req, res); 1269 } catch (CmsResourceInitException e) { 1271 break; 1272 } 1273 } 1274 1275 if (resource == null && tmpException != null) { 1277 throw tmpException; 1278 } 1279 1280 return resource; 1282 } 1283 1284 1294 protected void initServlet(OpenCmsServlet servlet) { 1295 1296 synchronized (LOCK) { 1297 addRequestHandler(servlet); 1299 if (CmsLog.INIT.isInfoEnabled()) { 1301 CmsLog.INIT.info(Messages.get().getBundle().key( 1302 Messages.INIT_SYSTEM_RUNNING_1, 1303 CmsStringUtil.formatRuntime(getSystemInfo().getRuntime()))); 1304 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LINE_0)); 1305 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1306 } 1307 } 1308 } 1309 1310 1318 protected void setRuntimeProperty(Object key, Object value) { 1319 1320 m_runtimeProperties.put(key, value); 1321 } 1322 1323 1328 protected void setSessionManager(CmsSessionManager sessionManager) { 1329 1330 m_sessionManager = sessionManager; 1331 } 1332 1333 1340 protected void showResource(HttpServletRequest req, HttpServletResponse res) { 1341 1342 CmsObject cms = null; 1343 try { 1344 cms = initCmsObject(req, res); 1345 CmsResource resource = initResource(cms, cms.getRequestContext().getUri(), req, res); 1347 if (resource != null) { 1348 m_resourceManager.loadResource(cms, resource, req, res); 1350 updateUserSessionData(cms, req); 1351 } 1352 1353 } catch (Throwable t) { 1354 errorHandling(cms, req, res, t); 1355 } 1356 } 1357 1358 1361 protected void shutDown() { 1362 1363 synchronized (LOCK) { 1364 if (getRunLevel() > OpenCms.RUNLEVEL_0_OFFLINE) { 1365 1366 System.err.println(Messages.get().getBundle().key( 1367 Messages.LOG_SHUTDOWN_CONSOLE_NOTE_2, 1368 getSystemInfo().getVersionName(), 1369 getSystemInfo().getWebApplicationName())); 1370 if (CmsLog.INIT.isInfoEnabled()) { 1371 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1372 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1373 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LINE_0)); 1374 CmsLog.INIT.info(Messages.get().getBundle().key( 1375 Messages.INIT_SHUTDOWN_START_1, 1376 getSystemInfo().getVersionName())); 1377 CmsLog.INIT.info(Messages.get().getBundle().key( 1378 Messages.INIT_CURRENT_RUNLEVEL_1, 1379 new Integer (getRunLevel()))); 1380 CmsLog.INIT.info(Messages.get().getBundle().key( 1381 Messages.INIT_SHUTDOWN_TIME_1, 1382 new Date (System.currentTimeMillis()))); 1383 } 1384 1385 setRunLevel(OpenCms.RUNLEVEL_0_OFFLINE); 1387 1388 if (LOG.isDebugEnabled()) { 1389 LOG.debug(Messages.get().getBundle().key(Messages.LOG_SHUTDOWN_TRACE_0), new Exception ()); 1391 } 1392 1393 try { 1394 if (m_staticExportManager != null) { 1395 m_staticExportManager.shutDown(); 1396 } 1397 } catch (Throwable e) { 1398 CmsLog.INIT.error(Messages.get().getBundle().key( 1399 Messages.LOG_ERROR_EXPORT_SHUTDOWN_1, 1400 e.getMessage()), e); 1401 } 1402 try { 1403 if (m_moduleManager != null) { 1404 m_moduleManager.shutDown(); 1405 } 1406 } catch (Throwable e) { 1407 CmsLog.INIT.error(Messages.get().getBundle().key( 1408 Messages.LOG_ERROR_MODULE_SHUTDOWN_1, 1409 e.getMessage()), e); 1410 } 1411 try { 1412 if (m_scheduleManager != null) { 1413 m_scheduleManager.shutDown(); 1414 } 1415 } catch (Throwable e) { 1416 CmsLog.INIT.error(Messages.get().getBundle().key( 1417 Messages.LOG_ERROR_SCHEDULE_SHUTDOWN_1, 1418 e.getMessage()), e); 1419 } 1420 try { 1421 if (m_resourceManager != null) { 1422 m_resourceManager.shutDown(); 1423 } 1424 } catch (Throwable e) { 1425 CmsLog.INIT.error(Messages.get().getBundle().key( 1426 Messages.LOG_ERROR_RESOURCE_SHUTDOWN_1, 1427 e.getMessage()), e); 1428 } 1429 try { 1430 if (m_securityManager != null) { 1431 m_securityManager.destroy(); 1432 } 1433 } catch (Throwable e) { 1434 CmsLog.INIT.error(Messages.get().getBundle().key( 1435 Messages.LOG_ERROR_SECURITY_SHUTDOWN_1, 1436 e.getMessage()), e); 1437 } 1438 try { 1439 if (m_threadStore != null) { 1440 m_threadStore.shutDown(); 1441 } 1442 } catch (Throwable e) { 1443 CmsLog.INIT.error(Messages.get().getBundle().key( 1444 Messages.LOG_ERROR_THREAD_SHUTDOWN_1, 1445 e.getMessage()), e); 1446 } 1447 String runtime = CmsStringUtil.formatRuntime(getSystemInfo().getRuntime()); 1448 if (CmsLog.INIT.isInfoEnabled()) { 1449 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_OPENCMS_STOPPED_1, runtime)); 1450 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_LINE_0)); 1451 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1452 CmsLog.INIT.info(Messages.get().getBundle().key(Messages.INIT_DOT_0)); 1453 } 1454 System.err.println(Messages.get().getBundle().key(Messages.LOG_CONSOLE_TOTAL_RUNTIME_1, runtime)); 1455 1456 } 1457 m_instance = null; 1458 } 1459 } 1460 1461 1472 protected OpenCmsCore upgradeRunlevel(ExtendedProperties configuration) throws CmsInitException { 1473 1474 synchronized (LOCK) { 1475 if ((m_instance != null) && (getRunLevel() >= OpenCms.RUNLEVEL_2_INITIALIZING)) { 1476 return m_instance; 1478 } 1479 if (getRunLevel() != OpenCms.RUNLEVEL_1_CORE_OBJECT) { 1480 CmsLog.INIT.error(Messages.get().getBundle().key( 1481 Messages.LOG_WRONG_INIT_SEQUENCE_2, 1482 new Integer (3), 1483 new Integer (getRunLevel()))); 1484 return m_instance; 1485 } 1486 1487 setRunLevel(OpenCms.RUNLEVEL_2_INITIALIZING); 1489 m_instance.initConfiguration(configuration); 1491 setRunLevel(OpenCms.RUNLEVEL_3_SHELL_ACCESS); 1493 1494 return m_instance; 1495 } 1496 } 1497 1498 1509 protected OpenCmsCore upgradeRunlevel(ServletContext context) throws CmsInitException { 1510 1511 synchronized (LOCK) { 1512 if ((m_instance != null) && (getRunLevel() >= OpenCms.RUNLEVEL_4_SERVLET_ACCESS)) { 1513 return m_instance; 1515 } 1516 if (getRunLevel() != OpenCms.RUNLEVEL_1_CORE_OBJECT) { 1517 CmsLog.INIT.error(Messages.get().getBundle().key( 1518 Messages.LOG_WRONG_INIT_SEQUENCE_2, 1519 new Integer (4), 1520 new Integer (getRunLevel()))); 1521 return m_instance; 1522 } 1523 1524 setRunLevel(OpenCms.RUNLEVEL_2_INITIALIZING); 1526 m_instance.initContext(context); 1528 setRunLevel(OpenCms.RUNLEVEL_4_SERVLET_ACCESS); 1531 1532 return m_instance; 1533 } 1534 } 1535 1536 1541 protected void writeConfiguration(Class clazz) { 1542 1543 try { 1545 m_configurationManager.writeConfiguration(clazz); 1546 } catch (IOException e) { 1547 CmsLog.getLog(CmsConfigurationManager.class).error( 1548 Messages.get().getBundle().key(Messages.LOG_ERROR_WRITING_CONFIG_1, clazz.getName()), 1549 e); 1550 } catch (CmsConfigurationException e) { 1551 CmsLog.getLog(CmsConfigurationManager.class).error( 1552 Messages.get().getBundle().key(Messages.LOG_ERROR_WRITING_CONFIG_1, clazz.getName()), 1553 e); 1554 } 1555 } 1556 1557 1562 private void addExportPoints(Set exportPoints) { 1563 1564 HashSet newSet = new HashSet (m_exportPoints.size() + exportPoints.size()); 1566 newSet.addAll(exportPoints); 1567 newSet.addAll(m_exportPoints); 1568 m_exportPoints = Collections.unmodifiableSet(newSet); 1569 } 1570 1571 1580 private void checkBasicAuthorization(CmsObject cms, HttpServletRequest req, HttpServletResponse res) 1581 throws IOException { 1582 1583 String auth = req.getHeader("Authorization"); 1585 1586 if (auth != null) { 1588 1589 if (auth.toUpperCase().startsWith("BASIC ")) { 1591 1592 String base64Token = auth.substring(6); 1594 1595 String token = new String (Base64.decodeBase64(base64Token.getBytes())); 1597 String username = null; 1598 String password = null; 1599 int pos = token.indexOf(":"); 1600 if (pos != -1) { 1601 username = token.substring(0, pos); 1602 password = token.substring(pos + 1); 1603 } 1604 try { 1606 try { 1607 cms.loginUser(username, password); 1609 } catch (CmsException exc) { 1610 cms.loginWebUser(username, password); 1612 } 1613 req.getSession(true); 1615 } catch (CmsException e) { 1616 requestAuthorization(req, res); 1618 } 1619 } 1620 } 1621 } 1622 1623 1634 private String createErrorBox(Throwable t, HttpServletRequest request, CmsObject cms) { 1635 1636 String errorUri = CmsFlexController.getThrowableResourceUri(request); 1637 if (errorUri == null) { 1638 errorUri = cms.getRequestContext().getUri(); 1639 } 1640 Throwable cause = CmsFlexController.getThrowable(request); 1642 if (cause == null) { 1643 cause = t; 1644 } 1645 CmsErrorBean errorBean = new CmsErrorBean(cms, cause); 1646 errorBean.setParamAction(errorUri); 1647 return errorBean.toHtml(); 1648 } 1649 1650 1658 private void errorHandling(CmsObject cms, HttpServletRequest req, HttpServletResponse res, Throwable t) { 1659 1660 CmsFlexController.removeController(req); 1662 1663 boolean canWrite = !res.isCommitted() && !res.containsHeader("Location"); 1664 int status = -1; 1665 boolean isNotGuest = false; 1666 1667 if (t instanceof ServletException ) { 1668 ServletException s = (ServletException )t; 1669 if (s.getRootCause() != null) { 1670 t = s.getRootCause(); 1671 } 1672 } else if (t instanceof CmsSecurityException) { 1673 if (canWrite) { 1675 try { 1676 requestAuthorization(req, res); 1677 } catch (IOException ioe) { 1678 } 1680 return; 1681 } 1682 } else if (t instanceof CmsDbEntryNotFoundException) { 1683 status = HttpServletResponse.SC_SERVICE_UNAVAILABLE; 1685 isNotGuest = true; 1686 } else if (t instanceof CmsVfsResourceNotFoundException) { 1687 status = HttpServletResponse.SC_NOT_FOUND; 1689 } else if (t instanceof CmsException) { 1690 if (t.getCause() != null) { 1691 t = t.getCause(); 1692 } 1693 } 1694 1695 if (status < 1) { 1696 status = HttpServletResponse.SC_INTERNAL_SERVER_ERROR; 1698 } 1699 res.setStatus(status); 1700 1701 try { 1702 isNotGuest = isNotGuest 1703 || (cms != null 1704 && cms.getRequestContext().currentUser() != null 1705 && (!OpenCms.getDefaultUsers().getUserGuest().equals( 1706 cms.getRequestContext().currentUser().getName())) && ((cms.userInGroup( 1707 cms.getRequestContext().currentUser().getName(), 1708 OpenCms.getDefaultUsers().getGroupUsers())) 1709 || (cms.userInGroup( 1710 cms.getRequestContext().currentUser().getName(), 1711 OpenCms.getDefaultUsers().getGroupProjectmanagers())) || (cms.userInGroup( 1712 cms.getRequestContext().currentUser().getName(), 1713 OpenCms.getDefaultUsers().getGroupAdministrators())))); 1714 } catch (CmsException e) { 1715 } 1717 1718 if (canWrite) { 1719 res.setContentType("text/html"); 1720 CmsRequestUtil.setNoCacheHeaders(res); 1721 if (isNotGuest && cms != null && !cms.getRequestContext().currentProject().isOnlineProject()) { 1722 try { 1723 res.setStatus(HttpServletResponse.SC_OK); 1724 res.getWriter().print(createErrorBox(t, req, cms)); 1725 } catch (IOException e) { 1726 } 1728 } else { 1729 try { 1730 res.sendError(status, t.toString()); 1731 } catch (IOException e) { 1732 } 1734 } 1735 } 1736 } 1737 1738 1747 private CmsObject initCmsObject(CmsContextInfo contextInfo) throws CmsException { 1748 1749 CmsUser user = contextInfo.getUser(); 1750 if (user == null) { 1751 user = m_securityManager.readUser(contextInfo.getUserName()); 1752 } 1753 1754 CmsProject project = contextInfo.getProject(); 1755 if (project == null) { 1756 project = m_securityManager.readProject(contextInfo.getProjectName()); 1757 } 1758 1759 CmsRequestContext context = new CmsRequestContext( 1761 user, 1762 project, 1763 contextInfo.getRequestedUri(), 1764 contextInfo.getSiteRoot(), 1765 contextInfo.getLocale(), 1766 contextInfo.getEncoding(), 1767 contextInfo.getRemoteAddr(), 1768 m_resourceManager.getFolderTranslator(), 1769 m_resourceManager.getFileTranslator()); 1770 1771 CmsObject cms = new CmsObject(m_securityManager, context); 1773 return cms; 1774 } 1775 1776 1797 private CmsObject initCmsObject(HttpServletRequest req, HttpServletResponse res) throws IOException , CmsException { 1798 1799 CmsObject cms; 1800 1801 HttpSession session = req.getSession(false); 1803 String sessionId; 1804 1805 if (session != null) { 1807 sessionId = session.getId(); 1809 } else { 1810 sessionId = req.getHeader(CmsRequestUtil.HEADER_JSESSIONID); 1812 } 1813 CmsSessionInfo sessionInfo = null; 1814 if (sessionId != null) { 1815 sessionInfo = m_sessionManager.getSessionInfo(sessionId); 1816 } 1817 1818 CmsSite site = getSiteManager().matchRequest(req); 1820 1821 if (sessionInfo != null) { 1822 int project = sessionInfo.getProject(); 1824 1825 String siteroot = null; 1827 if ((getSiteManager().getWorkplaceSiteMatcher().equals(site.getSiteMatcher()))) { 1829 siteroot = sessionInfo.getSiteRoot(); 1832 } 1833 if (siteroot == null) { 1834 siteroot = site.getSiteRoot(); 1835 } 1836 cms = initCmsObject(req, sessionInfo.getUser().getName(), siteroot, project); 1837 } else { 1838 cms = initCmsObject( 1840 req, 1841 OpenCms.getDefaultUsers().getUserGuest(), 1842 site.getSiteRoot(), 1843 CmsProject.ONLINE_PROJECT_ID); 1844 checkBasicAuthorization(cms, req, res); 1846 } 1847 1848 return cms; 1850 } 1851 1852 1867 private CmsObject initCmsObject(HttpServletRequest req, HttpServletResponse res, String user, String password) 1868 throws CmsException { 1869 1870 String siteroot = null; 1871 if ((req != null) && (res != null)) { 1873 siteroot = OpenCms.getSiteManager().matchRequest(req).getSiteRoot(); 1874 } 1875 if (user == null) { 1877 user = getDefaultUsers().getUserGuest(); 1878 } 1879 if (siteroot == null) { 1880 siteroot = "/"; 1881 } 1882 CmsObject cms = initCmsObject(req, user, siteroot, CmsProject.ONLINE_PROJECT_ID); 1883 if ((password != null) && !getDefaultUsers().getUserGuest().equals(user)) { 1885 cms.loginUser(user, password, CmsContextInfo.LOCALHOST); 1886 } 1887 return cms; 1888 } 1889 1890 1900 private CmsObject initCmsObject(HttpServletRequest req, String userName, String currentSite, int projectId) 1901 throws CmsException { 1902 1903 CmsUser user = m_securityManager.readUser(userName); 1904 CmsProject project = null; 1905 try { 1906 project = m_securityManager.readProject(projectId); 1907 } catch (CmsDbEntryNotFoundException e) { 1908 project = m_securityManager.readProject(CmsProject.ONLINE_PROJECT_ID); 1910 } 1911 1912 String requestedResource = null; 1914 if (req != null) { 1915 requestedResource = req.getPathInfo(); 1916 } 1917 if (requestedResource == null) { 1918 requestedResource = "/"; 1920 } 1921 1922 String remoteAddr; 1924 if (req != null) { 1925 remoteAddr = req.getHeader(CmsRequestUtil.HEADER_X_FORWARDED_FOR); 1926 if (remoteAddr == null) { 1927 remoteAddr = req.getRemoteAddr(); 1928 } 1929 } else { 1930 remoteAddr = CmsContextInfo.LOCALHOST; 1931 } 1932 1933 CmsI18nInfo i18nInfo; 1935 if (m_localeManager.isInitialized()) { 1936 String resourceName; 1939 if (requestedResource.startsWith(CmsWorkplace.VFS_PATH_SYSTEM)) { 1940 resourceName = requestedResource; 1942 } else { 1943 resourceName = currentSite.concat(requestedResource); 1944 } 1945 i18nInfo = m_localeManager.getI18nInfo(req, user, project, resourceName); 1946 } else { 1947 i18nInfo = new CmsI18nInfo(Locale.ENGLISH, getSystemInfo().getDefaultEncoding()); 1951 } 1952 1953 requestedResource = CmsEncoder.decode(requestedResource); 1955 1956 CmsContextInfo contextInfo = new CmsContextInfo( 1958 user, 1959 project, 1960 requestedResource, 1961 currentSite, 1962 i18nInfo.getLocale(), 1963 i18nInfo.getEncoding(), 1964 remoteAddr); 1965 1966 return initCmsObject(contextInfo); 1968 } 1969 1970 1978 private void requestAuthorization(HttpServletRequest req, HttpServletResponse res) throws IOException { 1979 1980 CmsObject adminCms; 1982 try { 1983 adminCms = initCmsObject(req, res, getDefaultUsers().getUserAdmin(), null); 1984 } catch (CmsException e) { 1985 throw new IOException (Messages.get().getBundle().key( 1987 Messages.ERR_INVALID_INIT_USER_2, 1988 getDefaultUsers().getUserAdmin(), 1989 null)); 1990 } 1991 String path = adminCms.getRequestContext().getUri(); 1993 CmsProperty propertyLoginForm = null; 1994 String redirectURL = null; 1995 try { 1996 propertyLoginForm = adminCms.readPropertyObject(path, CmsPropertyDefinition.PROPERTY_LOGIN_FORM, true); 1997 } catch (Throwable t) { 1998 if (LOG.isWarnEnabled()) { 1999 LOG.warn(Messages.get().getBundle().key( 2000 Messages.LOG_ERROR_READING_AUTH_PROP_2, 2001 CmsPropertyDefinition.PROPERTY_LOGIN_FORM, 2002 path), t); 2003 } 2004 } 2005 2006 CmsHttpAuthenticationSettings httpAuthenticationSettings = getSystemInfo().getHttpAuthenticationSettings(); 2007 String pathWithParams = CmsRequestUtil.encodeParamsWithUri(path, req); 2008 if (propertyLoginForm != null 2009 && propertyLoginForm != CmsProperty.getNullProperty() 2010 && CmsStringUtil.isNotEmpty(propertyLoginForm.getValue())) { 2011 redirectURL = propertyLoginForm.getValue() 2016 + "?__loginform=true&" 2017 + CmsWorkplaceManager.PARAM_LOGIN_REQUESTED_RESOURCE 2018 + "=" 2019 + pathWithParams; 2020 } else if (!httpAuthenticationSettings.useBrowserBasedHttpAuthentication() 2021 && CmsStringUtil.isNotEmpty(httpAuthenticationSettings.getFormBasedHttpAuthenticationUri())) { 2022 redirectURL = httpAuthenticationSettings.getFormBasedHttpAuthenticationUri() 2025 + "?" 2026 + CmsWorkplaceManager.PARAM_LOGIN_REQUESTED_RESOURCE 2027 + "=" 2028 + pathWithParams; 2029 } 2030 2031 if (redirectURL == null) { 2032 res.setHeader(CmsRequestUtil.HEADER_WWW_AUTHENTICATE, "BASIC realm=\"" 2034 + getSystemInfo().getOpenCmsContext() 2035 + "\""); 2036 res.setStatus(HttpServletResponse.SC_UNAUTHORIZED); 2037 } else { 2038 redirectURL = m_linkManager.substituteLink(adminCms, redirectURL, null, true); 2040 if (LOG.isDebugEnabled()) { 2041 LOG.debug(Messages.get().getBundle().key(Messages.LOG_AUTHENTICATE_PROPERTY_2, redirectURL, path)); 2042 } 2043 res.sendRedirect(redirectURL); 2045 } 2046 } 2047 2048 2056 private void setRunLevel(int level) { 2057 2058 if (m_instance != null) { 2059 if (m_instance.m_runLevel >= OpenCms.RUNLEVEL_1_CORE_OBJECT) { 2060 if (CmsLog.INIT.isInfoEnabled()) { 2062 CmsLog.INIT.info(Messages.get().getBundle().key( 2063 Messages.INIT_RUNLEVEL_CHANGE_2, 2064 new Integer (m_instance.m_runLevel), 2065 new Integer (level))); 2066 } 2067 } 2068 m_instance.m_runLevel = level; 2069 } 2070 } 2071 2072 2084 private void updateUserSessionData(CmsObject cms, HttpServletRequest req) { 2085 2086 if (!cms.getRequestContext().isUpdateSessionEnabled()) { 2087 return; 2090 } 2091 HttpSession session = req.getSession(false); 2093 if (session != null) { 2096 if (!cms.getRequestContext().currentUser().isGuestUser()) { 2097 CmsSessionInfo sessionInfo = m_sessionManager.getSessionInfo(session.getId()); 2099 if (sessionInfo != null) { 2100 sessionInfo.update(cms.getRequestContext()); 2102 } else { 2103 sessionInfo = new CmsSessionInfo( 2105 cms.getRequestContext(), 2106 session.getId(), 2107 session.getMaxInactiveInterval()); 2108 m_sessionManager.addSessionInfo(sessionInfo); 2110 } 2111 } 2112 } 2113 } 2114} | Popular Tags |