2009-05-05 27 views

回答

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> 
+0

這對我很好。我寫了我自己的過濾器。 – Mnementh 2009-05-06 14:18:41

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

相關問題