OAM 和 SP 中的自訂認證模組

此文章會在 OAM/SP 中建立新的自訂「認證模組」,此模組是由現有的「OAM 同盟認證 Plugin」和自訂 Plugin 所組成,其中:

如需如何設計自訂「認證 Plugin」的詳細資訊,請參閱 OAM Developer's Guide,其中說明如何開發這類模組。

聚焦於如何:

同盟認證模組

OOTB Federation Authentication Module (稱為 FederationPlugin) 由兩個 Plugin 組成:

協調流程可由下列項目查看:

  1. 前往「OAM 管理主控台」:http(s)://oam-admin-host:oam-adminport/oamconsole

  2. 瀏覽至 Access ManagerAuthentication Modules

  3. 開啟 FederationScheme

  4. 按一下「步驟 (Step)」頁籤來查看外掛程式。

  5. 按一下「步驟協調流程」頁籤即可查看不同 Plugin 與用來啟動作業之 Plugin 之間的協調流程。

Steps_Orchestration_Screen.jpg 圖解說明

FedAuthnRequestPlugin 外掛程式

FedAuthnRequestPlugin 可以使用來自先前自訂「認證 Plugin」的資訊,這會影響「聯合 SSO」作業的觸發方式。

「認證 Plugin」之間共用的 AuthenticationContext 執行處理包含 CredentialParam 物件,可讓各種 Plugin 在程式實際執行時進行通訊。

oracle.security.am.plugin.authn.AuthenticationContext:跨各種認證 Plugin 共用的認證作業相關資訊環境

oracle.security.am.plugin.authn.Credential:收集儲存在 AuthenticationContext 中的證明資料資料

oracle.security.am.plugin.authn.CredentialParam:名稱參照的單一證明資料參數,且類型 (大部分時間的字串) 具有值,視「儲存在證明資料」執行處理中的類型而定

使用該機制時,FedAuthnRequestPlugin 會在啟動「證明資料」執行處理中儲存的「聯合 SSO」作業時,使用各種類型的資訊:

自訂認證 Plugin

概觀

自訂認證 Plugin:

在範例中,我們有:

這三個元素隨附在 JAR 檔案中,然後透過「OAM 管理主控台」上傳至 OAM 伺服器。上傳並啟用之後,請建立「同盟認證模組」。

Java 類別

實行我的自訂認證 Plugin 的類別必須遵循下列條件:

下列程式碼是自訂外掛程式的範例。

 package userauthn;
 import java.util.Map;
 import oracle.security.am.plugin.ExecutionStatus; import oracle.security.am.plugin.MonitoringData;
 import oracle.security.am.plugin.authn.AbstractAuthenticationPlugIn; import oracle.security.am.plugin.authn.AuthenticationContext; import oracle.security.am.plugin.authn.AuthenticationException; import oracle.security.am.plugin.authn.CredentialParam;
 public class CustomIdPSelectionPlugin extends
 AbstractAuthenticationPlugIn
 {
  public ExecutionStatus process(AuthenticationContext context)
  throws AuthenticationException {
  // requested URL
  String resourceURL = context.getResourceURL();
  // determines the IdP based on the request resource
  String idpPartnerName = null;
  if (resourceURL.startsWith("http://company.com/businesspartners/acmebank"))
  idpPartnerName = "AcmeIdP";
  else if (resourceURL.startsWith("http://company.com/businesspartners/worldbank"))
  idpPartnerName = "WorldBank";
  else if (resourceURL.startsWith("http://company.com/businesspartners/worldinsurance"))
  idpPartnerName = "WInsuranceIdP";
  // if IdP was determined, create a Credential param
  // instance in the AuthenticationContext
  // the OAM/SP FedAuthnRequestPlugin will consume it
 to start Federation SSO if (idpPartnerName != null) {
  CredentialParam idpParam = new
 CredentialParam();
  idpParam.setName("KEY_FEDIDP");
  idpParam.setType("string");
  idpParam.setValue(idpPartnerName);

 context.getCredential().addCredentialParam("KEY_FEDIDP", idpParam);
  }
  // here, the plugin evaluates if the account subpath is being requested
  // if it is, it requests from IdP higher Fed Auth
 Method
  String fedAuthnMethod = null;
  if ("AcmeIdP".equals(idpPartnerName) &&
  resourceURL.startsWith("http://company.com/businesspartners/acmebank/account")) { // AcmeIdP supports X.509 as the higher
 authentication method
  fedAuthnMethod =
 "urn:oasis:names:tc:SAML:2.0:ac:classes:X509";
  } else if ("WorldBank".equals(idpPartnerName) &&
  resourceURL.startsWith("http://company.com/businesspartners/worldbank/account")) // WorldBank supports smart card as the higher
 authentication method
  fedAuthnMethod =
 "urn:oasis:names:tc:SAML:2.0:ac:classes:SmartcardPKI";
  } else if ("WInsuranceIdP".equals(idpPartnerName)
 &&
  resourceURL.startsWith("http://company.com/businesspartners/worldinsurance/account"))
  {
  // WInsuranceIdP does not support another fed
 authn method
  }
  // if another fed authn method was requested, create a Credential param
  // instance in the AuthenticationContext
  // the OAM/SP FedAuthnRequestPlugin consumes it to start Federation SSO if (fedAuthnMethod != null) {
  CredentialParam fedAuthnParam = new
 CredentialParam();

 fedAuthnParam.setName("KEY_FEDAUTHNMETHOD")
  fedAuthnParam.setType("string");
  fedAuthnParam.setValue(fedAuthnMethod);

 context.getCredential().addCredentialParam("KEY_FEDAUTHNMETHOD fedAuthnParam);
  }
  // return success, which is mapped to
 FedAuthnRequestPlugin in the
  // Authentication Module steps orchestration
  return ExecutionStatus.SUCCESS;
  }
  public String getPluginName() {
  return "CustomIdPSelectionPlugin";
  }
  public String getDescription() {
  return "Custom IdP Selection Plugin";
  }
  public Map<String, MonitoringData> getMonitoringData() {
  return null;
  }
  public boolean getMonitoringStatus() {
  return false;
  }
  public int getRevision() {
  return 10;
  }
 public void setMonitoringStatus(boolean arg0) {
  } }

外掛程式註冊檔案

必須在 Plugin XML 檔案中定義自訂認證 Plugin,例如:

<Plugin type="Authentication">
<author>uid=admin</author>
<email>admin@example</email>
<creationDate>08:00:00,2014-01-15</creationDate>
<description>Custom IdP Selection
Plugin</description>
<confguration>
</confguration>

重要注意事項:XML 檔案的名稱必須與實行 Plugin 的類別相同,在此情況下為 CustomIdPSelectionPlugin.xml

請參閱 OAM 開發人員手冊瞭解詳細資訊

資訊清單檔案

將自訂認證 Plugin 封裝在 JAR fle 之前,必須先定義 MANIFEST.MF,例如:

Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CustomIdPSelectionPlugin
Bundle-SymbolicName: CustomIdPSelectionPlugin
Bundle-Version: 10
Bundle-Activator: userauthn.CustomIdPSelectionPlugin Import-Package:
org.osgi.framework;version="1.3.0",oracle.security.am. plugin,oracle.security.am.plugin.authn Bundle-RequiredExecutionEnvironment: JavaSE-1.6

請參閱 OAM 開發人員手冊瞭解詳細資訊

注意:資訊清單檔案必須包含 ImportPackage 特性,此特性會列出外掛程式中使用的所有套裝軟體。

建立外掛程式

編譯中

OAM 部署的下列 JAR 檔案需要用於編譯:

在下列位置找到這些檔案:

在此範例中,會將 CustomIdPSelectionPlugin.java 檔案放在 src/userautn 資料夾中:

bash-4.1$ ls -l src/userauthn/total 4
-rw-r--r-- 1 root root 3894 Mar 1 11:42 CustomIdPSelectionPlugin.java

若要編譯,請執行下列命令:

$JDK_HOME/bin/javac -cp $IAM_HOME/oam/serve/lib/plugin/felix.jar:$IAM_HOME/oam/server/lib/plu /oam-plugin.jar src/userauthn/*.java

封裝自訂 Plugin

我們根據上一節列出的內容,在目前的目錄中建立 MANIFEST.MF,在 src 目錄中建立 CustomIdPSelectionPlugin.xml,其中包含上一節列出的外掛程式定義。

find
.
./MANIFEST.MF
./src
./src/userauthn
./src/userauthn/CustomIdPSelectionPlugin.class
./src/userauthn/CustomIdPSelectionPlugin.java ./src/CustomIdPSelectionPlugin.xm

若要建立包含 Plugin 和必要檔案的 CustomIdPSelectionPlugin.jar JAR 檔案,請執行下列命令:

jar cfvm CustomIdPSelectionPlugin.jar MANIFEST.MF -C src/ .
added manifest
adding: userauthn/(in = 0) (out= 0)(stored 0%) adding: userauthn/CustomIdPSelectionPlugin.class(in =2717) (out= 1267)(deflated 53%)
adding: userauthn/CustomIdPSelectionPlugin.java(in =3894) (out= 1055)(deflated 72%)
adding: CustomIdPSelectionPlugin.xml(in = 234) (out= 155)(deflated 33%)

這會建立 CustomIdPSelectionPlugin.jar。檢視檔案的內容:

unzip -l CustomIdPSelectionPlugin.jar Archive: CustomIdPSelectionPlugin.jar
長度 日期 時間 名稱
0 03-01-2014 10:14 後設通知 /
425 03-01-2014 10:14 中繼資訊 /MANIFEST.MF
0 03-01-2014 10:13 使用者認證 /
2717 03-01-2014 10:13 userauthn/CustomIdPSelectionPlugin.class
3894 03-01-2014 09:56 userauthn/CustomIdPSelectionPlugin.java
234 03-01-2014 10:03 CustomIdPSelectionPlugin.xml
7270     6 呎

重要注意事項: JAR 檔案的名稱必須與實行 Plugin 的類別相同,在此例中為 CustomIdPSelectionPlugin.jar

部署自訂驗證 Plugin

請執行下列步驟,在 OAM 中部署自訂認證 Plugin:

  1. 移至「OAM 管理主控台」:http(s)://oam-admin-host:oam-adminport/oamconsole

  2. 瀏覽至 Access ManagerPlugin

  3. 按一下匯入 Plug-In

  4. 選取 Plugin JAR 檔案 (此範例中的 CustomIdPSelectionPlugin.jar)

Import_Plug-In_Screen.jpg 圖解描述

外掛程式會處於已上傳狀態:

Plug-In_State_Screen.jpg 圖解描述

您必須將 Plugin 分配給程式實際執行 OAM 伺服器並加以啟動:

Activation_Status_Screen.jpg 圖解說明

您需要啟用外掛程式:

Activate_Plugin_Screen.jpg 圖解說明

建立認證模組

根據現有的 FederationPlugin 認證模組 (與現有的模組不同) 建立新的「同盟認證模組」:

執行下列步驟以建立新的「認證模組」:

  1. 移至「OAM 管理主控台」:http(s)://oam-admin-host:oam-adminport/oamconsole

  2. 瀏覽至 Access Manager認證模組

  3. 按一下建立認證模組

  4. 選取建立自訂認證模組

  5. 輸入名稱 (例如 CustomFedModule)

Authentication_Module_Screen.jpg 圖解說明

執行下列步驟以新增步驟至新的「認證模組」:

  1. 按一下 Steps 頁籤

  2. 按一下「新增」來新增 FedAuthnRequestPlugin 步驟:

    1. 步驟名稱:FedAuthnRequestPlugin

    2. 外掛程式名稱:FedAuthnRequestPlugin

  3. 按一下確定

Authentication_Steps_Screen.jpg 圖解說明

  1. 按一下「新增」來新增 AssertionProcessing 步驟:

    1. 步驟名稱:AssertionProcessing

    2. 外掛程式名稱:FedUserAuthenticationPlugin

  2. 按一下確定

Assertion_Processing_Screen.jpg 圖解說明

  1. 按一下「新增」來新增 IdPSelection 步驟:

    1. 步驟名稱:IdPSelection

    2. 外掛程式名稱:CustomIdPSelectionPlugin

  2. 按一下確定

IdP_Selection_Screen.jpg 圖解說明

「步驟」頁籤顯示:

Steps_Screen.jpg 圖解說明

請執行下列步驟來定義新「認證模組」的步驟協調流程:

  1. 按一下「步驟協調」頁籤

  2. 選取 IdPSelection 作為初始步驟

  3. FedAuthnRequestPlugin:

    1. 成功時選取成功

    2. 為失敗時選取 AssertionProcessing

    3. 選取「發生錯誤時失敗」

  4. AssertionProcessing:

    1. 成功時選取成功

    2. 失敗時選取失敗

    3. 選取「發生錯誤時失敗」

  5. IdPSelection:

    1. 成功時選取 FedAuthnRequestPlugin

    2. 失敗時選取失敗

    3. 選取「發生錯誤時失敗」

  6. 按一下套用

Define_steps_orchestration_Screen.jpg 圖解說明

認證配置

使用使用新的「認證模組」的「認證原則」保護資源之前,必須先建立新的「認證配置」,參照新的自訂模組。這是必要的,因為「認證原則」連結至「認證配置」,而不是「認證模組」。

若要為該自訂模組建立新的「認證配置」,請執行下列步驟:

  1. 移至「OAM 管理主控台」:http(s)://oam-admin-host:oam-adminport/oamconsole

  2. 瀏覽至 Access Manager認證配置

  3. 按一下建立認證配置

  4. 輸入名稱 (例如 CustomFedScheme) 和描述

  5. 將「認證層次」設為可接受的值 (我的範例中有 2 個) 選取 FORM 作為「查問方法」

  6. 設定「查問重導 URL」(在此範例中,我們將其設為 /oam/server/)

  7. 選取新建立的自訂認證模組 (範例中的 CustomFedModule)

  8. 設定「查問 URL」(此範例中的 /pages/servererror.jsp)

  9. 設定「相關資訊環境類型」(例如 customWar) 設定「相關資訊環境值」(/oam,因為我們不使用任何頁面)

  10. 請至少輸入下列「查問參數」:initial_command=NONE is_rsa=true

  11. 按一下套用

Authentication_Scheme_Screen.jpg 圖解說明

測試

使用新建立的「認證配置」,使用「認證原則」保護資源。這會呼叫自訂「認證模組」。

其他學習資源

探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,瀏覽 education.oracle.com/learning-explorer 成為 Oracle Learning Explorer。

如需產品文件,請造訪 Oracle Help Center