この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

SamlJitHandler インターフェース

このインターフェースを使用して、SAML シングルサインオン時にジャストインタイムのユーザープロビジョニングロジックの制御とカスタマイズを行います。

名前空間

Auth

使用方法

SAML シングルサインオン時にユーザープロビジョニングのカスタムロジックを使用するには、Auth.SamlJitHandler を実装するクラスを作成する必要があります。これにより、ユーザーがシングルサインオンで Salesforce にログインするときに、組織固有のロジック (カスタム項目の自動入力など) を組み込むことができます。クラスは、関連付けられた取引先レコードと取引先責任者レコードを含め、ユーザーデータを作成および更新するロジックを必要に応じて実行する必要があります。

Salesforce で、[SAML シングルサインオン設定] の [SAML JIT ハンドラー] 項目にこのインターフェースを実装するクラスを指定します。クラスを実行するよう指定するユーザーに「ユーザーの管理」権限があることを確認します。

SamlJitHandler のメソッド

SamlJitHandler のメソッドは次のとおりです。

createUser(samlSsoProviderId, communityId, portalId, federationId, attributes, assertion)

指定された統合 ID を使用して User オブジェクトを返します。User オブジェクトはユーザー情報に対応します。このオブジェクトは、データベースに挿入されていない新規ユーザーまたはデータベース内の既存のユーザーレコードになります。

署名

public User createUser(Id samlSsoProviderId, Id communityId, Id portalId, String federationId, Map<String,String> attributes, String assertion)

パラメーター

samlSsoProviderId
型: Id
SamlSsoConfig 標準オブジェクトの ID。
communityId
型: Id
Experience Cloud サイトの ID。Experience Cloud ユーザーを作成しない場合、このパラメーターは null にできます。
portalId
型: Id
ポータルの ID。ポータルユーザーを作成しない場合、このパラメーターは null にできます。
federationId
型: String
このユーザーに使用されると Salesforce が想定する ID。
attributes
型: Map<String, String>
SAML アサーションのうち、デフォルトのアサーションに追加されたすべての属性 (カスタム属性など)。属性では、大文字と小文字が区別されます。
アサーションが暗号化されると、Sfdc.SamlAssertion という鍵を持つ値として保存される復号化されたアサーションが属性の対応付けに含まれます。
assertion
型: String
Base-64 エンコードされたデフォルトの SAML アサーション。
アサーションが暗号化されると、このパラメーターも暗号化されます。復号化されたアサーションにアクセスするには、属性の対応付けの Sfdc.SamlAssertion という鍵を確認します。

戻り値

型: User

User sObject。

使用方法

この組織に Experience Cloud サイトまたはポータルが設定されていない場合、communityId および portalId パラメーター値は null または関連付けられた鍵になる可能性があります。

updateUser(userId, samlSsoProviderId, communityId, portalId, federationId, attributes, assertion)

指定のユーザーの情報を更新します。ユーザーが以前 SAML シングルサインオンを使用してログインしたことがあり、再度ログインする場合、またはアプリケーションが [既存ユーザーをリンクする URL] を使用している場合、このメソッドがコールされます。

署名

public void updateUser(Id userId, Id samlSsoProviderId, Id communityId, Id portalId, String federationId, Map<String,String> attributes, String assertion)

パラメーター

userId
型: Id
Salesforce ユーザーの ID。
samlSsoProviderId
型: Id
SamlSsoConfig オブジェクトの ID。
communityId
型: Id
Experience Cloud サイトの ID。Experience Cloud ユーザーを更新しない場合、この型は null にできます。
portalId
型: Id
ポータルの ID。ポータルユーザーを更新しない場合、この型は null にできます。
federationId
型: String
このユーザーに使用されると Salesforce が想定する ID。
attributes
型: Map<String,String>
SAML アサーションのうち、デフォルトのアサーションに追加されたすべての属性 (カスタム属性など)。属性では、大文字と小文字が区別されます。
アサーションが暗号化されると、Sfdc.SamlAssertion という鍵を持つ値として保存される復号化されたアサーションも属性の対応付けに含まれます。
assertion
型: String
Base-64 エンコードされたデフォルトの SAML アサーション。
アサーションが暗号化されると、このパラメーターも暗号化されます。復号化されたアサーションにアクセスするには、属性の対応付けの Sfdc.SamlAssertion という鍵を確認します。

戻り値

型: void

SamlJitHandler の実装例

これは、Auth.SamlJitHandler インターフェースの実装例です。このコードでは、非公開メソッドを使用して取引先と取引先責任者を処理します (handleContact() と handleAccount() は、この例には含まれていません)。

1global class StandardUserHandler implements Auth.SamlJitHandler {
2    private class JitException extends Exception{}
3    private void handleUser(boolean create, User u, Map<String, String> attributes,
4        String federationIdentifier, boolean isStandard) {
5        if(create && attributes.containsKey('User.Username')) {
6            u.Username = attributes.get('User.Username');
7        }
8        if(create) {
9            if(attributes.containsKey('User.FederationIdentifier')) {
10                u.FederationIdentifier = attributes.get('User.FederationIdentifier');
11            } else {
12                u.FederationIdentifier = federationIdentifier;
13            }
14        }
15        if(attributes.containsKey('User.ProfileId')) {
16            String profileId = attributes.get('User.ProfileId');
17            Profile p = [SELECT Id FROM Profile WHERE Id=:profileId];
18            u.ProfileId = p.Id;
19        }
20        if(attributes.containsKey('User.UserRoleId')) {
21            String userRole = attributes.get('User.UserRoleId');
22            UserRole r = [SELECT Id FROM UserRole WHERE Id=:userRole];
23            u.UserRoleId = r.Id;
24        }
25        if(attributes.containsKey('User.Phone')) {
26            u.Phone = attributes.get('User.Phone');
27        }
28        if(attributes.containsKey('User.Email')) {
29            u.Email = attributes.get('User.Email');
30        }
31
32	//More attributes here - removed for length
33
34        //Handle custom fields here
35
36        if(!create) {
37            update(u);
38        }
39    }
40
41    private void handleJit(boolean create, User u, Id samlSsoProviderId, Id communityId, Id portalId,
42        String federationIdentifier, Map<String, String> attributes, String assertion) {
43        if(communityId != null || portalId != null) {
44            String account = handleAccount(create, u, attributes);
45            handleContact(create, account, u, attributes);
46            handleUser(create, u, attributes, federationIdentifier, false);
47        } else {
48            handleUser(create, u, attributes, federationIdentifier, true);
49        }
50    }
51
52    global User createUser(Id samlSsoProviderId, Id communityId, Id portalId,
53        String federationIdentifier, Map<String, String> attributes, String assertion) {
54        User u = new User();
55        handleJit(true, u, samlSsoProviderId, communityId, portalId,
56            federationIdentifier, attributes, assertion);
57        return u;
58    }
59
60    global void updateUser(Id userId, Id samlSsoProviderId, Id communityId, Id portalId,
61        String federationIdentifier, Map<String, String> attributes, String assertion) {
62        User u = [SELECT Id FROM User WHERE Id=:userId];
63        handleJit(false, u, samlSsoProviderId, communityId, portalId,
64            federationIdentifier, attributes, assertion);
65    }
66}