2012-03-23 42 views
4

新安裝的Tomcat v7.0和Eclipse。嘗試加載SSI Servlet支持。按照Tomcat的說明修改了context.xml和web.xml。Tomcat v7.0加載異常 - 將servlet ssi標記爲不可用

的context.xml(顯示的相關片段):

<Context reloadable="true" privileged="true"> 

    <!-- Default set of monitored resources --> 
    <WatchedResource>WEB-INF/web.xml</WatchedResource> 


</Context> 

web.xml文件(所顯示的相關片段):

<servlet> 
     <servlet-name>ssi</servlet-name> 
     <servlet-class> 
      org.apache.catalina.ssi.SSIServlet 
     </servlet-class> 
     <init-param> 
      <param-name>buffered</param-name> 
      <param-value>1</param-value> 
     </init-param> 
     <init-param> 
      <param-name>debug</param-name> 
      <param-value>0</param-value> 
     </init-param> 
     <init-param> 
      <param-name>expires</param-name> 
      <param-value>666</param-value> 
     </init-param> 
     <init-param> 
      <param-name>isVirtualWebappRelative</param-name> 
      <param-value>0</param-value> 
     </init-param> 
     <load-on-startup>4</load-on-startup> 
    </servlet> 

    <servlet-mapping> 
     <servlet-name>ssi</servlet-name> 
     <url-pattern>*.shtml</url-pattern> 
    </servlet-mapping> 

但我仍然得到以下負載例外:

Mar 23, 2012 12:06:00 PM org.apache.catalina.core.StandardContext loadOnStartup 
SEVERE: Servlet threw load() exception 
java.lang.SecurityException: Restricted class org.apache.catalina.ssi.SSIServlet 
    at 

org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:548) 
     at org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:539) 
    at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:509) 
    at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:124) 
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136) 
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1080) 
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5001) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5289) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525) 
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 

Mar 23, 2012 12:06:00 PM org.apache.catalina.core.ApplicationContext log 
INFO: Marking servlet ssi as unavailable 

我試過了我能想到的一切。任何人都可以建議如何解決這個問題? 謝謝!

回答

0

所以只是爲了確認(因爲這對我的作品):

  • 下載的Tomcat 7.0.26(ZIP)
  • 解壓後
  • 修改$ {TOMCAT_HOME)/conf/web.xml
    • 未註釋的周圍線的SSI servlet定義276
    • 未註釋的周圍線的SSI servlet映射370
  • 修改$ {} TOMCAT_HOME /conf/tomcat-users.xml
    • 新增角色管理器的GUI
    • 與管理貴角色
  • 添加了一個簡單ssi.shtml添加的用戶管理頁面$ {} TOMCAT_HOME/webapps /下主機經理:

    < - #printenv - >

  • 開始的Tomcat ,沒有錯誤,http://localhost:8080/host-manager/ssi.shtml按預期工作

最後 - 你正在編輯的Web應用程序,而不是在$ {} TOMCAT_HOME在web.xml/conf文件夾的context.xml的 - 我想是因爲你的例子有WatchedResource元素

1

我得到了與另一個包相同的問題:cgi而不是ssi。我將通過我發現的解決方案來解決錯誤。

與OP一樣,我安裝了Tomcat 7.0.27。我正在測試CGI。通過初始設置工作,我不斷得到以下幾點:

SEVERE: Servlet /TestTomcatApp threw load() exception 
java.lang.SecurityException: Restricted class org.apache.catalina.servlets.CGIServlet 
at  org.apache.catalina.core.DefaultInstanceManager.checkAccess(DefaultInstanceManager.java:548 ) 

這是非常相同的OP除了涉及的類。

我搜索「Tomcat的受限DefaultInstanceManager」和位於[本Java源代碼] [1]:

private void [More ...] checkAccess(Class<?> clazz, Properties restricted) { 
    while (clazz != null) { 
     if ("restricted".equals(restricted.getProperty(clazz.getName()))) { 
      throw new SecurityException("Restricted class" + clazz); 
     } 
     clazz = clazz.getSuperclass(); 
    } 
} 

Properties類(其可以是熱連接的,從所引用的代碼頁)所指示的代碼是最有可能讀取.properties文件。所以我能夠在catalina.properties和catalina.policy中找零。在這兩個文件的文檔的仔細閱讀,加上參考[Tomcat的SecurityManager的文檔]後[2]我意識到我必須授予語句添加到文件的catalina.policy:

// The Manager application needs access to the following packages to support the 
// session display functionality. These settings support the following 
// configurations: 
// - default CATALINA_HOME == CATALINA_BASE 
// - CATALINA_HOME != CATALINA_BASE, per instance Manager in CATALINA_BASE 
// - CATALINA_HOME != CATALINA_BASE, shared Manager in CATALINA_HOME 
grant codeBase "file:${catalina.base}/webapps/manager/-" { 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.ha.session"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager.util"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.util"; 
    **permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.servlets.CGIServlet";** 

}; 
grant codeBase "file:${catalina.home}/webapps/manager/-" { 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.ha.session"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.manager.util"; 
    permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.util"; 
    **permission java.lang.RuntimePermission "accessClassInPackage.org.apache.catalina.servlets.CGIServlet"; 
};** 

(我的加法粗體)

重新啓動Tomcat後,錯誤消失了。

注意:我意識到整個問題必須由在Tomcat上運行某些模塊的安全問題驅動。我的用途純粹是爲了在單臺機器上進行測試,並且在這種模式下預計不會有生產。

[1] http://grepcode.com/file/repo1.maven.org/maven2/org.apache.tomcat/tomcat-catalina/7.0.0/org/apache/catalina/core/DefaultInstanceManager.java#DefaultInstanceManager.checkAccess%28java.lang.Class%29

[2] http://tomcat.apache.org/tomcat-7.0-doc/security-manager-howto.html#Configuring_Tomcat_With_A_SecurityManager

6

我添加privileged="true"屬性上下文元件在context.xml文件在根。它爲我解決了CGI的安全異常。

我發現通過this site

+0

謝謝本!它也適用於我。 – 2014-07-25 10:47:27