1.security-constraint元素
部署描述符中的<security-constraint>元素允许不通过编程就可以限制对某个资源的访问。
<security-constraint> <display-name>default</display-name> <web-resource-collection> <web-resource-name>all files</web-resource-name> <url-pattern>/*</url-pattern> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint>
(1) web-resource-collection元素
web-resource-collection元素标识需要限制访问的资源子集。在web-resource-collection元素中,可以定义URL模式和HTTP方法。如果不存在HTTP方法,就将安全约束应用于所有的方法。
web-resource-name是与受保护资源相关联的名称。http-method元素可被赋予一个HTTP方法,比如GET和POS。
(2) auth-constraint元素
auth-constraint元素用于指定可以访问该资源集合的用户角色。如果没有指定auth-constraint元素,就将安全约束应用于所有角色。
role-name元素包含安全角色的名称。
(3) user-data-constraint元素
user-data-constraint元素用来显示怎样保护在客户端和Web容器之间传递的数据。
transport-guarantee元素必须具有如下的某个值:
● NONE,这意味着应用不需要传输保证。
● INTEGRAL,意味着服务器和客户端之间的数据必须以某种方式发送,而且在传送中不能改变。
● CONFIDENTIAL,这意味着传输的数据必须是加密的数据。
在大多数情况下,安全套接字层(SSL)用于INTEGRAL或CONFIDENTIAL。
2.login-config元素
login-config元素用来指定所使用的验证方法、领域名和表单验证机制所需的特性。
<login-config>
<auth-method>FORM</auth-method>
<realm-name>appTest</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/login_failed.jsp</form-error-page>
</form-login-config>
</login-config>
login-config子元素的描述如下:
● auth-method指定验证方法。它的值为下面的一个:BASIC、DIGEST、FORM或 CLIENT-CERT
● realm-name指定HTTP Basic验证中使用的领域名。
●form-login-config指定基于表单的登录中应该使用的登录页面和出错页面。如果没有使用基于表单的验证,则忽略这些元素。这个元素的定义如下,其中form-login-page用于指定显示登录页面的资源路径, form-error-page则用于指定用户登录失败时显示出错页面的资源路径。这两个页面路径都必须以a/开始,并与应用目录相对应。
3.security-role元素
security-role元素指定用于安全约束中的安全角色的声明。
<security-role>
<description>admin</description>
<role-name>admin</role-name>
</security-role>
<security-constraint> <display-name> baseporject</display-name> <web-resource-collection> <web-resource-name>baseproject</web-resource-name> <url-pattern>*.jsp</url-pattern> <url-pattern>*.do</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> baseproject</description> <role-name>All Role</role-name> </auth-constraint> <user-data-constraint> <transport-guarantee>NONE</transport-guarantee> </user-data-constraint> </security-constraint> <login-config>Xml代码 <!--四种验证方式,附在最后有说明--> <auth-method>FORM</auth-method> <form-login-config> <form-login-page>/login.html</form-login-page> <form-error-page>/error.html</form-error-page> </form-login-config> </login-config> <security-role> <role-name>All Role</role-name> </security-role>
自己项目采用:
<security-constraint> <web-resource-collection> <web-resource-name>testxiangmu</web-resource-name> <url-pattern>/ssl/*</url-pattern> </web-resource-collection> <user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint>
网上配置SSL的例子
http://www.oschina.net/question/12_23148
相关推荐
在web.xml文件中配置下面一段内容 <security-constraint> <web-resource-collection> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>DELETE</http-method> <http-method>HEAD</...
部署描述文件web.xml详解(web-app_2_3.dtd),全面介绍: 1. icon元素 2. display-name元素 3. description元素 4. distributable元素 5. context-param元素 6. filter元素 7. filter-mapping元素 8. ...
Tomcat压缩包 资源下载,tomcat自带了一套管理程序...无论是basic还是digest,设置过程基本一致,在conf/server.xml中添加realm数据源,在{project}/WEB-INF/web.xml中添加 security-constraint 和 login-config属性。
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
本书共分4部分,从xml、servlet、jsp和应用的角度向读者展示了java web开发中各种技术的应用,循序渐进地引导读者快速掌握java web开发。. 本书内容全面,涵盖了从事java web开发所应掌握的所有知识。在知识的讲解...
目录 前言 ............................... 3 其他资料 ......................................................................................................................................................
Introduction . . . . . . . . . ....1.1 Distributed Data Processing .... ....1.3 Data Delivery Alternatives ....1.4 Promises of DDBSs ....1.4.2 Reliability Through Distributed Transactions ....1.4.3 Improved Performance...
Servlet3.1规范(最终版) JavaTM Servlet 规范 版本 3.1(最终版) Shing Wai Chan Rajiv Mordani [作者] 穆茂强 张开涛 [译者] 2012年6月翻译 2013年7月修订 目录 前言 ..................................
You'll learn ways to design RESTful web services for client and server applications that meet performance, scalability, reliability, and security goals, no matter what programming language and ...