牛仔裤的夏天

JAVA是蓝色的- online

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  30 随笔 :: 5 文章 :: 15 评论 :: 0 Trackbacks
在tomcat中的配置比较简单
首先定义了tomcat-users.xml 中的内容,主要设置了用户和角色
<?xml version='1.0' encoding='utf-8'?>
<tomcat-users>
  
<role rolename="tomcat"/>
  
<role rolename="role1"/>
  
<role rolename="manager"/>
  
<role rolename="wxds" description=""/>
  
<role rolename="admin"/>
  
<user username="tomcat" password="tomcat" roles="tomcat"/>
  
<user username="both" password="tomcat" roles="tomcat,role1"/>
  
<user username="role1" password="tomcat" roles="role1"/>
  
<user username="abc" password="abc" fullName="abcabc" roles="wxds"/>
  
<user username="admin" password="" roles="admin,manager"/>
</tomcat-users>

然后在application中的web.xml中对应的<web-app>中增加如下设置
   <security-constraint>
       
<web-resource-collection>
           
<web-resource-name>Protected Area</web-resource-name>
        
<!-- Define the context-relative URL(s) to be protected -->
           
<url-pattern>*</url-pattern>
        
<!-- If you list http methods, only those methods are protected -->
        
<http-method>DELETE</http-method>
           
<http-method>GET</http-method>
           
<http-method>POST</http-method>
        
<http-method>PUT</http-method>
       
</web-resource-collection>
       
<auth-constraint>
           
<!-- Anyone with one of the listed roles may access this area -->
           
<role-name>wxds</role-name>
       
</auth-constraint>
   
</security-constraint>
   
<login-config>
       
<auth-method>BASIC</auth-method>
       
<realm-name>EShop</realm-name>
   
</login-config>

这样就好了,登录这个web应用会有个验证窗口弹出,输入用户名abc和密码abc后就能正常访问了。

在weblogic8.1中的配置比较麻烦,首先在web.xml的<web-app>中增加上面一段代码后,还要加上这一段
<security-role>
      
<role-name>wxds</role-name>
</security-role>

然后新建一个weblogic.xml 内容如下
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE weblogic-web-app PUBLIC "-//BEA Systems, Inc.//DTD Web Application 8.1//EN" "http://www.bea.com/servers/wls810/dtd/weblogic810-web-jar.dtd">

<weblogic-web-app>

  
<security-role-assignment>
    
<role-name>wxds</role-name>
    
<principal-name>wxds_group</principal-name>
  
</security-role-assignment>

</weblogic-web-app>

进入weblogic的console,在mydomain-security-realms中新建一个realm
name: wxdsRealm
check roles and policies for: web applications and ejbs protected in dd
展开wxdsRealm,
在providers中configure a new default adjudicator... 默认创建
在auditors中创建一个缺省auditor
然后创建一个缺省的authentication,authorizers, cred mappers 和role mapper 等等
最后可以在testing中测试一下 validate this security realm... 看是否successful

在groups中定义一个group name: wxds_group
在users中configure a new user
name: jyds password:11111111
把刚才建立的wxds_group 增加进来

把Security中的Default Realm设置为wxdsRealm, 最后Apply就ok啦。

posted on 2006-03-22 14:24 luckyrobbie 阅读(454) 评论(0)  编辑  收藏 所属分类: Tomcat & Weblogic

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


网站导航: