關於單一登入架構

Build Forge SSO 架構提供了整合市場上許多 SSO 解決方案的功能。SSO 架構是攔截程式型,意指其會截取 HTTP 要求並提供處理方法。您可以撰寫自訂攔截程式來接收及驗證 HTTP 要求中的安全構件。特別是,攔截程式可以在 HTTP 回應中設定記號,然後在後續的要求中尋找這些記號。

Build Forge 提供了兩個 SSO 解決方案:

SSO 架構方法

SSO 攔截程式是一種 Java 類別,其會實作 Build Forge SSO 架構所使用的介面:
com.buildforge.services.server.sso.ISSOIntercaptor
其位於服務層元件中:
<bfinstall>/Apache/tomcat/webapps/rbf-services/WEB-INF/classes

該介面提供了下列方法。

initInterceptor
於載入攔截程式時呼叫。配置內容的對映會傳給 initInterceptor() 方法。配置內容是在 Build Forge 主控台的管理 > 安全 > SSO 中建立。
isTargetInterceptor
檢閱入埠要求中的屬性,以判斷這個攔截程式是否需要處理這些屬性。若是如此,攔截程式會負責以 authenticateRequest() 方法鑑別要求。否則會略過這個攔截程式。攔截程式選項會假設多個攔截程式已配置為執行中。其會依序處理。
authenticateRequest
利用要求中的資料來鑑別要求。其會使用回應屬性將資料傳回用戶端。
logoutRequest
在處理要求之後,清除任何與使用者相關的安全資訊。

攔截程式配置與排序

攔截程式配置定義在管理 > 安全 > SSO 中。Build Forge 隨附了下列配置:

實作攔截程式類別並將它放在 Build Forge Apache Tomcat 應用程式伺服器之後,您就可以在這裡配置新的 SSO 配置。該類別是 SSO 配置的其中一個內容。

這份清單的順序會決定參考攔截程式以便處理要求的順序。您可以配置多個攔截程式來處理要求。在登入期間,每一個攔截程式都會依序參考。處理要求的攔截程式會是第一個作用中的攔截程式,其屬性適用於要求中的屬性。只有一個攔截程式會處理要求。其一律是第一個對 isTargetInterceptor 回應 true 的攔截程式。

註: 「表單 SSO 攔截程式」應該維持作用中,才能在錯誤時提供撤回。自訂攔截程式在清單中的位置應該在其之前。

新增自訂 SSO 攔截程式

如果要在 Build Forge 中建立自訂攔截程式,請執行下列動作:

  1. 建立自訂 Java 類別。

    該類別必須實作 ISSOInterceptor 介面。

  2. 將自訂類別部署至服務層元件 WAR。
    1. 建立含有經過編譯的自訂 SSO 攔截程式類別的 JAR 檔。
    2. 將 JAR 檔複製到下列位置中的 Build Forge 服務層元件:
      <bfinstall>/Apache/tomcat/webapps/rbf-services/WEB-INF/classes
    3. 在這個目錄中解壓縮 JAR 檔。SSOManager 會在這裡尋找要載入的類別。
    4. 重新啟動 Build Forge。
  3. 選用:定義環境。這個環境可以當成 Properties 物件傳給 initInterceptor() 方法。
    1. 在「管理主控台」中,移至環境
    2. 按一下新增環境
    3. 定義 SSO 攔截程式所需的所有內容以執行起始設定。
  4. 新增 SSO 攔截程式至 Build Forge:
    1. 在「管理主控台」中,移至管理 > 安全 > SSO
    2. 按一下新增 SSO 配置。請填寫其內容:
      • 名稱 - 輸入 SSO 配置的名稱。
      • 作用中 - 設為「是」。作用中的配置全都會在鑑別要求期間加以存取。其會依出現在這個畫面中的順序來存取。
      • Java 類別 - 輸入類別的完整套件名稱。一個給定的類別只能指派給一個 SSO 攔截程式。
      • 環境 - 如果您定義了環境供這個 SSO 攔截程式使用,請選取該環境。
    3. 按一下儲存
    您的 SSO 攔截程式現在會顯示在清單中。
  5. 排序 SSO 配置。按一下 SSO 攔截程式左側的圖示,然後選取移至頂端

    在要求期間,作用中的 SSO 配置會依其出現在這個畫面中的順序來存取。您的配置必須放在表單 SSO 配置前,因為依預設其會在作用中,且存取時一律會傳回 true。依預設 SPNEGO SSO 配置是在非作用中。

範例 authenticateRequest 實作

下例取自「WebSphere SSO 攔截程式」,其用來整合 WebSphere 安全與 Build Forge。

該攔截程式會使用反射來尋找 WebSphere 的 WSSubject 類別。該類別具有 getCallerPrincipal 方法,來傳回用於登入 AuthServlet 的主體。AuthServlet 需要受保護,WAS 才能加以鑑別。

還有其他可傳回更多資訊的方法可供使用。有類似的方法可用來搭配任何應用程式伺服器使用。

public Result authenticateRequest
      (Request requestAttributes, Response responseAttributes)
       throws SSOException {

  Result result = null;

try {
  Class<?> cl =
    Class.forName(“com.ibm.websphere.security.auth.WSSubject”);
      Method theMethod = cl.getMethod("getCallerPrincipal",
        (Class[])null);
    String principal = (String)theMethod.invoke((Object[])null,
          (Object[])null);

if (principal != null
      && principal.length() > 0
      && !principal.equals("UNAUTHENTICATED")) {
  result = new Result(Result.UseridOnlyOID, domain, principal);
	responseAttributes.setStatus(HttpServletResponse.SC_OK);} catch (Exception e) {
				throw new SSOException(e);
}

return result;
}

authenticateRequest 的實作期間,您必須先設定回應狀態再傳回:

有其他狀態值可供使用。請參閱 JavaDoc 中的 HttpServletResponse

從登入錯誤中回復

如果您的自訂攔截程式在測試時未正常運作,則會鑑別最可能的問題。您會看到含有下列資訊的錯誤頁面:

Build Forge Error

     Access is denied to the Buil Forge console

     "Error authenticating:
     com.buildforge.services.common.api.APIException - API:
     Authentication Error."

     Please click here to try the same type of login again
     or click here to force a form login (user ID/password).

您有兩個選擇來進行回復:

方法來源報表

下列註解和來源報表提供了 ISSOInterceptor 介面中關於方法的詳細資訊。

initInterceptor
	/**
	 * This method is called when the interceptor is loaded.  A map of the 
     configuration properties is passed into the init method.  You can create 
     the configuration properties from a BuildForge Environment and associate 
     it with the SSO configuration.
	 *
	 * @param initializationProps used to configure the implementation
	 * @return true if successful, false if an error should be reported.
	 * @throws SSOException if the initialization fails
	 **/
	public boolean initInterceptor (Properties initializationProps) throws SSOException; 
isTargetInterceptor

	/**
	 * This methods will review the attributes in the requestAttributes Map 
     to determine if there is something that this interceptor should 
     act on.  If the interceptor return is "true", then the interceptor will 
     be responsible for authenticating the request and the authenticateRequest 
     method is invoked.   If the interceptor return is "false", then this 
     interceptor is skipped and the next isTargetInterceptor in the list will 
     be called.  Ordering of the interceptors during the configuration will 
     return which interceptor has the first shot at authenticating a request.
	 *
	 * @param requestAttributes attributes found in the inbound request	 
   * @return true if this interceptor will authenticate the request, 
             false if it will not.
	 * @throws SSOException
	 *
	 **/
	public boolean isTargetInterceptor(Request requestAttributes) throws SSOException;
	authenticateRequest

  /**
	 * This method is called on an interceptor that returns true for the 
     isTargetInterceptor method.  The Request will contain data used 
     to perform the authentication.  The Response is for the interceptor 
     to send information back to the client.  The Result returned will contain 
     the following information if the status code is 200:
	 * 
	 * OID:  an object identifier of the SecurityContext that can process token 
     information stored in this map when going to an Agent.
	 * Domain:  a valid BF domain name or <default> if not known 
     (the username must be valid in the configured realm).
	 * Username:  a valid BF username.   This will be used to lookup BFUser attributes 
     that are used in checking authorization policy.
	 * @see com.buildforge.services.common.security.context.Result
	 * 
	 * @param requestAttributes attributes found in the inbound request
	 * @param responseAttributes sent back in the outbound response
	 * @return com.buildforge.services.common.security.context.Result - result 
          information that tells BF how to handle the authentication request.
	 * @throws com.buildforge.services.server.sso.SSOException
	 **/
	public Result authenticateRequest(
			Request requestAttributes, 
			Response responseAttributes)
		throws SSOException;
	logoutRequest

  /**
	 * This method is called to logout a request.  The first interceptor that 
     returns true for the isTargetInterceptor method will perform the logout.   
     The main point is to clean up any user-related security information that 
     should not be kept.  The interceptor can inspect the request and response 
     objects to determine what needs to be removed.
	 * 
	 * @param requestAttributes attributes found in the inbound request
	 * @param responseAttributes sent back in the outbound response
	 * @return boolean - true if request redirect to exit page, 
                       false if redirect to login page.
	 * @throws com.buildforge.services.server.sso.SSOException
	 **/
	public boolean logoutRequest(
			Request requestAttributes, 
			Response responseAttributes)
		throws SSOException;

意見