在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>
首先定義了tomcat-users.xml 中的內容,主要設置了用戶和角色













然后在application中的web.xml中對應的<web-app>中增加如下設置





















這樣就好了,登錄這個web應用會有個驗證窗口彈出,輸入用戶名abc和密碼abc后就能正常訪問了。
在weblogic8.1中的配置比較麻煩,首先在web.xml的<web-app>中增加上面一段代碼后,還要加上這一段



然后新建一個weblogic.xml 內容如下











進入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啦。