ConnectedAppPlugin クラス
名前空間
使用方法
接続アプリケーションを作成するときは、アプリケーションに関する一般な情報と、OAuth、Web アプリケーション、モバイルアプリケーション、およびキャンバスアプリケーションの設定を指定します。アプリケーションの呼び出し方法をカスタマイズするには、この ConnectedAppPlugin Apex クラスを使用して接続アプリケーションハンドラーを作成します。たとえば、このクラスを使用して、新しい認証プロトコルをサポートしたり、ビジネスプロセスにメリットがある形でユーザー属性に応答したりできます。
接続アプリケーションハンドラーを作成する場合、ConnectedAppPlugin クラスも設定して、実行ユーザーとして実行されるようにします。実行ユーザーは、接続アプリケーションのアクセスを承認します。たとえば、authorize メソッドを使用する場合、実行ユーザーは接続アプリケーションのデータへのアクセスを承認します。
実行ユーザーを指定しない場合、プラグインは自動化プロセスユーザー (バックグラウンドでタスクを実行するシステムユーザー) として実行されます。customAttributes メソッドを除く大部分の ConnectedAppPlugin メソッドでは、実行ユーザーを指定する必要があります。詳細は、「カスタム接続アプリケーションハンドラーの作成」を参照してください。
例
この例では、コンテキストが SAML でユーザーがカスタム項目で追跡される目標に達した場合、接続アプリケーションユーザーによる接続アプリケーションの使用を承認します。ユーザーの権限セットの割り当てが返されます。Auth.InvocationContext を使用して、サービスプロバイダーに送信される前に SAML アサーションを変更します。
1global class ConnectedAppPluginExample extends Auth.ConnectedAppPlugin
2{
3 // Authorize the app if the user has achieved quota tracked in a custom field
4 global override Boolean authorize(Id userId, Id connectedAppId, Boolean isAdminApproved, Auth.InvocationContext context)
5 {
6 // Create a custom boolean field HasAchievedQuota__c on the user record
7 // and then uncomment the block below
8 // User u = [select id, HasAchievedQuota__c from User where id =: userId].get(0);
9 // return u.HasAchievedQuota__c;
10
11 return isAdminApproved;
12 }
13
14 // Call a flow during refresh
15 global override void refresh(Id userId, Id connectedAppId, Auth.InvocationContext context)
16 {
17 try
18 {
19 Map<String, Object> inputVariables = new Map<String, Object>();
20 inputVariables.put('userId', userId);
21 inputVariables.put('connectedAppId', connectedAppId);
22
23 // Create a custom trigger ready flow and uncomment the block below
24 // Flow.Interview.MyCustomFlow interview = new Flow.Interview.MyCustomFlow(inputVariables);
25 // interview.start();
26 } catch ( Exception e ) {
27 System.debug('FLOW Exception:' + e);
28 }
29 }
30
31 // Return a user’s permission set assignments
32 global override Map<String,String> customAttributes(Id userId, Id connectedAppId, Map<String,String>
33 formulaDefinedAttributes, Auth.InvocationContext context)
34 {
35 List<PermissionSetAssignment> psas = [SELECT id, PermissionSet.Name FROM PermissionSetAssignment
36 WHERE PermissionSet.IsOwnedByProfile = false AND (AssigneeId = :userId)];
37 String permsets = '[';
38 for (PermissionSetAssignment psa :psas)
39 {
40 permsets += psa.PermissionSet.Name + ';';
41 }
42 permsets += ']';
43 formulaDefinedAttributes.put('PermissionSets', permsets);
44 return formulaDefinedAttributes;
45 }
46}ConnectedAppPlugin のメソッド
ConnectedAppPlugin のメソッドは次のとおりです。
authorize(userId, connectedAppId, isAdminApproved)
authorize(userId, connectedAppId, isAdminApproved, context)
署名
public Boolean authorize(Id userId, Id connectedAppId, Boolean isAdminApproved, Auth.InvocationContext context)
パラメーター
- userId
- 型: Id
- 接続アプリケーションの使用を試みているユーザーの 15 文字の ID。
- connectedAppId
- 型: Id
- 接続アプリケーションの 15 文字の ID。
- isAdminApproved
- 型: Boolean
- 接続アプリケーションで承認が必要な場合の指定されたユーザーの承認状態。
- context
- 型: InvocationContext
- 接続アプリケーションが呼び出されるコンテキスト。
使用方法
ConnectedAppPlugin が現在のユーザーの代わりに実行されます。ただし、プラグインが動作するには、このユーザーに接続アプリケーションの使用権限が必要です。このメソッドを使用してユーザーを認証します。
customAttributes(userId, connectedAppId, formulaDefinedAttributes)
customAttributes(userId, connectedAppId, formulaDefinedAttributes, context)
署名
public Map<String,String> customAttributes(Id userId, Id connectedAppId, Map<String,String> formulaDefinedAttributes, Auth.InvocationContext context)
パラメーター
- userId
- 型: Id
- 接続アプリケーションの使用を試みているユーザーの 15 文字の ID。
- connectedAppId
- 型: Id
- 接続アプリケーションの 15 文字の ID。
- formulaDefinedAttributes
- 型: Map<String, String>
- UserInfo エンドポイント (OAuth) から、または SAML アサーションからの現在の属性セットの対応付け。詳細は、オンラインヘルプの「UserInfo エンドポイント」を参照してください。
- 型: InvocationContext
- 接続アプリケーションが呼び出されるコンテキスト。
modifySAMLResponse(authSession, connectedAppId, samlResponse)
署名
public dom.XmlNode modifySAMLResponse(Map<String,String> authSession, Id connectedAppId, dom.XmlNode samlResponse)
パラメーター
- authSession
- 型: Map<String, String>
- 承認されたユーザーのセッションの属性。対応付けには、接続アプリケーションにアクセスしている、承認されたユーザーの 15 文字の ID が含まれます。
- connectedAppId
- 型: Id
- 接続アプリケーションの 15 文字の ID。
- samlResponse
- 型: Dom.XmlNode
- IDP によって生成された SAML XML 応答が含まれます。
使用方法
このメソッドを使用して XML SAML 応答を変更し、検証、署名、および対象サービスプロバイダーへの送信前に SAML 要求のコンテキストに基づいてアクションを実行できます。このメソッドにより、開発者は特定のニーズに合わせて接続アプリケーションプラグインを拡張できます。
開発者は、接続アプリケーションプラグイン内で行われる変更の全責任を負います。プラグインには、検証とエラー処理を含める必要があります。プラグイン��例外が発生したら、キャッチしてログに記録し、プロセスを停止します。対象サービスプロバイダーには何も送信しないでください。
refresh(userId, connectedAppId, context)
署名
public void refresh(Id userId, Id connectedAppId, Auth.InvocationContext context)
パラメーター
- userId
- 型: Id
- 更新トークンを要求しているユーザーの 15 文字の ID。
- connectedAppId
- 型: Id
- 接続アプリケーションの 15 文字の ID。
- context
- 型: InvocationContext
- 接続アプリケーションが呼び出されるコンテキスト。
戻り値
型: void