![]()
概要
指定したエンティティのプロファイルを Apigee Edge データストアから取得します。このポリシーは、名前が AccessEntity.{policy_name} という形式の変数にプロファイルを格納します。AccessEntity を使用すると、以下のエンティティのプロファイルにアクセスできます。
- アプリ
- API プロダクト
- 会社
- 会社のデベロッパー
- コンシューマ キー
- デベロッパー
AccessEntity ポリシーは、ポリシーベースのランタイム データベース検索として機能します。このポリシーで返されたプロファイル情報を使用すると、条件付きのエンドポイント ルーティング、フロー実行、ポリシー適用など、動的な動作を有効にできます。
AccessEntity ポリシーを使用して、エンティティのプロファイル データを XML 形式で取得し、変数に格納します。取得するエンティティを指定するには、エンティティのタイプと ID を使用して、必要なタイプのエンティティを指定します。後で、別のポリシーを使用して、ExtractVariables ポリシーや AssignMessage ポリシーなどの別のポリシーのエンティティ プロファイル データを取得できます。
サンプル
以下のサンプルでは、ExtractVariables と AssignMessage ポリシーと一緒に AccessEntity を使用して、デベロッパーのメールアドレスを抽出し、HTTP ヘッダーに追加しています。
デベロッパーのメールアドレスを取得して他のポリシーで使用する
AccessEntity ポリシーを設定して、Edge から取得したエンティティ プロファイルとプロファイル データの格納場所を指定します。
次の例では、クエリ パラメータとして渡された API キーを使用して、ポリシーで developer エンティティ プロファイルを取得し、デベロッパーを特定しています。このプロファイルは、名前が AccessEntity.{policy_name} という形式の変数に格納されます。このポリシーで設定する変数は AccessEntity.GetDeveloperProfile です。
<AccessEntity name="GetDeveloperProfile"> <!-- This is the type entity whose profile we need to pull from the Edge datastore. --> <EntityType value="developer"/> <!-- We tell the policy to use the API key (presented as query parameter) to identify the developer. --> <EntityIdentifier ref="request.queryparam.apikey" type="consumerkey"/> </AccessEntity>
別のポリシーを使用して、AccessEntity で設定された変数からエンティティ プロファイルの値を取得します。
以下の例では、ExtractVariables ポリシーを使用して、AccessEntity.GetDeveloperProfile 変数から値を取得しています。この変数は AccessEntity で設定されています。
取得された値は XMLPayload 要素で XPath 式として指定されています。抽出された値は developer.email 変数に格納されます。
<ExtractVariables name="SetDeveloperPro>fil<e" !-- The source element points to the variable populated by AccessEntity policy. The <format is p>o<licy-type.p>olicy-name. In this case, the variable contains the whole developer p>rof<ile. ->- SourceAccessEntity.GetDevelo<perProf>ile</Source Vari>ablePrefi<xdeveloper/Vari>abl<ePrefix >XMLPa<yload Variable name="email>" ty<pe="string" !-- You parse elements from the dev>eloper <profi>le using XPath. <-- > XP<ath/Devel>ope<r/Email/XPa>t<h /Variable > /XMLPayload /ExtractVariables
次の AssignMessage ポリシーでは、ExtractVariables ポリシーによって設定されたデベロッパーのメールアドレスを取得します。
<!-- We'll use this policy to return the variables set in the developer profile, just so that we can easily see them in the response>.< -- AssignMessage name="EchoV>ari<ables" AssignTo createNew="fal><se" >typ<e="response"/As>sign<To IgnoreUnresolvedVaria>ble<str>ue/Ig<noreUnr>esolved<Variables Set Headers > Header name=&q<uot;X-D>evelo<per-emai>l&q<uot;>{<developer.emai>l}/Header /Headers /Set /AssignMessage
要素リファレンス
AccessEntity ポリシーの基本的な構造は次のとおりです。
<AccessEntity name="policy_>nam<e" EntityType value=&quo>t;e<ntity_type"/ EntityIdentifier ref="entity_identifie>r&q<uot; type="identifer_type"/ SecondaryIdentifier ref=">;<secondary_ide>ntifier" type="identifer_type"/ /AccessEntity
Identifiers 要素でエンティティをグループ化すると、同じタイプの複数のエンティティにアクセスできます。
<AccessEntity name="name_of_the_po>lic<y" EntityType value="t>ype<_of_entity&>quot;</ Identi>fiers < Identifier EntityIdentifier ref="reference_to_entity_identifier>" <type*="identifer_type"/ SecondaryIdentifier ref="reference_to_second><ary_entity_iden>tifie<r" type>=&quo<t;identife>r_type&<quot;/!-- optional -- /Identifier Identifier EntityIdentifier >ref=&qu<ot;reference_to_entity_identifier" type*="identifer_type"/ Secondary><Identifier ref=>"<;reference_t>o_s<econdary_ent>i<ty_identifier>" type="identifer_type"/!-- optional -- /Identifier /Identifiers /AccessEntity
<AccessEntity> 属性
<AccessEntity async="false" continueOnError="false" enabled=">;true" name="policy_name"
次の表に、すべてのポリシーの親要素に共通する属性を示します。
| 属性 | 説明 | デフォルト | 要否 |
|---|---|---|---|
name |
ポリシーの内部名。 管理 UI プロキシ エディタで |
なし | 必須 |
continueOnError |
ポリシーが失敗した場合にエラーを返すには、 ポリシーが失敗した後もフローの実行を続行する場合は、 |
false | 省略可 |
enabled |
ポリシーを適用するには、 ポリシーを無効にするには、 |
true | 省略可 |
async |
この属性は非推奨となりました。 |
false | 非推奨 |
<DisplayName> 要素
管理 UI プロキシ エディタで name 属性と一緒に使用して、ポリシーのラベルに使用する自然言語名を指定します。
<DisplayName>Policy Display Name</DisplayName>
| デフォルト |
なし この要素を省略した場合、ポリシーの |
|---|---|
| 要否 | 省略可 |
| タイプ | 文字列 |
<EntityIdentifier> 要素
取得するエンティティ(EntityType で指定されたタイプ)を指定します。
<EntityIdentifier ref="value_variable" type="id>entifier_type"/
|
デフォルト |
なし |
|
要否 |
必須 |
|
型 |
文字列 |
属性
| 属性 | 説明 | デフォルト | 要否 | 型 |
|---|---|---|---|---|
| ref |
ID の参照元を格納する変数(例: |
なし | 必須。 | 文字列 |
| type | ref 属性の変数で更新されるタイプ(例: consumerkey)。値の一覧については、エンティティ タイプと ID をご覧ください。 |
必須。 | 文字列 |
例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=>"<;false">; enabled="t<rue" na>me=&q<uot;GetCompany" D><isplayNameG>etCom<panyProfile/DisplayName EntityType value="company"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
<EntityType> 要素
データストアから取得するエンティティのタイプを指定します。
<EntityType value="entity_t>ype"/
|
デフォルト |
なし |
|
要否 |
必須 |
|
型 |
文字列 |
EntityIdentifier 要素を使用して、必要なタイプのエンティティを指定します。エンティティ タイプのリファレンスについては、エンティティ タイプと ID をご覧ください。
属性
| 属性 | 説明 | デフォルト | 要否 | 型 |
|---|---|---|---|---|
| value | サポートされるエンティティ タイプのいずれか。一覧については、エンティティ タイプと ID をご覧ください。 | なし | 必須。 | 文字列 |
<SecondaryIdentifier> 要素
EntityIdentifier と一緒に使用して、EntityType の必要なインスタンスを表す値を指定します。
<SecondaryIdentifier ref="value_variable" type="id>entifier_type"/
|
デフォルト |
なし |
|
要否 |
省略可 |
|
型 |
文字列 |
EntityIdentifier のみを指定しても単一エンティティの取得が保証されない場合は、SecondaryIdentifier を使用します。詳細については、セカンダリ ID での結果の絞り込みをご覧ください。
複数の SecondaryIdentifier 要素を使用することはできません。
属性
| 属性 | 説明 | デフォルト | 要否 | 型 |
|---|---|---|---|---|
| ref |
ID の参照元を格納する変数(例: |
なし | 必須。 | 文字列 |
| type | ref 属性の変数で更新されるタイプ(例: consumerkey)。値の一覧については、エンティティ タイプと ID をご覧ください。 |
必須。 | 文字列 |
例
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnError=&qu>ot;fa<lse" e>nabled="<true" n>ame=&<quot;GetAPIProduct" ><DisplayName>GetAP<IProduct/DisplayName EntityType value="apiproduc>t&quo<t;/EntityType EntityIdentifier ref="developer.app>.<name" ty>pe="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
使用上の注意
セカンダリ ID での結果の絞り込み
エンティティによっては、1 つの ID だけでは必要なエンティティが取得できないことがあります。この場合、セカンダリ ID を使用すると、結果を絞り込むことができます。
最初のポリシー構成は次のようになります。
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduct"/Ent>i<tyType En>tityIdentifier ref="request.queryparam.apikey" type="consumerkey"/ /AccessEntity
アプリが複数の API プロダクトに関連付けられているため、単独のアプリ ID では必要な API プロダクトが返されない可能性があります(複数の該当結果の最初の一致しか返されないこともあります)。
より正確な結果を取得するため、SecondaryIdentifier を使用します。たとえば、デフォルトでは、OAuth 2.0 による交換時に交換されるため、フローに appname 変数と developerid 変数がある可能性があります。これらの変数の値を AccessEntity ポリシーで使用して、結果のアプリのプロファイル情報を取得します。
より具体的なポリシー構成は次のようになります。
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? AccessEntity async="false" continueOnEr>ror=&<quot;false&>quot; enabled<="true&>quot;< name="GetApp" ><DisplayName>GetAp<pProfile/DisplayName EntityType value="apiproduc>t&quo<t;/EntityType EntityIdentifier ref="developer.app>.<name" ty>pe="appname"/ SecondaryIdentifier ref="developer.id" type="developerid"/ /AccessEntity
サポートされるエンティティ タイプと ID
AccessEntity は、次のエンティティ タイプと ID をサポートします。
| EntityType 値 | EntityIdentifier タイプ | SecondaryIdentifier タイプ |
|---|---|---|
apiproduct |
appid |
apiresource |
apiproductname |
||
appname |
apiresourcedeveloperemaildeveloperidcompanyname |
|
consumerkey |
apiresource |
|
app |
appid |
|
appname |
developeremaildeveloperidcompanyname |
|
consumerkey |
||
authorizationcode |
authorizationcode |
|
company |
appid |
|
company |
||
consumerkey |
||
companydeveloper |
companyname |
|
consumerkey |
consumerkey |
|
consumerkey_scope |
consumerkey |
|
developer |
appid |
|
consumerkey |
||
developeremail |
||
developerid |
||
requesttoken |
requesttoken |
consumerkey |
verifier |
verifier |
XML 形式のエンティティ プロファイルの例
必要なエンティティ プロファイルの値を XPath で取得するには、プロファイルの XML 構造を理解しておく必要があります。構造のサンプルを確認するため、Management API 呼び出しを使用して、必要なエンティティの XML を取得します。詳しくは、Management API のリファレンスをご覧ください。
以降のセクションでは、API 呼び出しのコードとその呼び出しで返される XML のサンプルについて説明します。
アプリ
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/apps/{app_id} \ -u email:password
Edge Management API リファレンスのアプリ ID で組織のアプリを取得するもご覧ください。
または
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name} \ -u email:password
Edge Management API リファレンスのデベロッパー アプリの詳細を取得するもご覧ください。
サンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="ye>s&quo<t;? App na>me=&<quot;thomas>-app&<quot; Ac>cessT<yperead/Acc>essType < ApiProd>ucts/ Cre<dentials > Credent<ial > Attributes/ Con<sumerKeywrqO>OOiPArFI0WRoB<1gAJMRbOguekJ5>w/ConsumerKey < Consu>merSecretWvOh<DrJ8m6kzz7N>i/ConsumerSecret < > ApiProducts < > ApiPro<duct<>/span> N<ameFre>eProduct</Name > < Statusapp>roved/Status < > /ApiProdu<ct > /ApiP<roduct>s < S>copes/ < S>tatus<approved/Sta>tus < /C>redenti<al /Cr>edent<ials<>/span> AppFamilydefault/AppFamily A<ppIdab>308c1<3-bc99-4c5>0-8434-0e<0ed1b8607>5/AppId A<ttri>butes < At>tribute < > NameDisplayName</Name > < ValueTo>m'<;s Weather >App/V<alue > /Attribute /At<tributes > Call<backUrlht>tp://tom.app/<login/Call>backU<rl Cr>eatedAt136250287<2727/Creat>edAt < Created>Byadmin@apigee.c<om/CreatedBy> <DeveloperIdPFK>8IwOeAOW01JKA</DeveloperId > Las<tModifiedAt136>2502872727/LastM<odifiedAt L>astMo<difiedB>yadmi<n@apig>ee.com/L<astModi>f<iedB>y Scopes/ Statusapproved/Status /App
API プロダクト
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/apiproducts/{apiproduct_name} \ -u email:password
Edge Management API リファレンスの API プロダクトを取得するもご覧ください。
次の XPath のサンプルでは、weather_free という名前の API プロダクトから 2 つ目の API リソース(URI)を取得しています。
/ApiProduct['@name=weather_free']/ApiResources/ApiResource[1]/text()
XML として返されるサンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes"? >ApiPr<oduct name=&>quot;weat<her_free&qu>ot; ApiResources < ApiRe>sourc<e/forecastrss>, /re<ports/ApiRes>ourc<e /ApiRes>ource<s Appr>ovalTypea<uto/Appro>valType A<ttri>butes < At>tribute < > Namedescription/Name < > Valu<eIntroduct>ory API P<roduct/Va>lue /<Attr>ibute Attribute < > Namede<velop>e<r.quot>a.interva<l/Name > <Value1/Va>lue /<Attr>ibute Attribu<te > Nam<edeve>l<oper.q>uota.limi<t/Name > <Value1/Va>lue /<Attr>ibute Attribute < > Namede<velop>er.quo<ta.tim>eunit/Nam<e > Value<minute/Va>lue /<Attr>ibute < At>tribute < > Nameservic<ePlan/>Name < Va>lueIn<troductory/>Value< >/Attribute < /Attribu>tes < Create>dAt1355847839224/<CreatedAt > C<reatedByand>rew@apigee.com/C<reatedBy > Desc<riptionFree> API Product/Des<cription > Disp<layNameFree A>PI Pr<oduct/DisplayN>ame Envir<onments/ La>stMod<ifiedAt1355847>839224/LastModifi<edAt LastMo>difie<dByandre>w@api<gee.com>/<LastModifie>dBy Proxies/ Scopes/ /ApiProduct
会社
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name} \ -u email:password
Edge Management API リファレンスの会社情報を取得するもご覧ください。
サンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalone="yes&>quot;<? Com>pany <name=">theramin" A<pps/ Dis>playN<ameTheramin >Corporati<on/DisplayNam>e < Organ>izatio<napigee>-pm/O<rganizatio>n Sta<tusactive>/Status A<ttri>butes < Att>ribute < > Namebil<ling_c>ode/Name < > Val<ue13648765/>Value< >/Attribute < /Attribu>tes < Create>dAt1349208631291/<CreatedAt > C<reatedByandrew>@apigee.com/C<reatedBy La>stMod<ifiedAt1349208>631291/LastModifi<edAt LastMo>d<ifiedBya>ndrew@apigee.com/LastModifiedBy /Company
会社のデベロッパー
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/companies/{company_name}/developers/{developer_name} \ -u email:password
サンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalo>ne=&q<uot;yes&q>uot;? Dev<elope>rs Developer < >Emailntes<la@t>heramin.c<om/Em>ail < Rol>e<developer/R>ole /Developer /Developers
コンシューマ キー
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email}/apps/{app_name}/keys/{consumer_key} \ -u email:password
Edge Management API リファレンスのデベロッパー アプリのキー情報を取得するもご覧ください。
XPath のサンプル:
/Credential/ApiProducts/ApiProduct[Name='weather_free']/Status/text()
サンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standalo>ne=&q<uot;yes&quo>t;?
C<redential
> Attributes/
ConsumerKeyXL<otL3PRxNkUGX>hGAFD<POr6fqtvAhuZe/>ConsumerKey
<ConsumerSecreti>NUyEa<OOh96KR3YL/>ConsumerS<ecret
>ApiProducts
< > ApiProduc<t
> Name<weathe>r_free/N<ame
> <Statusappro>ved/S<tatus
> /Ap<iProduc>t
< /ApiP>roducts
< Sco>p<es/
Sta>tusapproved/Status
/Credentialデベロッパー
$ curl -H "Accept:text/xml" -X GET \ https://api.enterprise.apigee.com/v1/o/{org_name}/developers/{developer_email} \ -u email:password
Edge Management API リファレンスのデベロッパーを取得するもご覧ください。
XPath のサンプル:
/Developer/Attributes/Attribute[Name='my_custom_attribute']/Value/text()
/Developer/Email/text()
サンプル プロファイル:
<?xml version="1.0" encoding="UTF-8&quo>t<; standal>one=&<quot>;yes"<;? >Developer < A>pps < >Appweather<appx>/App < > Ap<pweat>herapp/App /App<s >Email<ntesla@ther>amin.com/Email < Developer>Id4Y4<xd0KRZ1wm>HJqu/D<eveloperId> <FirstNam>eNiko<la/FirstN>ame < LastN>ameTesla</LastName> <UserNametheramin>/UserName< Organization>Namea<pigee->pm/Org<anizati>onNam<e Stat>usactive/<Status > Attributes < > Attribut<e > Name<proje>ct_typ<e/Name> < Valuep>ublic</Value > /<Attribute> /Attribu<tes Cr>eated<At1349797>040634/CreatedAt< Creat>edByr<saha@apigee.co>m/CreatedBy < LastModified>At134<9797040634/Las>tModifiedAt <LastModifiedByr>s<aha@apigee>.com/LastModifiedBy /Developer
フロー変数
AccessEntity ポリシーに指定したエンティティ プロファイルが取得されると、メッセージ コンテキストに XML 形式のプロファイル オブジェクトが変数として追加されます。この情報には、他の変数と同様に、変数名を参照することでアクセスできます。ユーザーが指定した AccessEntity ポリシーの名前が変数名の接頭辞として設定されます。
たとえば、GetDeveloper という名前の AccessEntity ポリシーが実行されると、AccessEntity.GetDeveloper という名前の変数に XML 形式のプロファイルが格納されます。XML 形式のプロファイルは、ExtractVariables ポリシーに定義された XPath で解析されます。このポリシーでは、AccessEntity.GetDeveloper がソースとして指定されています。
エラー リファレンス
関連情報については、ポリシーエラーについて知っておくべきことと障害の処理をご覧ください。
ランタイム エラー
なし。
デプロイエラー
| エラー名 | 障害文字列 | HTTP ステータス | 発生条件 |
|---|---|---|---|
InvalidEntityType |
Invalid type [entity_type] in ACCESSENTITYStepDefinition
[policy_name] |
なし | 使用するエンティティ タイプをサポートされているタイプのいずれかにする必要があります。 |
関連トピック
ExtractVariables: ExtractVariables ポリシーAssignMessage: AssignMessage ポリシー