Liberty 設定檔安全入門

您可以利用 <quickStartSecurity> 元素來啟用 Liberty 設定檔的簡式(單一使用者)安全設定。

關於這項作業

您可以遵循一些基本配置步驟來設定安全 Liberty 設定檔伺服器和 Web 應用程式。 Liberty 設定檔內的配置動作是動態的,這表示無需重新啟動伺服器,配置更新就會生效。

程序

  1. 建立及啟動您的伺服器。
    • 適用於 Windows 平台在 Windows 系統上:
      server.bat create MyNewServer
      server.bat start MyNewServer
    • 適用於 AIX 平台適用於 LINUX 平台適用於 UNIX 平台適用於 HP UNIX 平台適用於 Solaris 平台適用於 IBM i 平台在 Windows 系統以外的所有系統上:
      server create MyNewServer
      server start MyNewServer
  2. appSecurity-2.0servlet-3.0 特性包括在 server.xml 檔中。

    server.xml 檔是在 myNewServer 伺服器目錄中,例如,wlp\usr\servers\myNewServer\server.xml

    <featureManager>
         <feature>appSecurity-2.0</feature>
         <feature>servlet-3.0</feature>
    </featureManager>
  3. 定義要針對伺服器管理活動來授與管理者角色的使用者名稱和密碼。
    <quickStartSecurity userName="Bob" userPassword="bobpwd" />
    註: 選擇對您有意義的使用者名稱和密碼。 您的應用程式絕不可使用範例中的名稱和密碼。
  4. 配置含有相關安全限制的部署描述子來保護 Web 資源。 比方說,利用 <auth-constraint><role-name> 元素來定義可以存取 Web 資源的角色。
    下列 web.xml 範例檔顯示 testing 角色對於應用程式中之所有 URI 的存取保護。
    <?xml version="1.0" encoding="UTF-8"?>
    <!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 id="myWebApp">
    
     <!-- SERVLET DEFINITIONS -->
     <servlet id="Default">
        <servlet-name>myWebApp</servlet-name>
        <servlet-class>com.web.app.MyWebAppServlet</servlet-class>
        <load-on-startup/>
     </servlet>
        
     <!-- SERVLET MAPPINGS -->
     <servlet-mapping id="ServletMapping_Default">
        <servlet-name>myWebApp</servlet-name>
        <url-pattern>/*</url-pattern>
     </servlet-mapping>
    
     <!-- SECURITY ROLES -->
     <security-role>
        <role-name>testing</role-name>
     </security-role>
    
     <!-- SECURITY CONSTRAINTS -->
     <security-constraint>
        <web-resource-collection>
          <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <auth-constraint>
          <role-name>testing</role-name>
        </auth-constraint>
     </security-constraint>
    
     <!-- AUTHENTICATION METHOD: Basic authentication -->
     <login-config>
        <auth-method>BASIC</auth-method>
     </login-config>
    
    </web-app>
  5. server.xml 檔中配置您的應用程式。
    在下列範例中,使用者 Bob 對映至應用程式的 testing 角色:
     <application type="war" id="myWebApp" name="myWebApp"
                  location="${server.config.dir}/apps/myWebApp.war">
         <application-bnd>
             <security-role name="testing">
                  <user name="Bob" />
             </security-role>
         </application-bnd>
     </application>
  6. 以使用者名稱 Bob 來存取應用程式及登入。 myWebApp 應用程式的預設 URL 如下:http://localhost:9080/myWebApp

結果

現在,您的應用程式已獲得安全維護。

指示主題類型的圖示 作業主題

資訊中心條款 | 意見


「時間戳記」圖示 前次更新: 2015 年 6 月 22 日
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=phil&product=was-libcore-mp&topic=twlp_sec_quickstart
檔名:twlp_sec_quickstart.html