我有一個Java-webapp。該webapp被打包成一個war文件。這些war文件允許通過HTTP直接傳遞靜態內容。對於這場戰爭中的servlet,我可以進行HTTP認證(使用servlet本身實現)。但我也想要靜態內容的HTTP-auth。我怎麼能意識到這一點?在Java-webapp(war)中,如何使用靜態內容的HTTP-auth?
2
A
回答
2
創建一個實現javax.servlet.Filter的類。請參閱The Essentials of Filters
主要方法是傳遞ServletRequest,ServletResponse和FilterChain對象的doFilter。這就是你強制認證的地方。
然後在web.xml中聲明和過濾器映射你的過濾器如下(映射到每一個請求)
<filter>
<filter-name>Authentication Filter</filter-name>
<filter-class>
com.nfsdsystems.security.filters.AuthenticationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Authentication Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
3
把你靜態HTML文件的direcotry並在你的web.xml定義安全約束。將約束映射到適當的角色。
<security-constraint>
<display-name>securedResources</display-name>
<web-resource-collection>
<web-resource-name>securedRes</web-resource-name>
<url-pattern>/secured/*</url-pattern>
<http-method>GET</http-method>
<http-method>PUT</http-method>
<http-method>HEAD</http-method>
<http-method>TRACE</http-method>
<http-method>POST</http-method>
<http-method>DELETE</http-method>
<http-method>OPTIONS</http-method>
</web-resource-collection>
<auth-constraint>
<description>
authenticatedUser_securedRes</description>
<role-name>authenticatedUsed</role-name>
</auth-constraint>
</security-constraint>
+0
這確實是使用領域做它的首選方式。 – Nathan 2009-05-05 19:20:43
相關問題
- 1. eclipse中的Jetty - 從.war中加載靜態內容
- 2. 如何在Rails中做靜態內容?
- 3. 如何使用Tomcat + Spring Security在靜態內容中實施HTTPS
- 4. 如何使用Maven在WAR的根目錄中添加內容?
- 5. 如何在靜態軌道上創建靜態內容的靜態內容動態編輯選項
- 6. 靜態內容
- 7. 靜態內容
- 8. 在IB/Storyboarding中創建的靜態UITableView使用動態內容?
- 9. 使用參數cacheControlControlling的靜態內容
- 10. 如何在Express.js中提供用戶特定的靜態內容
- 11. 如何在MVC視圖中重用簡單的靜態內容
- 12. docpad系統中的靜態與動態內容 - 如何創建動態內容?
- 13. 我應該如何結合使用CakePHP的靜態+非靜態內容
- 14. 如何在Microsoft Azure上使用web.py提供靜態內容?
- 15. 如何使用Docker在Node Express容器中提供靜態內容?
- 16. 如何將所有靜態內容保留在內容之下?
- 17. 調用靜態內容
- 18. 在Django中的PyBBM靜態內容
- 19. 靜態內容在Django
- 20. Html.dropdownlist靜態內容
- 21. 如何在Struts2中動態地提供靜態內容
- 22. 如何在AppFog中使用Apache的靜態內容(WSGI Python應用程序)
- 23. 如何在spring-servlet.xml中的靜態內容路徑中使用變量
- 24. 如何在newrelic中爲Apache靜態內容啓用RUM
- 25. 如何在導軌應用程序中管理靜態內容
- 26. 使用引導刷新靜態內容
- 27. 使用CherryPy加載靜態內容
- 28. nodejs靜態內容不使用sendFile
- 29. 使用Git和CDN靜態內容
- 30. 使用thoughtbot/high_voltage提供靜態內容
這對我很好。我寫了我自己的過濾器。 – Mnementh 2009-05-06 14:18:41