Tomcat安全網域設定大全

來源:互聯網
上載者:User

 安全域是tomcat內建的功能,在org.apache.catalina.Realm介面中聲明了把一組使用者名稱,口令及所關聯的角色整合到Tomcat的方法中,Tomcat5提供了4個實現這一介面的類,它們代表了4種安全域類型。
  下面我一一介紹其相關配置,及其應用方法。
  運行環境:windows2000,tomcat5.0.28,jdk1.5,jdbc3.0,sqlserver2000,
  測試目錄:%tomcat%/webapps/Area目錄。
  1. 記憶體域:類名,MemoryRealm;在初始化階段,從xml檔案中讀取安全驗證資訊,並把它們以一組對象的形式放在記憶體中。
  對於資源訪問它有三種方式:BASIC、DIGEST、FORM。使用Basic Authentication通過被認為是不安全的,因為它沒有強健的加密方法,除非在用戶端和伺服器端都使用HTTPS或者其他密碼加密碼方式(比如,在一個虛擬私人網路中)。
  設定檔%tomcat%/conf/Catalina/localhost/Area.xml為:
  <?xml version='1.0' encoding='utf-8'?>
  <Context docBase="D:/jakarta-tomcat-5.0.28/webapps/Area" path="/Area" reloadable="true"
  workDir="work/Catalina/localhost/Area">
   <Realm className="org.apache.catalina.realm.MemoryRealm"/>
  </Context>
  web應用所在的WEB-INF/web.xml為:
  <?xml version="1.0" encoding="GB2312"?>
  <!DOCTYPE web-app
   PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
  <web-app>
   <security-constraint>
   <display-name>sessiontest secruity constraint</display-name>
   <web-resource-collection>
   <web-resource-name>Protected Area</web-resource-name>
   <url-pattern>/test/*</url-pattern>
   </web-resource-collection>
   <auth-constraint>
   <role-name>cool</role-name>
   </auth-constraint>
   </security-constraint>
   <!--以下是基於BASIC驗證-->
  <login-config>
   <auth-method>BASIC</auth-method>
   <realm-name>Sessiontest Realm</realm-name>
   </login-config>
   <!--以下是基於DIGEST驗證-->
  <!-- <login-config>
   <auth-method>DIGEST</auth-method>
   <realm-name>Sessiontest Realm</realm-name>
   </login-config>
  -->
   <!--以下是基於FORM驗證-->
  <!--<login-config>
  <auth-method>FORM</auth-method>
  <realm-name>Sessiontest Realm</realm-name>
  <form-login-config>
  <form-login-page>/usercheck.jsp</form-login-page>
  <form-error-page>/error.jsp</form-error-page>
  </form-login-config>
  </login-config>
  若採用form驗證,usercheck.jsp,主要參數(不要去更改它)設定如下:
  <form method="post" action="j_security_check">
  <input type="text" name="j_username"><br>
  <br>
  <input type="password" name="j_password"><br>
  <br>
  <input type="submit" value="login">
  <input type="reset" value="reset">
  </form>
  -->
  <security-role>
   <description> session jdbctest </description>
   <role-name>cool</role-name>
   </security-role>
  </web-app>
  基中<url-pattern>/test/*</url-pattern>表示受保護的資源為:http://localhost:8080/Area/test/下的所有資源。role角色cool在%tomcat%conf中的tomcat-users.xml中添加:
   <role rolename="cool"/>
   <user username="zxj1" password="zxj2" roles="cool"/>
  2. JDBC域:類名,JDBCRealm,通過jdbc驅動程式訪問存在資料庫中的安全驗證。
  3. 資料來源域:類名,DataSourceRealm,通過JNDI資料來源訪問存在資料庫中的安全驗證資訊。
  4. JNDI域:類名,JNDIRealm,通過JNDIproveider訪問存放在基於LDAP的目錄伺服器中的安全驗證資訊。
  時間有限,待下回編輯進行修改。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.