我有一个Java-webapp。webapp被打包成一个war文件。这些war文件允许通过HTTP直接传递的静态内容。在这场战争中,对于servlet,我可以进行HTTP身份验证(使用servlet本身实现它)。但是我也想要静态内容的HTTP-auth。我怎么才能意识到这一点呢?
发布于 2009-05-05 15:18:40
创建一个实现javax.servlet.Filter的类。请参阅The Essentials of Filters
main方法是传递给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>发布于 2009-05-05 16:04:30
将静态html文件放在目录中,并在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>https://stackoverflow.com/questions/825142
复制相似问题