posts - 35,  comments - 7,  trackbacks - 0


安全域是Tomcat的内置功能,主要有以下几种安全域:
JDBCRealm
DataSourceRealm
JNDIRealm
MemoryRealm
JAASRealm

在conf/server.xml中配置应用的<Context......>下面的<Realm className="org.apache.catalina.realm.MemoryRealm" />
从一个XML文件中读取用户信息,默认的就是tomcat-users.xml

tomcat-users.xml中的角色定义
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users> 
    <role rolename="tomcat"/> 
    <role rolename="role1"/> 
    <role rolename="guest"/>
    <user username="lee" password="lee" roles="guest"/>
    <user username="suoxin" password="suoxin" roles="tomcat,role1"/>
</tomcat-users>

在应用下的web.xml中加入<security-constraint>元素
<security-constraint>  
    <web-resource-collection>
         <url-pattern>/*</url-pattern>   
    </web-resource-collection>   
    <auth-constraint>    
         <role-name>admin</role-name>   
         <role-name>guest</role-name>  
    </auth-constraint>
</security-constraint>

在应用下的web.xml中加入<login-config>元素
<login-config>     
   <auth-method>FORM</auth-method>
   <!--这里FORM是基于表单的验证,会跳转到mylogin.jsp,如果出错就到myerror.jsp,
   还有基于对话筐的是BASIC关键字,但是不安全在网络传输中。摘要验证DIGEST会采
   用MD5(Message Digest Algorithm)加密传输-->
   <form-login-config>       
      <form-login-page>/mylogin.jsp</form-login-page>       
      <form-error-page>/myerror.jsp</form-error-page>     
   </form-login-config>
</login-config>

mylogin.jsp的action和name必须严格规范写
<form name="form1" id="form1" method="post" action="j_security_check"> 
   <input type="text" name="j_username"/> 
   <input type="text" name="j_password"/>
   <input type="submit" name="Submit" value="提交" />
</form>

 

posted on 2006-02-11 09:11 java小记 阅读(215) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航:
 

<2006年2月>
2930311234
567891011
12131415161718
19202122232425
2627281234
567891011

常用链接

留言簿(1)

随笔分类

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜