J2EE安全之Http基本验证
2008-11-14 15:08
691 查看
http基本验证也是常用保障j2ee程序安全的重要验证方式之一.
下面小结一下.
以tomcat的admin角色为例.
tomcat-users.xml代码如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>
若想将web项目中的/root目录下的资源只对admin角色开放.可如下配置项目的web.xml文件
<security-constraint>
<web-resource-collection>
<web-resource-name>zgx</web-resource-name>
<url-pattern>/root/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</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>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>zgx</realm-name>
</login-config>
这样,访问/root目录下的文件时,需要提供admin用户名和密码.
下面小结一下.
以tomcat的admin角色为例.
tomcat-users.xml代码如下:
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
<role rolename="tomcat"/>
<role rolename="role1"/>
<role rolename="manager"/>
<role rolename="admin"/>
<user username="tomcat" password="tomcat" roles="tomcat"/>
<user username="role1" password="tomcat" roles="role1"/>
<user username="both" password="tomcat" roles="tomcat,role1"/>
<user username="admin" password="admin" roles="admin,manager"/>
</tomcat-users>
若想将web项目中的/root目录下的资源只对admin角色开放.可如下配置项目的web.xml文件
<security-constraint>
<web-resource-collection>
<web-resource-name>zgx</web-resource-name>
<url-pattern>/root/*</url-pattern>
<http-method>POST</http-method>
<http-method>GET</http-method>
</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>
<security-role>
<role-name>admin</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>zgx</realm-name>
</login-config>
这样,访问/root目录下的文件时,需要提供admin用户名和密码.
相关文章推荐
- ASP.NET Web API(二):安全验证之使用HTTP基本认证
- 学习笔记之 WCF安全(2) 基本身份验证(windows账号密码)(wsHttpBinding)
- ASP.NET Web API(二):安全验证之使用HTTP基本认证
- ASP.NET Web API(二):安全验证之使用HTTP基本认证
- WCF分布式安全开发实践(2):传输安全模式之基本身份验证(Windows账户密码):Transport_Basic_WSHttpBinding
- WCF分布式安全开发实践(2):传输安全模式之基本身份验证(Windows账户密码):Transport_Basic_WSHttpBinding
- ASP.NET Web API:安全验证之使用HTTP基本认证
- ASP.NET Web API(二):安全验证之使用HTTP基本认证
- Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结Atitit HT
- Spring Http Basic(基本)和Digest(摘要)验证
- XMLHTTPRequest如何访问需要安全验证的网站
- WCF分布式安全开发实践(11):消息安全模式之Certificate身份验证:Message_Certificate_WSHttpBinding
- 学习笔记之 WCF安全(1) SSL安全,无客户端验证(wsHttpBinding)
- Spring HttpInvoker 服务端安全验证的和客户端请求配置
- webserver的安全验证+easyui-datagrid-treegrid源码改造支持httpheader设置
- Webserives安全之HTTP验证
- Atitit HTTP 认证机制基本验证 (Basic Authentication) 和摘要验证 (Digest Authentication)attilax总结
- HttpWebRequest向路由器提交基本身份验证
- WS BasicHttpBinding 安全解析(7)Certificate验证(IIS宿主)
- WCF分布式安全开发实践(11):消息安全模式之Certificate身份验证:Message_Certificate_WSHttpBinding