TOMCAT鐨勫畨鍏ㄦ帶鍒剁瓥鐣ユ槸鏍規(guī)嵁Servlet 2.4瑙勮寖鏉ュ疄鐜扮殑銆?
1.鍦?CATALINA/conf/server.xml鏂囦歡涓厤緗?
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" debug="0" resourceName="UserDatabase"/>
榪欓噷UserDatabase鏄竴涓猨ndi鐨勫悕縐幫紝涔熼渶瑕佸湪server.xml涓厤緗紝瀵瑰簲浜?CATALINA/conf/tomcat-users.xml鏂囦歡
2.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="both" password="tomcat" roles="tomcat,role1"/>
<user username="manager" password="tomcat" roles="manager"/>
<user username="admin" password="tomcat" roles="admin"/>
</tomcat-users>
3.鍦ㄧ浉搴旂殑搴旂敤鐨剋eb.xml鏂囦歡涓姞鍏?lt;security-constraint><login-config> <security-role>鏍囩錛屽涓嬫墍紺猴細(xì)
<!-- Security is active on entire directory -->
<security-constraint>
<display-name>Tomcat Server Configuration Security Constraint</display-name>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<!-- Define the context-relative URL(s) to be protected -->
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<!-- Anyone with one of the listed roles may access this area -->
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
<!-- Login configuration uses form-based authentication -->
<login-config>
<auth-method>FORM</auth-method>
<realm-name>Tomcat Server Configuration Form-Based Authentication Area</realm-name>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
<!-- Security roles referenced by this web application -->
<security-role>
<description>
The role that is required to log in to the Administration Application
</description>
<role-name>admin</role-name>
</security-role>
4.鍦?<login-config>鏍囩鐨?lt;auth-method>FORM</auth-method>灞炴т腑錛屽彲浠ョ湅鍒拌繖閲岀殑authentication method 璁劇疆涓篎ORM錛岃繖鏄竴縐嶅熀浜庤〃鍗曠殑鐢ㄦ埛璁よ瘉鏂瑰紡銆傚熀浜巉orm鐨勭敤鎴瘋璇侀渶瑕佸湪<form-login-page>/login.jsp</form-login-page>瀹氫箟鐨勭櫥闄嗛〉闈腑鎻愪緵涓涓寘鎷敤鎴峰悕鍜屽瘑鐮佺殑html琛ㄥ崟錛岃繖涓〃鍗曠浉瀵瑰簲浜庣敤鎴峰悕鍜屽瘑鐮佺殑鍏冪礌蹇呴』鏄痡_username鍜宩_password,騫朵笖琛ㄥ崟鐨凙CTION蹇呴』涓簀_security_check銆傝濡傦細(xì)
<form method="POST" action="j_security_chack">
<input type="text" name="j_username">
<input type="password" name="j_password">
</form>
鍦ㄩ獙璇侀氳繃涔嬪悗錛宭ogin欏甸潰浼?xì)鑷姩铦{鍚戣搴旂敤鐨勯粯璁ら〉闈?index.html,index.jsp絳夌瓑)銆?
闄や簡FORM楠岃瘉鏂瑰紡涔嬪錛岃繕鏈塀ASIC鍜孋LIENT-CERT榪欎袱縐嶇敤鎴瘋璇佹柟寮忥紝鍓嶈呮槸鍩烘湰鐨勭敤鎴瘋璇佹柟寮忥紝瑕佹眰嫻忚鍣ㄥ脊鍑轟竴涓璇濇錛屽綍鍏ョ敤鎴峰悕鍜屽瘑鐮併傚悗鑰呮槸浣跨敤瀹㈡埛鏁板瓧璇佷功鏉ヨ璇佽姹傘?br />
5.浠ヤ笂鍥涙瀹屾垚涔嬪悗渚垮彲浠ラ氳繃鍦╰omcat-users.xml鏂囦歡涓坊鍔犵敤鎴峰拰瑙掕壊鏉ュ疄鐜拌闂帶鍒朵簡銆傝繕鏄瘮杈冩柟闈㈢殑銆?/p>