OAM 和 SP 中的自訂認證模組
此文章會在 OAM/SP 中建立新的自訂「認證模組」,此模組是由現有的「OAM 同盟認證 Plugin」和自訂 Plugin 所組成,其中:
-
評估要求的受保護資源
-
決定要用於聯合 SSO 作業的 IdP
-
根據要求的資源,從 IdP 要求較高的聯合認證方法
如需如何設計自訂「認證 Plugin」的詳細資訊,請參閱 OAM Developer's Guide,其中說明如何開發這類模組。
聚焦於如何:
-
實作外掛程式
-
編譯
-
封裝它
-
將 Plugin 上傳至 OAM
-
建立新的認證模組
同盟認證模組
OOTB Federation Authentication Module (稱為 FederationPlugin
) 由兩個 Plugin 組成:
-
FedAuthnRequestPlugin
:啟動「聯合 SSO」流程,決定若前一個「認證 Plugin」未提供要使用的 IdP,會建立 SSO 要求並將使用者重新導向至 IdP -
AssertionProcessing
:處理內送 SAML/OpenID SSO 回應,並將訊息對應至 LDAP 目錄中的本機使用者記錄
協調流程可由下列項目查看:
-
前往「OAM 管理主控台」:
http(s)://oam-admin-host:oam-adminport/oamconsole
。 -
瀏覽至 Access Manager 、 Authentication Modules 。
-
開啟
FederationScheme
。 -
按一下「步驟 (Step)」頁籤來查看外掛程式。
-
按一下「步驟協調流程」頁籤即可查看不同 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」作業時,使用各種類型的資訊:
-
IdP:以
KEY_FEDIDP
字串所參照的「選擇性」來執行「聯合 SSO」-
Type
:字串 -
Value
:IdP 合作夥伴名稱
-
-
從 IdP (選擇性) 要求的聯合認證方法,由
KEY_FEDAUTHNMETHOD
參照-
string
類型:字串 -
Value
:應在 SSO 要求中設定的聯合認證方法
-
-
KEY_FEDAUTHNMETHODCOMP
字串所參照的「SAML 2.0 同盟認證方法比較」屬性 (選擇性)-
Type
:字串 -
Value
:要用於 SAML 的比較
-
-
2.0 Authn Request message exact for exact better for better min for minimum max for maximum The Force
Authn
Wag Optional Referenced by theKEY_FEDFORCEAUTHN
string-
Type
:字串 -
Value
:指示 OAM/SP 是否應要求 IdP 查問使用者的 "true" 或 "false" 字串,即使使用者已在 IdP 進行認證
-
-
KEY_FEDISPASSIVE
字串所參照的 Is Passive Wag Optional-
Type
:字串 -
Value
:表示是否允許 IdP 與使用者互動的 "true" 或 "false" 字串
-
自訂認證 Plugin
概觀
自訂認證 Plugin:
-
評估要求的資源
-
決定要使用的 IdP
-
如果 IdP 支援更強的「同盟認證方法」,則要求 IdP 的強式「同盟認證方法」。
在範例中,我們有:
-
三個 IdP 合作夥伴:
-
支援下列聯合認證方法的 AcmeIdP
-
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
(預設值,不需要特別要求) -
urn:oasis:names:tc:SAML:2.0:ac:classes:X509
-
WorldBank
-
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
(預設值,不需要特別要求)urn:oasis:names:tc:SAML:2.0:ac:classes:SmartcardPKI
-
WInsuranceIdP
-
urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport
(預設值,不需要特別要求) -
三個高層次資源:
-
http://company.com/businesspartners/acmebank
,連結到AcmeIdP
-
http://company.com/businesspartners/worldbank
,連結到 WorldBank -
http://company.com/businesspartners/worldinsurance
,連結到WInsuranceIdP
-
-
三種機密資源,適用於三種高階資源:
-
http://company.com/businesspartners/acmebank/account
-
http://company.com/businesspartners/worldban/account
-
http://company.com/businesspartners/worldinsurance/account
-
-
自訂認證 Plugin 是由下列項目所組成:
-
一個擴充
oracle.security.am.plugin.authn.AbstractAuthenticationPlugIn
類別的 Java 類別 -
描述 Java 類別的
MANIFEST.MF
檔案 -
描述外掛程式的 XML 檔案
-
這三個元素隨附在 JAR 檔案中,然後透過「OAM 管理主控台」上傳至 OAM 伺服器。上傳並啟用之後,請建立「同盟認證模組」。
Java 類別
實行我的自訂認證 Plugin 的類別必須遵循下列條件:
-
擴充
oracle.security.am.plugin.authn.AbstractAuthenticationPlugIn
類別 -
實行下列方法:
-
公用
ExecutionStatus
-
process (
AuthenticationContext
context) 發生AuthenticationException
-
必須傳回狀態 (失敗或成功)
-
在我們的範例中,此方法會評估要求的資源
-
設定
KEY_FEDIDP
CredentialParam
以指示要使用的 IdP -
設定
KEY_FEDAUTHNMETHOD
CredentialParam
以從 IdP 要求特定的「聯合認證方法」
-
-
公用字串
getPluginName()
- 傳回自訂外掛程式的名稱
-
在我們的範例中,它會傳回
CustomIdPSelectionPlugin
-
公用字串
getDescription()
-
傳回自訂認證 Plugin 的描述
-
在我們的範例中,它會傳回 "Custom IdP Selection Plugin"
-
-
公用
Map <String, MonitoringData> getMonitoringData()
-
未用於認證 Plugin 流程中
-
在我們的範例中,它會傳回空值
-
-
公用布林值
getMonitoringStatus()
-
未用於認證 Plugin 流程中
-
在我們的範例中,它會傳回 false
-
-
公開 int
getRevision()
-
必須與資訊清單檔案中指定的版本相同
-
在我們的範例中,它會傳回 10
-
-
公開作廢
setMonitoringStatus(boolean status)
-
未用於認證 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 檔案需要用於編譯:
-
felix.jar
-
oam-plugin.jar
在下列位置找到這些檔案:
-
felix.jar
:$IAM_HOME/oam/server/lib/plug/felix.jar
-
oam-plugin.jar
:$IAM_HOME/oam/serve /lib/plugin/oam-plugin.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:
-
移至「OAM 管理主控台」:
http(s)://oam-admin-host:oam-adminport/oamconsole
-
瀏覽至 Access Manager 、 Plugin
-
按一下匯入 Plug-In
-
選取 Plugin JAR 檔案 (此範例中的
CustomIdPSelectionPlugin.jar
)
Import_Plug-In_Screen.jpg 圖解描述
外掛程式會處於已上傳狀態:
您必須將 Plugin 分配給程式實際執行 OAM 伺服器並加以啟動:
-
選取 Plugin
-
按一下分配選取的項目
-
外掛程式的啟用狀態頁籤顯示外掛程式的狀態
Activation_Status_Screen.jpg 圖解說明
您需要啟用外掛程式:
-
選取 Plugin
-
按一下啟用選取的項目
-
外掛程式的「 啟動狀態」分頁顯示外掛程式的狀態
Activate_Plugin_Screen.jpg 圖解說明
建立認證模組
根據現有的 FederationPlugin
認證模組 (與現有的模組不同) 建立新的「同盟認證模組」:
-
CustomIdPSelectionPlugin
將會是初始步驟協調流程:成功時將會對應至FedAuthnRequestPlugin
-
失敗時對應至失敗
-
發生錯誤時對應至失敗
執行下列步驟以建立新的「認證模組」:
-
移至「OAM 管理主控台」:
http(s)://oam-admin-host:oam-adminport/oamconsole
-
瀏覽至 Access Manager 、認證模組
-
按一下建立認證模組
-
選取建立自訂認證模組
-
輸入名稱 (例如
CustomFedModule
)
Authentication_Module_Screen.jpg 圖解說明
執行下列步驟以新增步驟至新的「認證模組」:
-
按一下
Steps
頁籤 -
按一下「新增」來新增
FedAuthnRequestPlugin
步驟:-
步驟名稱:
FedAuthnRequestPlugin
-
外掛程式名稱:
FedAuthnRequestPlugin
-
-
按一下確定
Authentication_Steps_Screen.jpg 圖解說明
-
按一下「新增」來新增
AssertionProcessing
步驟:-
步驟名稱:
AssertionProcessing
-
外掛程式名稱:
FedUserAuthenticationPlugin
-
-
按一下確定
Assertion_Processing_Screen.jpg 圖解說明
-
按一下「新增」來新增
IdPSelection
步驟:-
步驟名稱:
IdPSelection
-
外掛程式名稱:
CustomIdPSelectionPlugin
-
-
按一下確定。
「步驟」頁籤顯示:
請執行下列步驟來定義新「認證模組」的步驟協調流程:
-
按一下「步驟協調」頁籤
-
選取
IdPSelection
作為初始步驟 -
FedAuthnRequestPlugin
:-
成功時選取成功
-
為失敗時選取
AssertionProcessing
-
選取「發生錯誤時失敗」
-
-
AssertionProcessing
:-
成功時選取成功
-
失敗時選取失敗
-
選取「發生錯誤時失敗」
-
-
IdPSelection
:-
成功時選取
FedAuthnRequestPlugin
-
失敗時選取失敗
-
選取「發生錯誤時失敗」
-
-
按一下套用。
Define_steps_orchestration_Screen.jpg 圖解說明
認證配置
使用使用新的「認證模組」的「認證原則」保護資源之前,必須先建立新的「認證配置」,參照新的自訂模組。這是必要的,因為「認證原則」連結至「認證配置」,而不是「認證模組」。
若要為該自訂模組建立新的「認證配置」,請執行下列步驟:
-
移至「OAM 管理主控台」:
http(s)://oam-admin-host:oam-adminport/oamconsole
-
瀏覽至 Access Manager 、認證配置
-
按一下建立認證配置
-
輸入名稱 (例如
CustomFedScheme
) 和描述 -
將「認證層次」設為可接受的值 (我的範例中有 2 個) 選取 FORM 作為「查問方法」
-
設定「查問重導 URL」(在此範例中,我們將其設為
/oam/server/
) -
選取新建立的自訂認證模組 (範例中的
CustomFedModule
) -
設定「查問 URL」(此範例中的
/pages/servererror.jsp
) -
設定「相關資訊環境類型」(例如
customWar
) 設定「相關資訊環境值」(/oam
,因為我們不使用任何頁面) -
請至少輸入下列「查問參數」:
initial_command=NONE is_rsa=true
-
按一下套用
Authentication_Scheme_Screen.jpg 圖解說明
測試
使用新建立的「認證配置」,使用「認證原則」保護資源。這會呼叫自訂「認證模組」。
其他學習資源
探索 docs.oracle.com/learn 上的其他實驗室,或存取 Oracle Learning YouTube 頻道上的更多免費學習內容。此外,瀏覽 education.oracle.com/learning-explorer 成為 Oracle Learning Explorer。
如需產品文件,請造訪 Oracle Help Center 。
Custom Authentication Module in OAM and SP
F60229-01
September 2022
Copyright © 2022, Oracle and/or its affiliates.